ReactOS 0.4.16-dev-122-g325d74c
ppb.c File Reference
#include <rtl.h>
#include <debug.h>
Include dependency graph for ppb.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NORMALIZE(x, addr)   {if(x) x=(PVOID)((ULONG_PTR)(x)+(ULONG_PTR)(addr));}
 
#define DENORMALIZE(x, addr)   {if(x) x=(PVOID)((ULONG_PTR)(x)-(ULONG_PTR)(addr));}
 
#define ALIGN(x, align)   (((ULONG)(x)+(align)-1UL)&(~((align)-1UL)))
 

Functions

static __inline VOID RtlpCopyParameterString (PWCHAR *Ptr, PUNICODE_STRING Destination, PUNICODE_STRING Source, USHORT Size)
 
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)
 
NTSTATUS NTAPI RtlDestroyProcessParameters (IN PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
 
PRTL_USER_PROCESS_PARAMETERS NTAPI RtlDeNormalizeProcessParams (PRTL_USER_PROCESS_PARAMETERS Params)
 
PRTL_USER_PROCESS_PARAMETERS NTAPI RtlNormalizeProcessParams (PRTL_USER_PROCESS_PARAMETERS Params)
 

Macro Definition Documentation

◆ ALIGN

#define ALIGN (   x,
  align 
)    (((ULONG)(x)+(align)-1UL)&(~((align)-1UL)))

Definition at line 20 of file ppb.c.

◆ DENORMALIZE

#define DENORMALIZE (   x,
  addr 
)    {if(x) x=(PVOID)((ULONG_PTR)(x)-(ULONG_PTR)(addr));}

Definition at line 19 of file ppb.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file ppb.c.

◆ NORMALIZE

#define NORMALIZE (   x,
  addr 
)    {if(x) x=(PVOID)((ULONG_PTR)(x)+(ULONG_PTR)(addr));}

Definition at line 18 of file ppb.c.

Function Documentation

◆ RtlCreateProcessParameters()

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 at line 45 of file ppb.c.

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 */
143 &Param->CurrentDirectory.DosPath,
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}
#define NtCurrentPeb()
Definition: FLS.c:22
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
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
NTSYSAPI void WINAPI RtlReleasePebLock(void)
Definition: libsupp.c:84
NTSYSAPI void WINAPI RtlAcquirePebLock(void)
Definition: libsupp.c:74
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:47
static const char const char * DllPath
Definition: image.c:34
#define UserMode
Definition: asm.h:35
#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
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
PRTL_USER_PROCESS_PARAMETERS NTAPI RtlDeNormalizeProcessParams(PRTL_USER_PROCESS_PARAMETERS Params)
Definition: ppb.c:225
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
HANDLE Handle
Definition: rtltypes.h:1369
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ RtlDeNormalizeProcessParams()

PRTL_USER_PROCESS_PARAMETERS NTAPI RtlDeNormalizeProcessParams ( PRTL_USER_PROCESS_PARAMETERS  Params)

Definition at line 225 of file ppb.c.

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}
#define DENORMALIZE(x, addr)
Definition: ppb.c:19
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308

Referenced by RtlCreateProcessParameters().

◆ RtlDestroyProcessParameters()

NTSTATUS NTAPI RtlDestroyProcessParameters ( IN PRTL_USER_PROCESS_PARAMETERS  ProcessParameters)

Definition at line 213 of file ppb.c.

214{
215 RtlFreeHeap(RtlGetProcessHeap(), 0, ProcessParameters);
216 return STATUS_SUCCESS;
217}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608

◆ RtlNormalizeProcessParams()

PRTL_USER_PROCESS_PARAMETERS NTAPI RtlNormalizeProcessParams ( PRTL_USER_PROCESS_PARAMETERS  Params)

Definition at line 250 of file ppb.c.

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}
#define NORMALIZE(x, addr)
Definition: ppb.c:18

◆ RtlpCopyParameterString()

static __inline VOID RtlpCopyParameterString ( PWCHAR Ptr,
PUNICODE_STRING  Destination,
PUNICODE_STRING  Source,
USHORT  Size 
)
static

Definition at line 26 of file ppb.c.

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}
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3016
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by RtlCreateProcessParameters().