2002-03-14 16:32:49 +00:00
|
|
|
/* $Id: ppb.c,v 1.11 2002/03/14 16:32:49 hbirr Exp $
|
2000-02-13 16:05:19 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/ntdll/rtl/ppb.c
|
2000-02-18 00:51:03 +00:00
|
|
|
* PURPOSE: Process parameters functions
|
2000-02-13 16:05:19 +00:00
|
|
|
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* Created 01/11/98
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ****************************************************************/
|
|
|
|
|
|
|
|
#include <ddk/ntddk.h>
|
|
|
|
#include <ntdll/ldr.h>
|
2000-06-29 23:35:53 +00:00
|
|
|
#include <napi/teb.h>
|
2000-02-13 16:05:19 +00:00
|
|
|
#include <ntdll/base.h>
|
|
|
|
#include <ntdll/rtl.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <ntdll/ntdll.h>
|
|
|
|
|
2000-02-18 00:51:03 +00:00
|
|
|
/* MACROS ****************************************************************/
|
|
|
|
|
|
|
|
#define NORMALIZE(x,addr) {if(x) x=(VOID*)((ULONG)(x)+(ULONG)(addr));}
|
|
|
|
#define DENORMALIZE(x,addr) {if(x) x=(VOID*)((ULONG)(x)-(ULONG)(addr));}
|
|
|
|
#define ALIGN(x,align) (((ULONG)(x)+(align)-1UL)&(~((align)-1UL)))
|
|
|
|
|
|
|
|
|
2000-02-13 16:05:19 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2000-12-28 20:38:28 +00:00
|
|
|
VOID STDCALL
|
|
|
|
RtlAcquirePebLock(VOID)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2000-12-28 20:38:28 +00:00
|
|
|
PPEB Peb = NtCurrentPeb ();
|
|
|
|
Peb->FastPebLockRoutine (Peb->FastPebLock);
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-28 20:38:28 +00:00
|
|
|
VOID STDCALL
|
|
|
|
RtlReleasePebLock(VOID)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2000-12-28 20:38:28 +00:00
|
|
|
PPEB Peb = NtCurrentPeb ();
|
|
|
|
Peb->FastPebUnlockRoutine (Peb->FastPebLock);
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
|
|
|
|
2000-12-28 20:38:28 +00:00
|
|
|
static inline VOID
|
|
|
|
RtlpCopyParameterString(PWCHAR *Ptr,
|
|
|
|
PUNICODE_STRING Destination,
|
|
|
|
PUNICODE_STRING Source,
|
|
|
|
ULONG 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-28 20:38:28 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
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 RuntimeInfo)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2000-03-22 18:36:00 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PRTL_USER_PROCESS_PARAMETERS Param = NULL;
|
|
|
|
ULONG RegionSize = 0;
|
|
|
|
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"";
|
|
|
|
|
|
|
|
if (NtCurrentPeb()->ProcessParameters)
|
|
|
|
{
|
|
|
|
if (DllPath == NULL)
|
|
|
|
DllPath = &NtCurrentPeb()->ProcessParameters->DllPath;
|
|
|
|
if (Environment == NULL)
|
|
|
|
Environment = NtCurrentPeb()->ProcessParameters->Environment;
|
|
|
|
if (CurrentDirectory == NULL)
|
|
|
|
CurrentDirectory = &NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath;
|
|
|
|
CurrentDirectoryHandle = NtCurrentPeb()->ProcessParameters->CurrentDirectory.Handle;
|
|
|
|
ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
ConsoleFlags = NtCurrentPeb()->ProcessParameters->ConsoleFlags;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
if (RuntimeInfo == NULL)
|
|
|
|
RuntimeInfo = &EmptyString;
|
|
|
|
|
|
|
|
/* size of process parameter block */
|
|
|
|
Length = sizeof(RTL_USER_PROCESS_PARAMETERS);
|
|
|
|
|
|
|
|
/* size of current directory buffer */
|
|
|
|
Length += (MAX_PATH * sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* add string lengths */
|
|
|
|
Length += ALIGN(DllPath->MaximumLength, sizeof(ULONG));
|
|
|
|
Length += ALIGN(ImagePathName->Length, sizeof(ULONG));
|
|
|
|
Length += ALIGN(CommandLine->Length, sizeof(ULONG));
|
|
|
|
Length += ALIGN(WindowTitle->MaximumLength, sizeof(ULONG));
|
|
|
|
Length += ALIGN(DesktopInfo->MaximumLength, sizeof(ULONG));
|
|
|
|
Length += ALIGN(ShellInfo->MaximumLength, sizeof(ULONG));
|
|
|
|
Length += ALIGN(RuntimeInfo->MaximumLength, sizeof(ULONG));
|
|
|
|
|
|
|
|
/* Calculate the required block size */
|
|
|
|
RegionSize = ROUNDUP(Length, PAGESIZE);
|
|
|
|
|
|
|
|
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
|
|
|
|
(PVOID*)&Param,
|
|
|
|
0,
|
|
|
|
&RegionSize,
|
2001-08-07 14:13:45 +00:00
|
|
|
MEM_RESERVE | MEM_COMMIT,
|
2000-12-28 20:38:28 +00:00
|
|
|
PAGE_READWRITE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
RtlReleasePebLock();
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT ("Process parameters allocated\n");
|
|
|
|
|
|
|
|
Param->MaximumLength = RegionSize;
|
|
|
|
Param->Length = Length;
|
|
|
|
Param->Flags = PPF_NORMALIZED;
|
|
|
|
Param->Environment = Environment;
|
|
|
|
Param->CurrentDirectory.Handle = CurrentDirectoryHandle;
|
|
|
|
Param->ConsoleHandle = ConsoleHandle;
|
|
|
|
Param->ConsoleFlags = ConsoleFlags;
|
|
|
|
|
|
|
|
Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS));
|
|
|
|
|
|
|
|
/* copy current directory */
|
|
|
|
RtlpCopyParameterString(&Dest,
|
|
|
|
&Param->CurrentDirectory.DosPath,
|
|
|
|
CurrentDirectory,
|
|
|
|
MAX_PATH * sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* make sure the current directory has a trailing backslash */
|
|
|
|
if (Param->CurrentDirectory.DosPath.Length > 0)
|
|
|
|
{
|
|
|
|
ULONG Length;
|
|
|
|
|
|
|
|
Length = Param->CurrentDirectory.DosPath.Length / sizeof(WCHAR);
|
|
|
|
if (Param->CurrentDirectory.DosPath.Buffer[Length-1] != L'\\')
|
|
|
|
{
|
|
|
|
Param->CurrentDirectory.DosPath.Buffer[Length] = L'\\';
|
|
|
|
Param->CurrentDirectory.DosPath.Buffer[Length + 1] = 0;
|
|
|
|
Param->CurrentDirectory.DosPath.Length += sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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,
|
|
|
|
&Param->RuntimeInfo,
|
|
|
|
RuntimeInfo,
|
|
|
|
0);
|
|
|
|
|
|
|
|
RtlDeNormalizeProcessParams(Param);
|
|
|
|
*ProcessParameters = Param;
|
|
|
|
RtlReleasePebLock();
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
|
|
|
|
2000-12-28 20:38:28 +00:00
|
|
|
VOID STDCALL
|
|
|
|
RtlDestroyProcessParameters(PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2000-12-28 20:38:28 +00:00
|
|
|
ULONG RegionSize = 0;
|
2000-02-13 16:05:19 +00:00
|
|
|
|
2000-12-28 20:38:28 +00:00
|
|
|
NtFreeVirtualMemory (NtCurrentProcess (),
|
|
|
|
(PVOID)ProcessParameters,
|
|
|
|
&RegionSize,
|
|
|
|
MEM_RELEASE);
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* denormalize process parameters (Pointer-->Offset)
|
|
|
|
*/
|
2000-12-28 20:38:28 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS STDCALL
|
|
|
|
RtlDeNormalizeProcessParams(PRTL_USER_PROCESS_PARAMETERS Params)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2000-12-28 20:38:28 +00:00
|
|
|
if (Params && (Params->Flags & PPF_NORMALIZED))
|
|
|
|
{
|
|
|
|
DENORMALIZE(Params->CurrentDirectory.DosPath.Buffer, Params);
|
|
|
|
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);
|
|
|
|
DENORMALIZE(Params->RuntimeInfo.Buffer, Params);
|
|
|
|
|
|
|
|
Params->Flags &= ~PPF_NORMALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Params;
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* normalize process parameters (Offset-->Pointer)
|
|
|
|
*/
|
2000-12-28 20:38:28 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS STDCALL
|
|
|
|
RtlNormalizeProcessParams(PRTL_USER_PROCESS_PARAMETERS Params)
|
2000-02-13 16:05:19 +00:00
|
|
|
{
|
2000-12-28 20:38:28 +00:00
|
|
|
if (Params && !(Params->Flags & PPF_NORMALIZED))
|
|
|
|
{
|
|
|
|
NORMALIZE(Params->CurrentDirectory.DosPath.Buffer, Params);
|
|
|
|
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);
|
|
|
|
NORMALIZE(Params->RuntimeInfo.Buffer, Params);
|
|
|
|
|
|
|
|
Params->Flags |= PPF_NORMALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Params;
|
2000-02-13 16:05:19 +00:00
|
|
|
}
|
2000-02-18 00:51:03 +00:00
|
|
|
|
|
|
|
/* EOF */
|