ReactOS 0.4.16-dev-401-g45b008d
ppb.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/rtl/ppb.c
5 * PURPOSE: Process parameters functions
6 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
7 */
8
9/* INCLUDES ****************************************************************/
10
11#include <rtl.h>
12
13#define NDEBUG
14#include <debug.h>
15
16/* MACROS ****************************************************************/
17
18#define NORMALIZE(x,addr) {if(x) x=(PVOID)((ULONG_PTR)(x)+(ULONG_PTR)(addr));}
19#define DENORMALIZE(x,addr) {if(x) x=(PVOID)((ULONG_PTR)(x)-(ULONG_PTR)(addr));}
20#define ALIGN(x,align) (((ULONG)(x)+(align)-1UL)&(~((align)-1UL)))
21
22/* FUNCTIONS ****************************************************************/
23
24
25static __inline VOID
30{
31 Destination->Length = Source->Length;
32 Destination->MaximumLength = Size ? Size : Source->MaximumLength;
34 if (Source->Length)
35 memmove (Destination->Buffer, Source->Buffer, Source->Length);
36 Destination->Buffer[Destination->Length / sizeof(WCHAR)] = 0;
38}
39
40
41/*
42 * @implemented
43 */
46 PUNICODE_STRING ImagePathName,
49 PUNICODE_STRING CommandLine,
51 PUNICODE_STRING WindowTitle,
52 PUNICODE_STRING DesktopInfo,
53 PUNICODE_STRING ShellInfo,
54 PUNICODE_STRING RuntimeData)
55{
57 ULONG Length = 0;
58 PWCHAR Dest;
59 UNICODE_STRING EmptyString;
60 HANDLE CurrentDirectoryHandle;
61 HANDLE ConsoleHandle;
62 ULONG ConsoleFlags;
63
64 DPRINT ("RtlCreateProcessParameters\n");
65
67
68 EmptyString.Length = 0;
69 EmptyString.MaximumLength = sizeof(WCHAR);
70 EmptyString.Buffer = L"";
71
72 if (RtlpGetMode() == UserMode)
73 {
74 if (DllPath == NULL)
75 DllPath = &NtCurrentPeb()->ProcessParameters->DllPath;
76 if (Environment == NULL)
77 Environment = NtCurrentPeb()->ProcessParameters->Environment;
79 CurrentDirectory = &NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath;
80 CurrentDirectoryHandle = NtCurrentPeb()->ProcessParameters->CurrentDirectory.Handle;
81 ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
82 ConsoleFlags = NtCurrentPeb()->ProcessParameters->ConsoleFlags;
83 }
84 else
85 {
86 if (DllPath == NULL)
87 DllPath = &EmptyString;
89 CurrentDirectory = &EmptyString;
90 CurrentDirectoryHandle = NULL;
91 ConsoleHandle = NULL;
92 ConsoleFlags = 0;
93 }
94
95 if (CommandLine == NULL)
96 CommandLine = &EmptyString;
97 if (WindowTitle == NULL)
98 WindowTitle = &EmptyString;
99 if (DesktopInfo == NULL)
100 DesktopInfo = &EmptyString;
101 if (ShellInfo == NULL)
102 ShellInfo = &EmptyString;
103 if (RuntimeData == NULL)
104 RuntimeData = &EmptyString;
105
106 /* size of process parameter block */
108
109 /* size of current directory buffer */
110 Length += (MAX_PATH * sizeof(WCHAR));
111
112 /* add string lengths */
113 Length += ALIGN(DllPath->MaximumLength, sizeof(ULONG));
114 Length += ALIGN(ImagePathName->Length + sizeof(WCHAR), sizeof(ULONG));
115 Length += ALIGN(CommandLine->Length + sizeof(WCHAR), sizeof(ULONG));
116 Length += ALIGN(WindowTitle->MaximumLength, sizeof(ULONG));
117 Length += ALIGN(DesktopInfo->MaximumLength, sizeof(ULONG));
118 Length += ALIGN(ShellInfo->MaximumLength, sizeof(ULONG));
119 Length += ALIGN(RuntimeData->MaximumLength, sizeof(ULONG));
120
121 /* Calculate the required block size */
122 Param = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, Length);
123 if (!Param)
124 {
127 }
128
129 DPRINT ("Process parameters allocated\n");
130
131 Param->MaximumLength = Length;
132 Param->Length = Length;
134 Param->Environment = Environment;
135 Param->CurrentDirectory.Handle = CurrentDirectoryHandle;
136 Param->ConsoleHandle = ConsoleHandle;
137 Param->ConsoleFlags = ConsoleFlags;
138
139 Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS));
140
141 /* copy current directory */
145 MAX_PATH * sizeof(WCHAR));
146
147 /* make sure the current directory has a trailing backslash */
148 if (Param->CurrentDirectory.DosPath.Length > 0)
149 {
150 Length = Param->CurrentDirectory.DosPath.Length / sizeof(WCHAR);
151 if (Param->CurrentDirectory.DosPath.Buffer[Length-1] != L'\\')
152 {
153 Param->CurrentDirectory.DosPath.Buffer[Length] = L'\\';
154 Param->CurrentDirectory.DosPath.Buffer[Length + 1] = 0;
155 Param->CurrentDirectory.DosPath.Length += sizeof(WCHAR);
156 }
157 }
158
159 /* copy dll path */
161 &Param->DllPath,
162 DllPath,
163 0);
164
165 /* copy image path name */
167 &Param->ImagePathName,
168 ImagePathName,
169 ImagePathName->Length + sizeof(WCHAR));
170
171 /* copy command line */
173 &Param->CommandLine,
174 CommandLine,
175 CommandLine->Length + sizeof(WCHAR));
176
177 /* copy title */
179 &Param->WindowTitle,
180 WindowTitle,
181 0);
182
183 /* copy desktop */
185 &Param->DesktopInfo,
186 DesktopInfo,
187 0);
188
189 /* copy shell info */
191 &Param->ShellInfo,
192 ShellInfo,
193 0);
194
195 /* copy runtime info */
197 &Param->RuntimeData,
198 RuntimeData,
199 0);
200
202 *ProcessParameters = Param;
204
205 return STATUS_SUCCESS;
206}
207
208/*
209 * @implemented
210 */
212NTAPI
214{
215 RtlFreeHeap(RtlGetProcessHeap(), 0, ProcessParameters);
216 return STATUS_SUCCESS;
217}
218
219/*
220 * denormalize process parameters (Pointer-->Offset)
221 *
222 * @implemented
223 */
226{
228 {
229 DENORMALIZE(Params->CurrentDirectory.DosPath.Buffer, Params);
230 DENORMALIZE(Params->DllPath.Buffer, Params);
231 DENORMALIZE(Params->ImagePathName.Buffer, Params);
232 DENORMALIZE(Params->CommandLine.Buffer, Params);
233 DENORMALIZE(Params->WindowTitle.Buffer, Params);
234 DENORMALIZE(Params->DesktopInfo.Buffer, Params);
235 DENORMALIZE(Params->ShellInfo.Buffer, Params);
236 DENORMALIZE(Params->RuntimeData.Buffer, Params);
237
238 Params->Flags &= ~RTL_USER_PROCESS_PARAMETERS_NORMALIZED;
239 }
240
241 return Params;
242}
243
244/*
245 * normalize process parameters (Offset-->Pointer)
246 *
247 * @implemented
248 */
251{
253 {
254 NORMALIZE(Params->CurrentDirectory.DosPath.Buffer, Params);
255 NORMALIZE(Params->DllPath.Buffer, Params);
256 NORMALIZE(Params->ImagePathName.Buffer, Params);
257 NORMALIZE(Params->CommandLine.Buffer, Params);
258 NORMALIZE(Params->WindowTitle.Buffer, Params);
259 NORMALIZE(Params->DesktopInfo.Buffer, Params);
260 NORMALIZE(Params->ShellInfo.Buffer, Params);
261 NORMALIZE(Params->RuntimeData.Buffer, Params);
262
264 }
265
266 return Params;
267}
268
269/* EOF */
#define NtCurrentPeb()
Definition: FLS.c:22
LONG NTSTATUS
Definition: precomp.h:26
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
struct _RTL_USER_PROCESS_PARAMETERS RTL_USER_PROCESS_PARAMETERS
#define NULL
Definition: types.h:112
KPROCESSOR_MODE NTAPI RtlpGetMode(VOID)
Definition: libsupp.c:55
#define MAX_PATH
Definition: compat.h:34
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
NTSYSAPI void WINAPI RtlReleasePebLock(void)
Definition: libsupp.c:84
NTSYSAPI void WINAPI RtlAcquirePebLock(void)
Definition: libsupp.c:74
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:47
static const char const char * DllPath
Definition: image.c:34
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
#define UserMode
Definition: asm.h:39
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3016
#define RTL_USER_PROCESS_PARAMETERS_NORMALIZED
Definition: rtltypes.h:41
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
unsigned short USHORT
Definition: pedump.c:61
static __inline VOID RtlpCopyParameterString(PWCHAR *Ptr, PUNICODE_STRING Destination, PUNICODE_STRING Source, USHORT Size)
Definition: ppb.c:26
#define ALIGN(x, align)
Definition: ppb.c:20
#define DENORMALIZE(x, addr)
Definition: ppb.c:19
#define NORMALIZE(x, addr)
Definition: ppb.c:18
PRTL_USER_PROCESS_PARAMETERS NTAPI RtlDeNormalizeProcessParams(PRTL_USER_PROCESS_PARAMETERS Params)
Definition: ppb.c:225
PRTL_USER_PROCESS_PARAMETERS NTAPI RtlNormalizeProcessParams(PRTL_USER_PROCESS_PARAMETERS Params)
Definition: ppb.c:250
NTSTATUS NTAPI RtlDestroyProcessParameters(IN PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
Definition: ppb.c:213
NTSTATUS NTAPI RtlCreateProcessParameters(PRTL_USER_PROCESS_PARAMETERS *ProcessParameters, PUNICODE_STRING ImagePathName, PUNICODE_STRING DllPath, PUNICODE_STRING CurrentDirectory, PUNICODE_STRING CommandLine, PWSTR Environment, PUNICODE_STRING WindowTitle, PUNICODE_STRING DesktopInfo, PUNICODE_STRING ShellInfo, PUNICODE_STRING RuntimeData)
Definition: ppb.c:45
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
UNICODE_STRING DosPath
Definition: rtltypes.h:1368
HANDLE Handle
Definition: rtltypes.h:1369
UNICODE_STRING RuntimeData
Definition: rtltypes.h:1557
UNICODE_STRING CommandLine
Definition: btrfs_drv.h:1902
UNICODE_STRING ImagePathName
Definition: btrfs_drv.h:1901
UNICODE_STRING WindowTitle
Definition: rtltypes.h:1554
UNICODE_STRING ShellInfo
Definition: rtltypes.h:1556
UNICODE_STRING DesktopInfo
Definition: rtltypes.h:1555
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308
__wchar_t WCHAR
Definition: xmlstorage.h:180