Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenppb.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS system libraries 00004 * FILE: lib/rtl/ppb.c 00005 * PURPOSE: Process parameters functions 00006 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) 00007 */ 00008 00009 /* INCLUDES ****************************************************************/ 00010 00011 #include <rtl.h> 00012 00013 #define NDEBUG 00014 #include <debug.h> 00015 00016 /* MACROS ****************************************************************/ 00017 00018 #define NORMALIZE(x,addr) {if(x) x=(PVOID)((ULONG_PTR)(x)+(ULONG_PTR)(addr));} 00019 #define DENORMALIZE(x,addr) {if(x) x=(PVOID)((ULONG_PTR)(x)-(ULONG_PTR)(addr));} 00020 #define ALIGN(x,align) (((ULONG)(x)+(align)-1UL)&(~((align)-1UL))) 00021 00022 /* FUNCTIONS ****************************************************************/ 00023 00024 00025 static __inline VOID 00026 RtlpCopyParameterString(PWCHAR *Ptr, 00027 PUNICODE_STRING Destination, 00028 PUNICODE_STRING Source, 00029 USHORT Size) 00030 { 00031 Destination->Length = Source->Length; 00032 Destination->MaximumLength = Size ? Size : Source->MaximumLength; 00033 Destination->Buffer = (PWCHAR)(*Ptr); 00034 if (Source->Length) 00035 memmove (Destination->Buffer, Source->Buffer, Source->Length); 00036 Destination->Buffer[Destination->Length / sizeof(WCHAR)] = 0; 00037 *Ptr += Destination->MaximumLength/sizeof(WCHAR); 00038 } 00039 00040 00041 /* 00042 * @implemented 00043 */ 00044 NTSTATUS NTAPI 00045 RtlCreateProcessParameters(PRTL_USER_PROCESS_PARAMETERS *ProcessParameters, 00046 PUNICODE_STRING ImagePathName, 00047 PUNICODE_STRING DllPath, 00048 PUNICODE_STRING CurrentDirectory, 00049 PUNICODE_STRING CommandLine, 00050 PWSTR Environment, 00051 PUNICODE_STRING WindowTitle, 00052 PUNICODE_STRING DesktopInfo, 00053 PUNICODE_STRING ShellInfo, 00054 PUNICODE_STRING RuntimeData) 00055 { 00056 PRTL_USER_PROCESS_PARAMETERS Param = NULL; 00057 ULONG Length = 0; 00058 PWCHAR Dest; 00059 UNICODE_STRING EmptyString; 00060 HANDLE CurrentDirectoryHandle; 00061 HANDLE ConsoleHandle; 00062 ULONG ConsoleFlags; 00063 00064 DPRINT ("RtlCreateProcessParameters\n"); 00065 00066 RtlAcquirePebLock(); 00067 00068 EmptyString.Length = 0; 00069 EmptyString.MaximumLength = sizeof(WCHAR); 00070 EmptyString.Buffer = L""; 00071 00072 if (RtlpGetMode() == UserMode) 00073 { 00074 if (DllPath == NULL) 00075 DllPath = &NtCurrentPeb()->ProcessParameters->DllPath; 00076 if (Environment == NULL) 00077 Environment = NtCurrentPeb()->ProcessParameters->Environment; 00078 if (CurrentDirectory == NULL) 00079 CurrentDirectory = &NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath; 00080 CurrentDirectoryHandle = NtCurrentPeb()->ProcessParameters->CurrentDirectory.Handle; 00081 ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; 00082 ConsoleFlags = NtCurrentPeb()->ProcessParameters->ConsoleFlags; 00083 } 00084 else 00085 { 00086 if (DllPath == NULL) 00087 DllPath = &EmptyString; 00088 if (CurrentDirectory == NULL) 00089 CurrentDirectory = &EmptyString; 00090 CurrentDirectoryHandle = NULL; 00091 ConsoleHandle = NULL; 00092 ConsoleFlags = 0; 00093 } 00094 00095 if (CommandLine == NULL) 00096 CommandLine = &EmptyString; 00097 if (WindowTitle == NULL) 00098 WindowTitle = &EmptyString; 00099 if (DesktopInfo == NULL) 00100 DesktopInfo = &EmptyString; 00101 if (ShellInfo == NULL) 00102 ShellInfo = &EmptyString; 00103 if (RuntimeData == NULL) 00104 RuntimeData = &EmptyString; 00105 00106 /* size of process parameter block */ 00107 Length = sizeof(RTL_USER_PROCESS_PARAMETERS); 00108 00109 /* size of current directory buffer */ 00110 Length += (MAX_PATH * sizeof(WCHAR)); 00111 00112 /* add string lengths */ 00113 Length += ALIGN(DllPath->MaximumLength, sizeof(ULONG)); 00114 Length += ALIGN(ImagePathName->Length + sizeof(WCHAR), sizeof(ULONG)); 00115 Length += ALIGN(CommandLine->Length + sizeof(WCHAR), sizeof(ULONG)); 00116 Length += ALIGN(WindowTitle->MaximumLength, sizeof(ULONG)); 00117 Length += ALIGN(DesktopInfo->MaximumLength, sizeof(ULONG)); 00118 Length += ALIGN(ShellInfo->MaximumLength, sizeof(ULONG)); 00119 Length += ALIGN(RuntimeData->MaximumLength, sizeof(ULONG)); 00120 00121 /* Calculate the required block size */ 00122 Param = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, Length); 00123 if (!Param) 00124 { 00125 RtlReleasePebLock(); 00126 return STATUS_INSUFFICIENT_RESOURCES; 00127 } 00128 00129 DPRINT ("Process parameters allocated\n"); 00130 00131 Param->MaximumLength = Length; 00132 Param->Length = Length; 00133 Param->Flags = RTL_USER_PROCESS_PARAMETERS_NORMALIZED; 00134 Param->Environment = Environment; 00135 Param->CurrentDirectory.Handle = CurrentDirectoryHandle; 00136 Param->ConsoleHandle = ConsoleHandle; 00137 Param->ConsoleFlags = ConsoleFlags; 00138 00139 Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS)); 00140 00141 /* copy current directory */ 00142 RtlpCopyParameterString(&Dest, 00143 &Param->CurrentDirectory.DosPath, 00144 CurrentDirectory, 00145 MAX_PATH * sizeof(WCHAR)); 00146 00147 /* make sure the current directory has a trailing backslash */ 00148 if (Param->CurrentDirectory.DosPath.Length > 0) 00149 { 00150 ULONG Length; 00151 00152 Length = Param->CurrentDirectory.DosPath.Length / sizeof(WCHAR); 00153 if (Param->CurrentDirectory.DosPath.Buffer[Length-1] != L'\\') 00154 { 00155 Param->CurrentDirectory.DosPath.Buffer[Length] = L'\\'; 00156 Param->CurrentDirectory.DosPath.Buffer[Length + 1] = 0; 00157 Param->CurrentDirectory.DosPath.Length += sizeof(WCHAR); 00158 } 00159 } 00160 00161 /* copy dll path */ 00162 RtlpCopyParameterString(&Dest, 00163 &Param->DllPath, 00164 DllPath, 00165 0); 00166 00167 /* copy image path name */ 00168 RtlpCopyParameterString(&Dest, 00169 &Param->ImagePathName, 00170 ImagePathName, 00171 ImagePathName->Length + sizeof(WCHAR)); 00172 00173 /* copy command line */ 00174 RtlpCopyParameterString(&Dest, 00175 &Param->CommandLine, 00176 CommandLine, 00177 CommandLine->Length + sizeof(WCHAR)); 00178 00179 /* copy title */ 00180 RtlpCopyParameterString(&Dest, 00181 &Param->WindowTitle, 00182 WindowTitle, 00183 0); 00184 00185 /* copy desktop */ 00186 RtlpCopyParameterString(&Dest, 00187 &Param->DesktopInfo, 00188 DesktopInfo, 00189 0); 00190 00191 /* copy shell info */ 00192 RtlpCopyParameterString(&Dest, 00193 &Param->ShellInfo, 00194 ShellInfo, 00195 0); 00196 00197 /* copy runtime info */ 00198 RtlpCopyParameterString(&Dest, 00199 &Param->RuntimeData, 00200 RuntimeData, 00201 0); 00202 00203 RtlDeNormalizeProcessParams(Param); 00204 *ProcessParameters = Param; 00205 RtlReleasePebLock(); 00206 00207 return STATUS_SUCCESS; 00208 } 00209 00210 /* 00211 * @implemented 00212 */ 00213 NTSTATUS 00214 NTAPI 00215 RtlDestroyProcessParameters(IN PRTL_USER_PROCESS_PARAMETERS ProcessParameters) 00216 { 00217 RtlFreeHeap(RtlGetProcessHeap(), 0, ProcessParameters); 00218 return STATUS_SUCCESS; 00219 } 00220 00221 /* 00222 * denormalize process parameters (Pointer-->Offset) 00223 * 00224 * @implemented 00225 */ 00226 PRTL_USER_PROCESS_PARAMETERS NTAPI 00227 RtlDeNormalizeProcessParams(PRTL_USER_PROCESS_PARAMETERS Params) 00228 { 00229 if (Params && (Params->Flags & RTL_USER_PROCESS_PARAMETERS_NORMALIZED)) 00230 { 00231 DENORMALIZE(Params->CurrentDirectory.DosPath.Buffer, Params); 00232 DENORMALIZE(Params->DllPath.Buffer, Params); 00233 DENORMALIZE(Params->ImagePathName.Buffer, Params); 00234 DENORMALIZE(Params->CommandLine.Buffer, Params); 00235 DENORMALIZE(Params->WindowTitle.Buffer, Params); 00236 DENORMALIZE(Params->DesktopInfo.Buffer, Params); 00237 DENORMALIZE(Params->ShellInfo.Buffer, Params); 00238 DENORMALIZE(Params->RuntimeData.Buffer, Params); 00239 00240 Params->Flags &= ~RTL_USER_PROCESS_PARAMETERS_NORMALIZED; 00241 } 00242 00243 return Params; 00244 } 00245 00246 /* 00247 * normalize process parameters (Offset-->Pointer) 00248 * 00249 * @implemented 00250 */ 00251 PRTL_USER_PROCESS_PARAMETERS NTAPI 00252 RtlNormalizeProcessParams(PRTL_USER_PROCESS_PARAMETERS Params) 00253 { 00254 if (Params && !(Params->Flags & RTL_USER_PROCESS_PARAMETERS_NORMALIZED)) 00255 { 00256 NORMALIZE(Params->CurrentDirectory.DosPath.Buffer, Params); 00257 NORMALIZE(Params->DllPath.Buffer, Params); 00258 NORMALIZE(Params->ImagePathName.Buffer, Params); 00259 NORMALIZE(Params->CommandLine.Buffer, Params); 00260 NORMALIZE(Params->WindowTitle.Buffer, Params); 00261 NORMALIZE(Params->DesktopInfo.Buffer, Params); 00262 NORMALIZE(Params->ShellInfo.Buffer, Params); 00263 NORMALIZE(Params->RuntimeData.Buffer, Params); 00264 00265 Params->Flags |= RTL_USER_PROCESS_PARAMETERS_NORMALIZED; 00266 } 00267 00268 return Params; 00269 } 00270 00271 /* EOF */ Generated on Sat May 26 2012 04:35:22 for ReactOS by
1.7.6.1
|