Temporary code for debugging purposes
[reactos.git] / posix / include / psx / pdata.h
1 /* $Id: pdata.h,v 1.6 2002/05/17 01:49:53 hyperion Exp $
2 */
3 /*
4 * psx/pdata.h
5 *
6 * POSIX+ subsystem process environment data structure
7 *
8 * This file is part of the ReactOS Operating System.
9 *
10 * Contributors:
11 * Created by KJK::Hyperion <noog@libero.it>
12 *
13 * THIS SOFTWARE IS NOT COPYRIGHTED
14 *
15 * This source code is offered for use in the public domain. You may
16 * use, modify or distribute it freely.
17 *
18 * This code is distributed in the hope that it will be useful but
19 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
20 * DISCLAMED. This includes but is not limited to warranties of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 *
23 */
24 #ifndef __PSX_PDATA_H_INCLUDED__
25 #define __PSX_PDATA_H_INCLUDED__
26
27 /* INCLUDES */
28 #include <ddk/ntddk.h>
29 #include <ntdll/rtl.h>
30 #include <limits.h>
31 #include <psx/fdtable.h>
32
33 /* OBJECTS */
34
35 /* TYPES */
36 typedef struct __tagPDX_PDATA
37 {
38 BOOL Spawned; /* TRUE if process has been created through __PdxSpawnPosixProcess() */
39 int ArgCount; /* count of arguments passed to exec() */
40 char **ArgVect; /* array of arguments passed to exec() */
41 char ***Environment; /* pointer to user-provided environ variable */
42 UNICODE_STRING NativePathBuffer; /* static buffer used by low-level calls for pathname conversions */
43 UNICODE_STRING CurDir; /* current working directory */
44 UNICODE_STRING RootPath; /* NT path to the process's root directory */
45 HANDLE RootHandle; /* handle to the process's root directory */
46 __fdtable_t FdTable; /* file descriptors table */
47 /* WARNING: PRELIMINARY CODE FOR DEBUGGING PURPOSES ONLY - DO NOT CHANGE */
48 CRITICAL_SECTION Lock;
49 LONG TlsIndex;
50 } __PDX_PDATA, * __PPDX_PDATA;
51
52 /* serialized process data block, used by __PdxSpawnPosixProcess() and __PdxExecThunk().
53 The layout of buffers inside the Buffer byte array is as following:
54
55 ArgVect[0] + null byte
56 ArgVect[1] + null byte
57 ...
58 ArgVect[ArgCount - 1] + null byte
59 Environment[0] + null byte
60 Environment[1] + null byte
61 ...
62 Environment[n - 1] + null byte (NOTE: the value of n is stored in ProcessData.Environment)
63 CurDir.Buffer
64 RootPath.Buffer
65 FdTable.Descriptors[0]
66 FdTable.Descriptors[1]
67 ...
68 FdTable.Descriptors[FdTable.AllocatedDescriptors - 1]
69 FdTable.Descriptors[x].ExtraData
70 FdTable.Descriptors[y].ExtraData
71 ...
72 padding for page boundary alignment
73 */
74 typedef struct __tagPDX_SERIALIZED_PDATA
75 {
76 __PDX_PDATA ProcessData;
77 ULONG AllocSize;
78 BYTE Buffer[1];
79 } __PDX_SERIALIZED_PDATA, *__PPDX_SERIALIZED_PDATA;
80
81 typedef struct __tagPDX_TDATA
82 {
83 __PPDX_PDATA ProcessData;
84 int ErrNum;
85 } __PDX_TDATA, * __PPDX_TDATA;
86
87 /* CONSTANTS */
88
89 /* PROTOTYPES */
90 NTSTATUS STDCALL __PdxSerializeProcessData(IN __PPDX_PDATA, OUT __PPDX_SERIALIZED_PDATA *);
91 NTSTATUS STDCALL __PdxUnserializeProcessData(IN OUT __PPDX_SERIALIZED_PDATA *, OUT __PPDX_PDATA * OPTIONAL);
92
93 NTSTATUS
94 STDCALL
95 __PdxProcessDataToProcessParameters
96 (
97 OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
98 IN __PPDX_PDATA ProcessData,
99 IN PUNICODE_STRING ImageFile
100 );
101
102 /* MACROS */
103 /* WARNING: PRELIMINARY CODE FOR DEBUGGING PURPOSES ONLY - DO NOT CHANGE */
104 VOID __PdxSetProcessData(__PPDX_PDATA);
105 __PPDX_PDATA __PdxGetProcessData(VOID);
106
107 #include <ddk/ntddk.h>
108
109 #define __PdxAcquirePdataLock() (RtlEnterCriticalSection(&__PdxGetProcessData()->Lock))
110 #define __PdxReleasePdataLock() (RtlLeaveCriticalSection(&__PdxGetProcessData()->Lock))
111
112 #if 0
113 #define __PdxAcquirePdataLock() (RtlAcquirePebLock())
114 #define __PdxReleasePdataLock() (RtlReleasePebLock())
115
116 #define __PdxSetProcessData(PPDATA) ((void)((NtCurrentPeb()->SubSystemData) = (PPDATA)))
117 #define __PdxGetProcessData() ((__PPDX_PDATA)(&(NtCurrentPeb()->SubSystemData)))
118 #endif
119
120 #define __PdxGetNativePathBuffer() ((PUNICODE_STRING)(&(__PdxGetProcessData()->NativePathBuffer)))
121 #define __PdxGetCurDir() ((PUNICODE_STRING)(&(__PdxGetProcessData()->CurDir)))
122 #define __PdxGetRootPath() ((PUNICODE_STRING)(&(__PdxGetProcessData()->RootPath)))
123 #define __PdxGetRootHandle() ((HANDLE)(__PdxGetProcessData()->RootHandle))
124 #define __PdxGetFdTable() ((__fdtable_t *)(__PdxGetProcessData()->FdTable))
125
126 #define __PdxSetNativePathBuffer(BUF) ((void)((__PdxGetProcessData()->NativePathBuffer) = (BUF)))
127 #define __PdxSetCurDir(CURDIR) ((void)((__PdxGetProcessData()->CurDir) = (CURDIR)))
128 #define __PdxSetRootPath(ROOTPATH) ((void)((__PdxGetProcessData()->RootPath) = (ROOTPATH)))
129 #define __PdxSetRootHandle(ROOTHANDLE) ((void)((__PdxGetProcessData()->RootHandle) = (ROOTHANDLE)))
130 #define __PdxSetFdTable(FDTABLE) ((void)((__PdxGetProcessData()->FdTable) = (FDTABLE)))
131
132 #endif /* __PSX_PDATA_H_INCLUDED__ */
133
134 /* EOF */
135