added __PdxProcessDataToProcessParameters()
[reactos.git] / posix / include / psx / pdata.h
1 /* $Id: pdata.h,v 1.5 2002/03/11 20:51:16 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 } __PDX_PDATA, * __PPDX_PDATA;
48
49 /* serialized process data block, used by __PdxSpawnPosixProcess() and __PdxExecThunk().
50 The layout of buffers inside the Buffer byte array is as following:
51
52 ArgVect[0] + null byte
53 ArgVect[1] + null byte
54 ...
55 ArgVect[ArgCount - 1] + null byte
56 Environment[0] + null byte
57 Environment[1] + null byte
58 ...
59 Environment[n - 1] + null byte (NOTE: the value of n is stored in ProcessData.Environment)
60 CurDir.Buffer
61 RootPath.Buffer
62 FdTable.Descriptors[0]
63 FdTable.Descriptors[1]
64 ...
65 FdTable.Descriptors[FdTable.AllocatedDescriptors - 1]
66 FdTable.Descriptors[x].ExtraData
67 FdTable.Descriptors[y].ExtraData
68 ...
69 padding for page boundary alignment
70 */
71 typedef struct __tagPDX_SERIALIZED_PDATA
72 {
73 __PDX_PDATA ProcessData;
74 ULONG AllocSize;
75 BYTE Buffer[1];
76 } __PDX_SERIALIZED_PDATA, *__PPDX_SERIALIZED_PDATA;
77
78 /* CONSTANTS */
79
80 /* PROTOTYPES */
81 NTSTATUS STDCALL __PdxSerializeProcessData(IN __PPDX_PDATA, OUT __PPDX_SERIALIZED_PDATA *);
82 NTSTATUS STDCALL __PdxUnserializeProcessData(IN OUT __PPDX_SERIALIZED_PDATA *, OUT __PPDX_PDATA * OPTIONAL);
83
84 NTSTATUS
85 STDCALL
86 __PdxProcessDataToProcessParameters
87 (
88 OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
89 IN __PPDX_PDATA ProcessData,
90 IN PUNICODE_STRING ImageFile
91 );
92
93 /* MACROS */
94 #define __PdxAcquirePdataLock() (RtlAcquirePebLock())
95 #define __PdxReleasePdataLock() (RtlReleasePebLock())
96
97 #define __PdxSetProcessData(PPDATA) ((void)((NtCurrentPeb()->SubSystemData) = (PPDATA)))
98 #define __PdxGetProcessData() ((__PPDX_PDATA)(&(NtCurrentPeb()->SubSystemData)))
99
100 #define __PdxGetNativePathBuffer() ((PUNICODE_STRING)(&(__PdxGetProcessData()->NativePathBuffer)))
101 #define __PdxGetCurDir() ((PUNICODE_STRING)(&(__PdxGetProcessData()->CurDir)))
102 #define __PdxGetRootPath() ((PUNICODE_STRING)(&(__PdxGetProcessData()->RootPath)))
103 #define __PdxGetRootHandle() ((HANDLE)(__PdxGetProcessData()->RootHandle))
104 #define __PdxGetFdTable() ((__fdtable_t *)(__PdxGetProcessData()->FdTable))
105
106 #define __PdxSetNativePathBuffer(BUF) ((void)((__PdxGetProcessData()->NativePathBuffer) = (BUF)))
107 #define __PdxSetCurDir(CURDIR) ((void)((__PdxGetProcessData()->CurDir) = (CURDIR)))
108 #define __PdxSetRootPath(ROOTPATH) ((void)((__PdxGetProcessData()->RootPath) = (ROOTPATH)))
109 #define __PdxSetRootHandle(ROOTHANDLE) ((void)((__PdxGetProcessData()->RootHandle) = (ROOTHANDLE)))
110 #define __PdxSetFdTable(FDTABLE) ((void)((__PdxGetProcessData()->FdTable) = (FDTABLE)))
111
112 #endif /* __PSX_PDATA_H_INCLUDED__ */
113
114 /* EOF */
115