2005-09-08 00:09:32 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/rtl/ppb.c
|
|
|
|
* PURPOSE: Process parameters functions
|
|
|
|
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
2000-02-13 16:05:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ****************************************************************/
|
|
|
|
|
2005-07-26 08:39:07 +00:00
|
|
|
#include <rtl.h>
|
2000-02-13 16:05:19 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
2005-05-08 05:14:46 +00:00
|
|
|
#include <debug.h>
|
2000-02-13 16:05:19 +00:00
|
|
|
|
2000-02-18 00:51:03 +00:00
|
|
|
/* MACROS ****************************************************************/
|
|
|
|
|
2004-09-29 08:41:39 +00:00
|
|
|
#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));}
|
2000-02-18 00:51:03 +00:00
|
|
|
#define ALIGN(x,align) (((ULONG)(x)+(align)-1UL)&(~((align)-1UL)))
|
|
|
|
|
2005-04-01 00:39:52 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
2005-01-19 01:11:43 +00:00
|
|
|
|
|
|
|
|
2005-10-19 17:03:38 +00:00
|
|
|
static __inline VOID
|
2000-12-28 20:38:28 +00:00
|
|
|
RtlpCopyParameterString(PWCHAR *Ptr,
|
|
|
|
PUNICODE_STRING Destination,
|
|
|
|
PUNICODE_STRING Source,
|
2011-09-19 11:09:09 +00:00
|
|
|
USHORT Size)
|
2000-02-18 00:51:03 +00:00
|
|
|
{
|
2000-12-28 20:38:28 +00:00
|
|
|
Destination->Length = Source->Length;
|
|
|
|
Destination->MaximumLength = Size ? Size : Source->MaximumLength;
|
|
|
|
Destination->Buffer = (PWCHAR)(*Ptr);
|
|
|
|
if (Source->Length)
|
|
|
|
memmove (Destination->Buffer, Source->Buffer, Source->Length);
|
|
|
|
Destination->Buffer[Destination->Length / sizeof(WCHAR)] = 0;
|
2002-03-14 16:32:49 +00:00
|
|
|
*Ptr += Destination->MaximumLength/sizeof(WCHAR);
|
2000-02-18 00:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-11 13:50:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2002-09-08 10:23:54 +00:00
|
|
|
RtlCreateProcessParameters(PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
|
2000-12-28 20:38:28 +00:00
|
|
|
PUNICODE_STRING ImagePathName,
|
|
|
|
PUNICODE_STRING DllPath,
|
|
|
|
PUNICODE_STRING CurrentDirectory,
|
|
|
|
PUNICODE_STRING CommandLine,
|
|
|
|
PWSTR Environment,
|
|
|
|
PUNICODE_STRING WindowTitle,
|
|
|
|
PUNICODE_STRING DesktopInfo,
|
|
|
|
PUNICODE_STRING ShellInfo,
|
2005-07-12 01:56:14 +00:00
|
|
|
PUNICODE_STRING RuntimeData)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2002-09-08 10:23:54 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS Param = NULL;
|
2000-03-22 18:36:00 +00:00
|
|
|
ULONG Length = 0;
|
|
|
|
PWCHAR Dest;
|
|
|
|
UNICODE_STRING EmptyString;
|
|
|
|
HANDLE CurrentDirectoryHandle;
|
|
|
|
HANDLE ConsoleHandle;
|
|
|
|
ULONG ConsoleFlags;
|
|
|
|
|
|
|
|
DPRINT ("RtlCreateProcessParameters\n");
|
2000-12-28 20:38:28 +00:00
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
2000-03-22 18:36:00 +00:00
|
|
|
|
|
|
|
EmptyString.Length = 0;
|
|
|
|
EmptyString.MaximumLength = sizeof(WCHAR);
|
|
|
|
EmptyString.Buffer = L"";
|
|
|
|
|
2005-04-01 00:39:52 +00:00
|
|
|
if (RtlpGetMode() == UserMode)
|
2000-03-22 18:36:00 +00:00
|
|
|
{
|
|
|
|
if (DllPath == NULL)
|
|
|
|
DllPath = &NtCurrentPeb()->ProcessParameters->DllPath;
|
|
|
|
if (Environment == NULL)
|
|
|
|
Environment = NtCurrentPeb()->ProcessParameters->Environment;
|
|
|
|
if (CurrentDirectory == NULL)
|
2005-07-12 01:56:14 +00:00
|
|
|
CurrentDirectory = &NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath;
|
|
|
|
CurrentDirectoryHandle = NtCurrentPeb()->ProcessParameters->CurrentDirectory.Handle;
|
|
|
|
ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
ConsoleFlags = NtCurrentPeb()->ProcessParameters->ConsoleFlags;
|
2000-03-22 18:36:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (DllPath == NULL)
|
|
|
|
DllPath = &EmptyString;
|
|
|
|
if (CurrentDirectory == NULL)
|
|
|
|
CurrentDirectory = &EmptyString;
|
|
|
|
CurrentDirectoryHandle = NULL;
|
|
|
|
ConsoleHandle = NULL;
|
|
|
|
ConsoleFlags = 0;
|
|
|
|
}
|
2000-12-28 20:38:28 +00:00
|
|
|
|
|
|
|
if (CommandLine == NULL)
|
|
|
|
CommandLine = &EmptyString;
|
|
|
|
if (WindowTitle == NULL)
|
|
|
|
WindowTitle = &EmptyString;
|
|
|
|
if (DesktopInfo == NULL)
|
|
|
|
DesktopInfo = &EmptyString;
|
|
|
|
if (ShellInfo == NULL)
|
|
|
|
ShellInfo = &EmptyString;
|
2005-07-12 01:56:14 +00:00
|
|
|
if (RuntimeData == NULL)
|
|
|
|
RuntimeData = &EmptyString;
|
2000-12-28 20:38:28 +00:00
|
|
|
|
|
|
|
/* size of process parameter block */
|
2002-09-08 10:23:54 +00:00
|
|
|
Length = sizeof(RTL_USER_PROCESS_PARAMETERS);
|
2000-12-28 20:38:28 +00:00
|
|
|
|
|
|
|
/* size of current directory buffer */
|
|
|
|
Length += (MAX_PATH * sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* add string lengths */
|
|
|
|
Length += ALIGN(DllPath->MaximumLength, sizeof(ULONG));
|
2002-04-01 22:11:52 +00:00
|
|
|
Length += ALIGN(ImagePathName->Length + sizeof(WCHAR), sizeof(ULONG));
|
|
|
|
Length += ALIGN(CommandLine->Length + sizeof(WCHAR), sizeof(ULONG));
|
2000-12-28 20:38:28 +00:00
|
|
|
Length += ALIGN(WindowTitle->MaximumLength, sizeof(ULONG));
|
|
|
|
Length += ALIGN(DesktopInfo->MaximumLength, sizeof(ULONG));
|
|
|
|
Length += ALIGN(ShellInfo->MaximumLength, sizeof(ULONG));
|
2005-07-12 01:56:14 +00:00
|
|
|
Length += ALIGN(RuntimeData->MaximumLength, sizeof(ULONG));
|
2000-12-28 20:38:28 +00:00
|
|
|
|
|
|
|
/* Calculate the required block size */
|
2010-10-17 11:12:54 +00:00
|
|
|
Param = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, Length);
|
2010-10-16 14:20:30 +00:00
|
|
|
if (!Param)
|
2000-12-28 20:38:28 +00:00
|
|
|
{
|
|
|
|
RtlReleasePebLock();
|
2010-10-16 14:20:30 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2000-12-28 20:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT ("Process parameters allocated\n");
|
|
|
|
|
2010-10-16 14:20:30 +00:00
|
|
|
Param->MaximumLength = Length;
|
2005-07-12 01:56:14 +00:00
|
|
|
Param->Length = Length;
|
2005-11-27 18:24:32 +00:00
|
|
|
Param->Flags = RTL_USER_PROCESS_PARAMETERS_NORMALIZED;
|
2000-12-28 20:38:28 +00:00
|
|
|
Param->Environment = Environment;
|
2005-07-12 01:56:14 +00:00
|
|
|
Param->CurrentDirectory.Handle = CurrentDirectoryHandle;
|
|
|
|
Param->ConsoleHandle = ConsoleHandle;
|
|
|
|
Param->ConsoleFlags = ConsoleFlags;
|
2000-12-28 20:38:28 +00:00
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS));
|
2000-12-28 20:38:28 +00:00
|
|
|
|
|
|
|
/* copy current directory */
|
|
|
|
RtlpCopyParameterString(&Dest,
|
2005-07-12 01:56:14 +00:00
|
|
|
&Param->CurrentDirectory.DosPath,
|
2000-12-28 20:38:28 +00:00
|
|
|
CurrentDirectory,
|
|
|
|
MAX_PATH * sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* make sure the current directory has a trailing backslash */
|
2005-07-12 01:56:14 +00:00
|
|
|
if (Param->CurrentDirectory.DosPath.Length > 0)
|
2000-12-28 20:38:28 +00:00
|
|
|
{
|
2005-07-12 01:56:14 +00:00
|
|
|
Length = Param->CurrentDirectory.DosPath.Length / sizeof(WCHAR);
|
|
|
|
if (Param->CurrentDirectory.DosPath.Buffer[Length-1] != L'\\')
|
2000-12-28 20:38:28 +00:00
|
|
|
{
|
2005-07-12 01:56:14 +00:00
|
|
|
Param->CurrentDirectory.DosPath.Buffer[Length] = L'\\';
|
|
|
|
Param->CurrentDirectory.DosPath.Buffer[Length + 1] = 0;
|
|
|
|
Param->CurrentDirectory.DosPath.Length += sizeof(WCHAR);
|
2000-12-28 20:38:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy dll path */
|
|
|
|
RtlpCopyParameterString(&Dest,
|
|
|
|
&Param->DllPath,
|
|
|
|
DllPath,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* copy image path name */
|
|
|
|
RtlpCopyParameterString(&Dest,
|
|
|
|
&Param->ImagePathName,
|
|
|
|
ImagePathName,
|
|
|
|
ImagePathName->Length + sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* copy command line */
|
|
|
|
RtlpCopyParameterString(&Dest,
|
|
|
|
&Param->CommandLine,
|
|
|
|
CommandLine,
|
|
|
|
CommandLine->Length + sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* copy title */
|
|
|
|
RtlpCopyParameterString(&Dest,
|
|
|
|
&Param->WindowTitle,
|
|
|
|
WindowTitle,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* copy desktop */
|
|
|
|
RtlpCopyParameterString(&Dest,
|
|
|
|
&Param->DesktopInfo,
|
|
|
|
DesktopInfo,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* copy shell info */
|
|
|
|
RtlpCopyParameterString(&Dest,
|
|
|
|
&Param->ShellInfo,
|
|
|
|
ShellInfo,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* copy runtime info */
|
|
|
|
RtlpCopyParameterString(&Dest,
|
2005-07-12 01:56:14 +00:00
|
|
|
&Param->RuntimeData,
|
|
|
|
RuntimeData,
|
2000-12-28 20:38:28 +00:00
|
|
|
0);
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
RtlDeNormalizeProcessParams(Param);
|
2000-12-28 20:38:28 +00:00
|
|
|
*ProcessParameters = Param;
|
|
|
|
RtlReleasePebLock();
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
|
|
|
|
2003-07-11 13:50:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2010-10-16 14:20:30 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RtlDestroyProcessParameters(IN PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2010-10-16 14:20:30 +00:00
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, ProcessParameters);
|
|
|
|
return STATUS_SUCCESS;
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* denormalize process parameters (Pointer-->Offset)
|
2003-07-11 13:50:23 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
2000-02-13 16:05:19 +00:00
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS NTAPI
|
2002-09-08 10:23:54 +00:00
|
|
|
RtlDeNormalizeProcessParams(PRTL_USER_PROCESS_PARAMETERS Params)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2005-11-27 18:24:32 +00:00
|
|
|
if (Params && (Params->Flags & RTL_USER_PROCESS_PARAMETERS_NORMALIZED))
|
2000-12-28 20:38:28 +00:00
|
|
|
{
|
2005-07-12 01:56:14 +00:00
|
|
|
DENORMALIZE(Params->CurrentDirectory.DosPath.Buffer, Params);
|
2000-12-28 20:38:28 +00:00
|
|
|
DENORMALIZE(Params->DllPath.Buffer, Params);
|
|
|
|
DENORMALIZE(Params->ImagePathName.Buffer, Params);
|
|
|
|
DENORMALIZE(Params->CommandLine.Buffer, Params);
|
|
|
|
DENORMALIZE(Params->WindowTitle.Buffer, Params);
|
|
|
|
DENORMALIZE(Params->DesktopInfo.Buffer, Params);
|
|
|
|
DENORMALIZE(Params->ShellInfo.Buffer, Params);
|
2005-07-12 01:56:14 +00:00
|
|
|
DENORMALIZE(Params->RuntimeData.Buffer, Params);
|
2000-12-28 20:38:28 +00:00
|
|
|
|
2005-11-27 18:24:32 +00:00
|
|
|
Params->Flags &= ~RTL_USER_PROCESS_PARAMETERS_NORMALIZED;
|
2000-12-28 20:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Params;
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* normalize process parameters (Offset-->Pointer)
|
2003-07-11 13:50:23 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
2000-02-13 16:05:19 +00:00
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS NTAPI
|
2002-09-08 10:23:54 +00:00
|
|
|
RtlNormalizeProcessParams(PRTL_USER_PROCESS_PARAMETERS Params)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2005-11-27 18:24:32 +00:00
|
|
|
if (Params && !(Params->Flags & RTL_USER_PROCESS_PARAMETERS_NORMALIZED))
|
2000-12-28 20:38:28 +00:00
|
|
|
{
|
2005-07-12 01:56:14 +00:00
|
|
|
NORMALIZE(Params->CurrentDirectory.DosPath.Buffer, Params);
|
2000-12-28 20:38:28 +00:00
|
|
|
NORMALIZE(Params->DllPath.Buffer, Params);
|
|
|
|
NORMALIZE(Params->ImagePathName.Buffer, Params);
|
|
|
|
NORMALIZE(Params->CommandLine.Buffer, Params);
|
|
|
|
NORMALIZE(Params->WindowTitle.Buffer, Params);
|
|
|
|
NORMALIZE(Params->DesktopInfo.Buffer, Params);
|
|
|
|
NORMALIZE(Params->ShellInfo.Buffer, Params);
|
2005-07-12 01:56:14 +00:00
|
|
|
NORMALIZE(Params->RuntimeData.Buffer, Params);
|
2000-12-28 20:38:28 +00:00
|
|
|
|
2005-11-27 18:24:32 +00:00
|
|
|
Params->Flags |= RTL_USER_PROCESS_PARAMETERS_NORMALIZED;
|
2000-12-28 20:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Params;
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
2000-02-18 00:51:03 +00:00
|
|
|
|
|
|
|
/* EOF */
|