Fixed bugs in process parameter and environment code

svn path=/trunk/; revision=992
This commit is contained in:
Eric Kohl 2000-02-19 19:37:13 +00:00
parent e632116bee
commit b9bb1744aa
8 changed files with 257 additions and 229 deletions

View file

@ -33,34 +33,34 @@ typedef struct _PEB_FREE_BLOCK
typedef struct _RTL_USER_PROCESS_PARAMETERS typedef struct _RTL_USER_PROCESS_PARAMETERS
{ {
ULONG TotalSize; // 00h ULONG MaximumLength; // 00h
ULONG DataSize; // 04h ULONG Length; // 04h
ULONG Flags; // 08h ULONG Flags; // 08h
ULONG DebugFlags; // 0Ch ULONG DebugFlags; // 0Ch
PVOID ConsoleHandle; // 10h PVOID ConsoleHandle; // 10h
ULONG ConsoleFlags; // 14h ULONG ConsoleFlags; // 14h
HANDLE InputHandle; // 18h HANDLE InputHandle; // 18h
HANDLE OutputHandle; // 1Ch HANDLE OutputHandle; // 1Ch
HANDLE ErrorHandle; // 20h HANDLE ErrorHandle; // 20h
CURDIR CurrentDirectory; // 24h CURDIR CurrentDirectory; // 24h
UNICODE_STRING LibraryPath; // 30h UNICODE_STRING DllPath; // 30h
UNICODE_STRING CommandLine; // 38h UNICODE_STRING ImagePathName; // 38h
UNICODE_STRING ImageName; // 40h UNICODE_STRING CommandLine; // 40h
PVOID Environment; // 48h PVOID Environment; // 48h
DWORD X; // 4Ch ULONG StartingX; // 4Ch
DWORD Y; // 50h ULONG StartingY; // 50h
DWORD XSize; // 54h ULONG CountX; // 54h
DWORD YSize; // 58h ULONG CountY; // 58h
DWORD XCountChars; // 5Ch ULONG CountCharsX; // 5Ch
DWORD YCountChars; // 60h ULONG CountCharsY; // 60h
DWORD FillAttribute; // 64h ULONG FillAttribute; // 64h
DWORD WindowFlags; // 68h ULONG WindowFlags; // 68h
DWORD ShowWindow; // 6Ch ULONG ShowWindowFlags; // 6Ch
UNICODE_STRING Title; // 70h UNICODE_STRING WindowTitle; // 70h
UNICODE_STRING Desktop; // 78h UNICODE_STRING DesktopInfo; // 78h
UNICODE_STRING ShellInfo; // 80h UNICODE_STRING ShellInfo; // 80h
UNICODE_STRING RuntimeData; // 88h UNICODE_STRING RuntimeData; // 88h
RTL_DRIVE_LETTER_CURDIR RtlCurrentDirectory[0x20]; // 90h RTL_DRIVE_LETTER_CURDIR DLCurrentDirectory[0x20]; // 90h
} RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS; } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
#define PEB_BASE (0x7FFDF000) #define PEB_BASE (0x7FFDF000)

View file

@ -1,4 +1,4 @@
/* $Id: rtl.h,v 1.9 2000/02/18 00:48:25 ekohl Exp $ /* $Id: rtl.h,v 1.10 2000/02/19 19:33:28 ekohl Exp $
* *
*/ */
@ -193,14 +193,14 @@ STDCALL
RtlCreateProcessParameters ( RtlCreateProcessParameters (
IN OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters, IN OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
IN PUNICODE_STRING CommandLine, IN PUNICODE_STRING CommandLine,
IN PUNICODE_STRING LibraryPath, IN PUNICODE_STRING DllPath,
IN PUNICODE_STRING CurrentDirectory, IN PUNICODE_STRING CurrentDirectory,
IN PUNICODE_STRING ImageName, IN PUNICODE_STRING ImagePathName,
IN PVOID Environment, IN PVOID Environment,
IN PUNICODE_STRING Title, IN PUNICODE_STRING WindowTitle,
IN PUNICODE_STRING Desktop, IN PUNICODE_STRING DesktopInfo,
IN PUNICODE_STRING Reserved, IN PUNICODE_STRING ShellInfo,
IN PUNICODE_STRING Reserved2 IN PUNICODE_STRING RuntimeData
); );
PRTL_USER_PROCESS_PARAMETERS PRTL_USER_PROCESS_PARAMETERS

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.21 2000/02/18 00:50:07 ekohl Exp $ /* $Id: create.c,v 1.22 2000/02/19 19:35:57 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -326,7 +326,7 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
/* create the PPB */ /* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO; PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = Ppb->TotalSize; PpbSize = Ppb->MaximumLength;
Status = NtAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&PpbBase, &PpbBase,
0, 0,
@ -338,11 +338,11 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
return(Status); return(Status);
} }
DPRINT("Ppb->TotalSize %x\n", Ppb->TotalSize); DPRINT("Ppb->MaximumLength %x\n", Ppb->MaximumLength);
NtWriteVirtualMemory(ProcessHandle, NtWriteVirtualMemory(ProcessHandle,
PpbBase, PpbBase,
Ppb, Ppb,
Ppb->TotalSize, Ppb->MaximumLength,
&BytesWritten); &BytesWritten);
/* write pointer to environment */ /* write pointer to environment */

View file

@ -1,4 +1,4 @@
/* $Id: proc.c,v 1.29 2000/01/27 08:56:47 dwelch Exp $ /* $Id: proc.c,v 1.30 2000/02/19 19:35:57 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -12,6 +12,7 @@
/* INCLUDES ****************************************************************/ /* INCLUDES ****************************************************************/
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <ntdll/rtl.h>
#include <windows.h> #include <windows.h>
#include <kernel32/proc.h> #include <kernel32/proc.h>
#include <kernel32/thread.h> #include <kernel32/thread.h>
@ -23,40 +24,20 @@
#define NDEBUG #define NDEBUG
#include <kernel32/kernel32.h> #include <kernel32/kernel32.h>
/* TYPES *********************************************************************/
/*
typedef struct _WSTARTUPINFO {
DWORD cb;
LPWSTR lpReserved;
LPWSTR lpDesktop;
LPWSTR lpTitle;
DWORD dwX;
DWORD dwY;
DWORD dwXSize;
DWORD dwYSize;
DWORD dwXCountChars;
DWORD dwYCountChars;
DWORD dwFillAttribute;
DWORD dwFlags;
WORD wShowWindow;
WORD cbReserved2;
LPBYTE lpReserved2;
HANDLE hStdInput;
HANDLE hStdOutput;
HANDLE hStdError;
} WSTARTUPINFO, *LPWSTARTUPINFO;
*/
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle; WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle;
LPSTARTUPINFO lpLocalStartupInfo = NULL;
VOID VOID
STDCALL STDCALL
RegisterWaitForInputIdle ( RegisterWaitForInputIdle (
WaitForInputIdleType lpfnRegisterWaitForInputIdle WaitForInputIdleType lpfnRegisterWaitForInputIdle
); );
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
WINBOOL WINBOOL
@ -119,7 +100,7 @@ GetExitCodeProcess (
&ProcessBasic, &ProcessBasic,
sizeof(PROCESS_BASIC_INFORMATION), sizeof(PROCESS_BASIC_INFORMATION),
&BytesWritten); &BytesWritten);
if (!NT_SUCCESS(errCode)) if (!NT_SUCCESS(errCode))
{ {
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError(RtlNtStatusToDosError(errCode));
return FALSE; return FALSE;
@ -145,13 +126,13 @@ GetProcessId (
&ProcessBasic, &ProcessBasic,
sizeof(PROCESS_BASIC_INFORMATION), sizeof(PROCESS_BASIC_INFORMATION),
&BytesWritten); &BytesWritten);
if (!NT_SUCCESS(errCode)) if (!NT_SUCCESS(errCode))
{ {
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError(RtlNtStatusToDosError(errCode));
return FALSE; return FALSE;
} }
memcpy( lpProcessId ,&ProcessBasic.UniqueProcessId,sizeof(DWORD)); memcpy( lpProcessId ,&ProcessBasic.UniqueProcessId,sizeof(DWORD));
return TRUE; return TRUE;
} }
@ -210,11 +191,11 @@ OpenProcess (
else else
ObjectAttributes.Attributes = 0; ObjectAttributes.Attributes = 0;
errCode = NtOpenProcess(&ProcessHandle, errCode = NtOpenProcess(&ProcessHandle,
dwDesiredAccess, dwDesiredAccess,
&ObjectAttributes, &ObjectAttributes,
&ClientId); &ClientId);
if (!NT_SUCCESS(errCode)) if (!NT_SUCCESS(errCode))
{ {
SetLastError(RtlNtStatusToDosError(errCode)); SetLastError(RtlNtStatusToDosError(errCode));
return NULL; return NULL;
@ -234,7 +215,7 @@ WinExec (
PROCESS_INFORMATION ProcessInformation; PROCESS_INFORMATION ProcessInformation;
HINSTANCE hInst; HINSTANCE hInst;
DWORD dosErr; DWORD dosErr;
StartupInfo.cb = sizeof(STARTUPINFOA); StartupInfo.cb = sizeof(STARTUPINFOA);
StartupInfo.wShowWindow = uCmdShow; StartupInfo.wShowWindow = uCmdShow;
StartupInfo.dwFlags = 0; StartupInfo.dwFlags = 0;
@ -247,9 +228,9 @@ WinExec (
0, 0,
NULL, NULL,
NULL, NULL,
&StartupInfo, &StartupInfo,
&ProcessInformation); &ProcessInformation);
if ( hInst == NULL ) if ( hInst == NULL )
{ {
dosErr = GetLastError(); dosErr = GetLastError();
return dosErr; return dosErr;
@ -294,10 +275,10 @@ DWORD STDCALL SleepEx(DWORD dwMilliseconds,
BOOL bAlertable) BOOL bAlertable)
{ {
TIME Interval; TIME Interval;
NTSTATUS errCode; NTSTATUS errCode;
Interval.QuadPart = dwMilliseconds * 1000; Interval.QuadPart = dwMilliseconds * 1000;
errCode = NtDelayExecution(bAlertable,&Interval); errCode = NtDelayExecution(bAlertable,&Interval);
if (!NT_SUCCESS(errCode)) if (!NT_SUCCESS(errCode))
{ {
@ -314,7 +295,7 @@ GetStartupInfoW (
LPSTARTUPINFOW lpStartupInfo LPSTARTUPINFOW lpStartupInfo
) )
{ {
PPEB pPeb = NtCurrentPeb(); PRTL_USER_PROCESS_PARAMETERS Params;
if (lpStartupInfo == NULL) if (lpStartupInfo == NULL)
{ {
@ -322,25 +303,27 @@ GetStartupInfoW (
return; return;
} }
lpStartupInfo->cb = sizeof(STARTUPINFOW); Params = NtCurrentPeb ()->ProcessParameters;
// lstrcpyW(lpStartupInfo->lpDesktop, pPeb->Ppb->Desktop);
// lstrcpyW(lpStartupInfo->lpTitle, pPeb->Ppb->Title);
lpStartupInfo->dwX = pPeb->ProcessParameters->X;
lpStartupInfo->dwY = pPeb->ProcessParameters->Y;
lpStartupInfo->dwXSize = pPeb->ProcessParameters->XSize;
lpStartupInfo->dwYSize = pPeb->ProcessParameters->YSize;
lpStartupInfo->dwXCountChars = pPeb->ProcessParameters->XCountChars;
lpStartupInfo->dwYCountChars = pPeb->ProcessParameters->YCountChars;
lpStartupInfo->dwFillAttribute = pPeb->ProcessParameters->FillAttribute;
lpStartupInfo->dwFlags = pPeb->ProcessParameters->Flags;
lpStartupInfo->wShowWindow = pPeb->ProcessParameters->ShowWindow;
// lpStartupInfo->lpReserved = pPeb->ProcessParameters->lpReserved1;
// lpStartupInfo->cbReserved2 = pPeb->ProcessParameters->cbReserved;
// lpStartupInfo->lpReserved2 = pPeb->ProcessParameters->lpReserved2;
lpStartupInfo->hStdInput = pPeb->ProcessParameters->InputHandle; lpStartupInfo->cb = sizeof(STARTUPINFOW);
lpStartupInfo->hStdOutput = pPeb->ProcessParameters->OutputHandle; lpStartupInfo->lpDesktop = Params->DesktopInfo.Buffer;
lpStartupInfo->hStdError = pPeb->ProcessParameters->ErrorHandle; lpStartupInfo->lpTitle = Params->WindowTitle.Buffer;
lpStartupInfo->dwX = Params->StartingX;
lpStartupInfo->dwY = Params->StartingY;
lpStartupInfo->dwXSize = Params->CountX;
lpStartupInfo->dwYSize = Params->CountY;
lpStartupInfo->dwXCountChars = Params->CountCharsX;
lpStartupInfo->dwYCountChars = Params->CountCharsY;
lpStartupInfo->dwFillAttribute = Params->FillAttribute;
lpStartupInfo->dwFlags = Params->Flags;
lpStartupInfo->wShowWindow = Params->ShowWindowFlags;
lpStartupInfo->lpReserved = Params->ShellInfo.Buffer;
lpStartupInfo->cbReserved2 = Params->RuntimeData.Length;
lpStartupInfo->lpReserved2 = (LPBYTE)Params->RuntimeData.Buffer;
lpStartupInfo->hStdInput = Params->InputHandle;
lpStartupInfo->hStdOutput = Params->OutputHandle;
lpStartupInfo->hStdError = Params->ErrorHandle;
} }
@ -350,8 +333,8 @@ GetStartupInfoA (
LPSTARTUPINFOA lpStartupInfo LPSTARTUPINFOA lpStartupInfo
) )
{ {
PPEB pPeb = NtCurrentPeb(); PRTL_USER_PROCESS_PARAMETERS Params;
ULONG i = 0; ANSI_STRING AnsiString;
if (lpStartupInfo == NULL) if (lpStartupInfo == NULL)
{ {
@ -359,49 +342,68 @@ GetStartupInfoA (
return; return;
} }
lpStartupInfo->cb = sizeof(STARTUPINFOA); Params = NtCurrentPeb ()->ProcessParameters;
#if 0
i = 0;
while ((pPeb->ProcessParameters->Desktop[i])!=0 && i < MAX_PATH)
{
lpStartupInfo->lpDesktop[i] = (unsigned char)
pPeb->ProcessParameters->Desktop[i];
i++;
}
lpStartupInfo->lpDesktop[i] = 0;
i = 0; RtlAcquirePebLock ();
while ((pPeb->ProcessParameters->Title[i])!=0 && i < MAX_PATH)
{
lpStartupInfo->lpTitle[i] = (unsigned char)pPeb->ProcessParameters->Title[i];
i++;
}
lpStartupInfo->lpTitle[i] = 0;
#endif
lpStartupInfo->dwX = pPeb->ProcessParameters->X;
lpStartupInfo->dwY = pPeb->ProcessParameters->Y;
lpStartupInfo->dwXSize = pPeb->ProcessParameters->XSize;
lpStartupInfo->dwYSize = pPeb->ProcessParameters->YSize;
lpStartupInfo->dwXCountChars = pPeb->ProcessParameters->XCountChars;
lpStartupInfo->dwYCountChars = pPeb->ProcessParameters->YCountChars;
lpStartupInfo->dwFillAttribute = pPeb->ProcessParameters->FillAttribute;
lpStartupInfo->dwFlags = pPeb->ProcessParameters->Flags;
lpStartupInfo->wShowWindow = pPeb->ProcessParameters->ShowWindow;
// lpStartupInfo->cbReserved2 = pPeb->ProcessParameters->cbReserved;
// lpStartupInfo->lpReserved = pPeb->ProcessParameters->lpReserved1;
// lpStartupInfo->lpReserved2 = pPeb->ProcessParameters->lpReserved2;
lpStartupInfo->hStdInput = pPeb->ProcessParameters->InputHandle; if (lpLocalStartupInfo == NULL)
lpStartupInfo->hStdOutput = pPeb->ProcessParameters->OutputHandle; {
lpStartupInfo->hStdError = pPeb->ProcessParameters->ErrorHandle; /* create new local startup info (ansi) */
lpLocalStartupInfo = RtlAllocateHeap (RtlGetProcessHeap (),
0,
sizeof(STARTUPINFOA));
lpLocalStartupInfo->cb = sizeof(STARTUPINFOA);
/* copy window title string */
RtlUnicodeStringToAnsiString (&AnsiString,
&Params->WindowTitle,
TRUE);
lpLocalStartupInfo->lpTitle = AnsiString.Buffer;
/* copy desktop info string */
RtlUnicodeStringToAnsiString (&AnsiString,
&Params->DesktopInfo,
TRUE);
lpLocalStartupInfo->lpDesktop = AnsiString.Buffer;
/* copy shell info string */
RtlUnicodeStringToAnsiString (&AnsiString,
&Params->ShellInfo,
TRUE);
lpLocalStartupInfo->lpReserved = AnsiString.Buffer;
lpLocalStartupInfo->dwX = Params->StartingX;
lpLocalStartupInfo->dwY = Params->StartingY;
lpLocalStartupInfo->dwXSize = Params->CountX;
lpLocalStartupInfo->dwYSize = Params->CountY;
lpLocalStartupInfo->dwXCountChars = Params->CountCharsX;
lpLocalStartupInfo->dwYCountChars = Params->CountCharsY;
lpLocalStartupInfo->dwFillAttribute = Params->FillAttribute;
lpLocalStartupInfo->dwFlags = Params->Flags;
lpLocalStartupInfo->wShowWindow = Params->ShowWindowFlags;
lpLocalStartupInfo->cbReserved2 = Params->RuntimeData.Length;
lpLocalStartupInfo->lpReserved2 = (LPBYTE)Params->RuntimeData.Buffer;
lpLocalStartupInfo->hStdInput = Params->InputHandle;
lpLocalStartupInfo->hStdOutput = Params->OutputHandle;
lpLocalStartupInfo->hStdError = Params->ErrorHandle;
}
RtlReleasePebLock ();
/* copy local startup info data to external startup info */
memcpy (lpStartupInfo,
lpLocalStartupInfo,
sizeof(STARTUPINFOA));
} }
BOOL BOOL
STDCALL STDCALL
FlushInstructionCache ( FlushInstructionCache (
HANDLE hProcess, HANDLE hProcess,
LPCVOID lpBaseAddress, LPCVOID lpBaseAddress,
DWORD dwSize DWORD dwSize
) )
{ {
@ -483,5 +485,4 @@ FatalAppExitW (
return; return;
} }
/* EOF */ /* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: env.c,v 1.7 2000/02/18 00:49:11 ekohl Exp $ /* $Id: env.c,v 1.8 2000/02/19 19:34:49 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -229,8 +229,9 @@ RtlSetEnvironmentVariable (
UNICODE_STRING var; UNICODE_STRING var;
int hole_len, new_len, env_len = 0; int hole_len, new_len, env_len = 0;
WCHAR *new_env = 0, *env_end = 0, *wcs, *env, *val = 0, *tail = 0, *hole = 0; WCHAR *new_env = 0, *env_end = 0, *wcs, *env, *val = 0, *tail = 0, *hole = 0;
ULONG size = 0, new_size; PWSTR head = NULL;
LONG f = 1; ULONG size = 0, new_size;
LONG f = 1;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
DPRINT ("RtlSetEnvironmentVariable Environment %p Name %wZ Value %wZ\n", DPRINT ("RtlSetEnvironmentVariable Environment %p Name %wZ Value %wZ\n",
@ -275,6 +276,7 @@ RtlSetEnvironmentVariable (
} }
else /* Exact match */ else /* Exact match */
{ {
head = var.Buffer;
tail = ++wcs; tail = ++wcs;
hole = val; hole = val;
} }
@ -366,14 +368,10 @@ found:
if (env) if (env)
{ {
size = 0; size = 0;
CHECKPOINT;
DPRINT ("env %x\n", env);
DPRINT ("&env %x\n", &env);
NtFreeVirtualMemory (NtCurrentProcess (), NtFreeVirtualMemory (NtCurrentProcess (),
(VOID**)&env, (VOID**)&env,
&size, &size,
MEM_RELEASE); MEM_RELEASE);
CHECKPOINT;
} }
} }
@ -395,7 +393,7 @@ CHECKPOINT;
{ {
/* remove the environment variable */ /* remove the environment variable */
if (f == 0) if (f == 0)
memmove (hole, memmove (head,
tail, tail,
(env_end - tail) * sizeof(WCHAR)); (env_end - tail) * sizeof(WCHAR));
else else
@ -423,7 +421,7 @@ RtlQueryEnvironmentVariable_U (
int len; int len;
DPRINT("RtlQueryEnvironmentVariable_U Environment %p Variable %wZ Value %p\n", DPRINT("RtlQueryEnvironmentVariable_U Environment %p Variable %wZ Value %p\n",
Environment, varname, Value); Environment, Name, Value);
if (!Environment) if (!Environment)
Environment = NtCurrentPeb()->ProcessParameters->Environment; Environment = NtCurrentPeb()->ProcessParameters->Environment;

View file

@ -1,4 +1,4 @@
/* $Id: ppb.c,v 1.3 2000/02/18 00:49:11 ekohl Exp $ /* $Id: ppb.c,v 1.4 2000/02/19 19:34:49 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -70,23 +70,24 @@ STDCALL
RtlCreateProcessParameters ( RtlCreateProcessParameters (
PRTL_USER_PROCESS_PARAMETERS *Ppb, PRTL_USER_PROCESS_PARAMETERS *Ppb,
PUNICODE_STRING CommandLine, PUNICODE_STRING CommandLine,
PUNICODE_STRING LibraryPath, PUNICODE_STRING DllPath,
PUNICODE_STRING CurrentDirectory, PUNICODE_STRING CurrentDirectory,
PUNICODE_STRING ImageName, PUNICODE_STRING ImagePathName,
PVOID Environment, PVOID Environment,
PUNICODE_STRING Title, PUNICODE_STRING WindowTitle,
PUNICODE_STRING Desktop, PUNICODE_STRING DesktopInfo,
PUNICODE_STRING Reserved, PUNICODE_STRING ShellInfo,
PUNICODE_STRING Reserved2 PUNICODE_STRING RuntimeData
) )
{ {
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
PRTL_USER_PROCESS_PARAMETERS Param = NULL; PRTL_USER_PROCESS_PARAMETERS Param = NULL;
ULONG RegionSize = 0; ULONG RegionSize = 0;
ULONG DataSize = 0; ULONG Length = 0;
PWCHAR Dest; PWCHAR Dest;
UNICODE_STRING EmptyString; UNICODE_STRING EmptyString;
HANDLE CurrentDirectoryHandle; HANDLE CurrentDirectoryHandle;
HANDLE ConsoleHandle;
ULONG ConsoleFlags; ULONG ConsoleFlags;
DPRINT ("RtlCreateProcessParameters\n"); DPRINT ("RtlCreateProcessParameters\n");
@ -99,53 +100,55 @@ RtlCreateProcessParameters (
if (NtCurrentPeb()->ProcessParameters) if (NtCurrentPeb()->ProcessParameters)
{ {
if (LibraryPath == NULL) if (DllPath == NULL)
LibraryPath = &NtCurrentPeb()->ProcessParameters->LibraryPath; DllPath = &NtCurrentPeb()->ProcessParameters->DllPath;
if (Environment == NULL) if (Environment == NULL)
Environment = NtCurrentPeb()->ProcessParameters->Environment; Environment = NtCurrentPeb()->ProcessParameters->Environment;
if (CurrentDirectory == NULL) if (CurrentDirectory == NULL)
CurrentDirectory = &NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath; CurrentDirectory = &NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath;
CurrentDirectoryHandle = NtCurrentPeb()->ProcessParameters->CurrentDirectory.Handle; CurrentDirectoryHandle = NtCurrentPeb()->ProcessParameters->CurrentDirectory.Handle;
ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
ConsoleFlags = NtCurrentPeb()->ProcessParameters->ConsoleFlags; ConsoleFlags = NtCurrentPeb()->ProcessParameters->ConsoleFlags;
} }
else else
{ {
if (LibraryPath == NULL) if (DllPath == NULL)
LibraryPath = &EmptyString; DllPath = &EmptyString;
if (CurrentDirectory == NULL) if (CurrentDirectory == NULL)
CurrentDirectory = &EmptyString; CurrentDirectory = &EmptyString;
CurrentDirectoryHandle = NULL; CurrentDirectoryHandle = NULL;
ConsoleHandle = NULL;
ConsoleFlags = 0; ConsoleFlags = 0;
} }
if (ImageName == NULL) if (ImagePathName == NULL)
ImageName = CommandLine; ImagePathName = CommandLine;
if (Title == NULL) if (WindowTitle == NULL)
Title = &EmptyString; WindowTitle = &EmptyString;
if (Desktop == NULL) if (DesktopInfo == NULL)
Desktop = &EmptyString; DesktopInfo = &EmptyString;
if (Reserved == NULL) if (ShellInfo == NULL)
Reserved = &EmptyString; ShellInfo = &EmptyString;
if (Reserved2 == NULL) if (RuntimeData == NULL)
Reserved2 = &EmptyString; RuntimeData = &EmptyString;
/* size of process parameter block */ /* size of process parameter block */
DataSize = sizeof (RTL_USER_PROCESS_PARAMETERS); Length = sizeof (RTL_USER_PROCESS_PARAMETERS);
/* size of current directory buffer */ /* size of current directory buffer */
DataSize += (MAX_PATH * sizeof(WCHAR)); Length += (MAX_PATH * sizeof(WCHAR));
/* add string lengths */ /* add string lengths */
DataSize += ALIGN(LibraryPath->MaximumLength, sizeof(ULONG)); Length += ALIGN(DllPath->MaximumLength, sizeof(ULONG));
DataSize += ALIGN(CommandLine->Length, sizeof(ULONG)); Length += ALIGN(CommandLine->Length, sizeof(ULONG));
DataSize += ALIGN(ImageName->Length, sizeof(ULONG)); Length += ALIGN(ImagePathName->Length, sizeof(ULONG));
DataSize += ALIGN(Title->MaximumLength, sizeof(ULONG)); Length += ALIGN(WindowTitle->MaximumLength, sizeof(ULONG));
DataSize += ALIGN(Desktop->MaximumLength, sizeof(ULONG)); Length += ALIGN(DesktopInfo->MaximumLength, sizeof(ULONG));
DataSize += ALIGN(Reserved->MaximumLength, sizeof(ULONG)); Length += ALIGN(ShellInfo->MaximumLength, sizeof(ULONG));
DataSize += ALIGN(Reserved2->MaximumLength, sizeof(ULONG)); Length += ALIGN(RuntimeData->MaximumLength, sizeof(ULONG));
/* Calculate the required block size */ /* Calculate the required block size */
RegionSize = ROUNDUP(DataSize, PAGESIZE); RegionSize = ROUNDUP(Length, PAGESIZE);
Status = NtAllocateVirtualMemory ( Status = NtAllocateVirtualMemory (
NtCurrentProcess (), NtCurrentProcess (),
@ -162,11 +165,12 @@ RtlCreateProcessParameters (
DPRINT ("Ppb allocated\n"); DPRINT ("Ppb allocated\n");
Param->TotalSize = RegionSize; Param->MaximumLength = RegionSize;
Param->DataSize = DataSize; Param->Length = Length;
Param->Flags = PPF_NORMALIZED; Param->Flags = PPF_NORMALIZED;
Param->Environment = Environment; Param->Environment = Environment;
Param->CurrentDirectory.Handle = CurrentDirectoryHandle; Param->CurrentDirectory.Handle = CurrentDirectoryHandle;
Param->ConsoleHandle = ConsoleHandle;
Param->ConsoleFlags = ConsoleFlags; Param->ConsoleFlags = ConsoleFlags;
Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS)); Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS));
@ -193,8 +197,8 @@ RtlCreateProcessParameters (
/* copy library path */ /* copy library path */
RtlpCopyParameterString (&Dest, RtlpCopyParameterString (&Dest,
&Param->LibraryPath, &Param->DllPath,
LibraryPath, DllPath,
0); 0);
/* copy command line */ /* copy command line */
@ -205,30 +209,30 @@ RtlCreateProcessParameters (
/* copy image name */ /* copy image name */
RtlpCopyParameterString (&Dest, RtlpCopyParameterString (&Dest,
&Param->ImageName, &Param->ImagePathName,
ImageName, ImagePathName,
ImageName->Length + sizeof(WCHAR)); ImagePathName->Length + sizeof(WCHAR));
/* copy title */ /* copy title */
RtlpCopyParameterString (&Dest, RtlpCopyParameterString (&Dest,
&Param->Title, &Param->WindowTitle,
Title, WindowTitle,
0); 0);
/* copy desktop */ /* copy desktop */
RtlpCopyParameterString (&Dest, RtlpCopyParameterString (&Dest,
&Param->Desktop, &Param->DesktopInfo,
Desktop, DesktopInfo,
0); 0);
RtlpCopyParameterString (&Dest, RtlpCopyParameterString (&Dest,
&Param->ShellInfo, &Param->ShellInfo,
Reserved, ShellInfo,
0); 0);
RtlpCopyParameterString (&Dest, RtlpCopyParameterString (&Dest,
&Param->RuntimeData, &Param->RuntimeData,
Reserved2, RuntimeData,
0); 0);
RtlDeNormalizeProcessParams (Param); RtlDeNormalizeProcessParams (Param);
@ -264,11 +268,11 @@ RtlDeNormalizeProcessParams (
if (Params && (Params->Flags & PPF_NORMALIZED)) if (Params && (Params->Flags & PPF_NORMALIZED))
{ {
DENORMALIZE (Params->CurrentDirectory.DosPath.Buffer, Params); DENORMALIZE (Params->CurrentDirectory.DosPath.Buffer, Params);
DENORMALIZE (Params->LibraryPath.Buffer, Params); DENORMALIZE (Params->DllPath.Buffer, Params);
DENORMALIZE (Params->CommandLine.Buffer, Params); DENORMALIZE (Params->CommandLine.Buffer, Params);
DENORMALIZE (Params->ImageName.Buffer, Params); DENORMALIZE (Params->ImagePathName.Buffer, Params);
DENORMALIZE (Params->Title.Buffer, Params); DENORMALIZE (Params->WindowTitle.Buffer, Params);
DENORMALIZE (Params->Desktop.Buffer, Params); DENORMALIZE (Params->DesktopInfo.Buffer, Params);
DENORMALIZE (Params->ShellInfo.Buffer, Params); DENORMALIZE (Params->ShellInfo.Buffer, Params);
DENORMALIZE (Params->RuntimeData.Buffer, Params); DENORMALIZE (Params->RuntimeData.Buffer, Params);
@ -289,11 +293,11 @@ RtlNormalizeProcessParams (
if (Params && !(Params->Flags & PPF_NORMALIZED)) if (Params && !(Params->Flags & PPF_NORMALIZED))
{ {
NORMALIZE (Params->CurrentDirectory.DosPath.Buffer, Params); NORMALIZE (Params->CurrentDirectory.DosPath.Buffer, Params);
NORMALIZE (Params->LibraryPath.Buffer, Params); NORMALIZE (Params->DllPath.Buffer, Params);
NORMALIZE (Params->CommandLine.Buffer, Params); NORMALIZE (Params->CommandLine.Buffer, Params);
NORMALIZE (Params->ImageName.Buffer, Params); NORMALIZE (Params->ImagePathName.Buffer, Params);
NORMALIZE (Params->Title.Buffer, Params); NORMALIZE (Params->WindowTitle.Buffer, Params);
NORMALIZE (Params->Desktop.Buffer, Params); NORMALIZE (Params->DesktopInfo.Buffer, Params);
NORMALIZE (Params->ShellInfo.Buffer, Params); NORMALIZE (Params->ShellInfo.Buffer, Params);
NORMALIZE (Params->RuntimeData.Buffer, Params); NORMALIZE (Params->RuntimeData.Buffer, Params);

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.14 2000/02/18 00:49:11 ekohl Exp $ /* $Id: process.c,v 1.15 2000/02/19 19:34:49 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -156,22 +156,17 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
ULONG PpbSize; ULONG PpbSize;
ULONG BytesWritten; ULONG BytesWritten;
ULONG Offset; ULONG Offset;
PVOID ParentEnv = NULL;
PVOID EnvPtr = NULL; PVOID EnvPtr = NULL;
ULONG EnvSize = 0; ULONG EnvSize = 0;
/* create the Environment */ /* create the Environment */
if (Ppb->Environment != NULL) if (Ppb->Environment != NULL)
ParentEnv = Ppb->Environment;
else if (NtCurrentPeb()->ProcessParameters->Environment != NULL)
ParentEnv = NtCurrentPeb()->ProcessParameters->Environment;
if (ParentEnv != NULL)
{ {
MEMORY_BASIC_INFORMATION MemInfo; MEMORY_BASIC_INFORMATION MemInfo;
Status = NtQueryVirtualMemory (NtCurrentProcess (), Status = NtQueryVirtualMemory (NtCurrentProcess (),
ParentEnv, Ppb->Environment,
MemoryBasicInformation, MemoryBasicInformation,
&MemInfo, &MemInfo,
sizeof(MEMORY_BASIC_INFORMATION), sizeof(MEMORY_BASIC_INFORMATION),
@ -200,14 +195,15 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
NtWriteVirtualMemory(ProcessHandle, NtWriteVirtualMemory(ProcessHandle,
EnvPtr, EnvPtr,
ParentEnv, Ppb->Environment,
EnvSize, EnvSize,
&BytesWritten); &BytesWritten);
} }
DPRINT("EnvironmentPointer %p\n", EnvPtr);
/* create the PPB */ /* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO; PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = Ppb->TotalSize; PpbSize = Ppb->MaximumLength;
Status = NtAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&PpbBase, &PpbBase,
0, 0,
@ -219,14 +215,16 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
return(Status); return(Status);
} }
DPRINT("Ppb->TotalSize %x\n", Ppb->TotalSize); DPRINT("Ppb->MaximumLength %x\n", Ppb->MaximumLength);
/* write process parameters block*/ /* write process parameters block*/
RtlDeNormalizeProcessParams (Ppb);
NtWriteVirtualMemory(ProcessHandle, NtWriteVirtualMemory(ProcessHandle,
PpbBase, PpbBase,
Ppb, Ppb,
Ppb->TotalSize, Ppb->MaximumLength,
&BytesWritten); &BytesWritten);
RtlNormalizeProcessParams (Ppb);
/* write pointer to environment */ /* write pointer to environment */
Offset = FIELD_OFFSET(RTL_USER_PROCESS_PARAMETERS, Environment); Offset = FIELD_OFFSET(RTL_USER_PROCESS_PARAMETERS, Environment);
@ -262,13 +260,8 @@ NTSTATUS STDCALL RtlCreateUserProcess(PUNICODE_STRING CommandLine,
HANDLE hThread; HANDLE hThread;
NTSTATUS Status; NTSTATUS Status;
LPTHREAD_START_ROUTINE lpStartAddress = NULL; LPTHREAD_START_ROUTINE lpStartAddress = NULL;
// WCHAR TempCommandLine[256];
// PVOID BaseAddress;
// LARGE_INTEGER SectionOffset;
// ULONG InitialViewSize;
PROCESS_BASIC_INFORMATION ProcessBasicInfo; PROCESS_BASIC_INFORMATION ProcessBasicInfo;
ULONG retlen; ULONG retlen;
// DWORD len = 0;
DPRINT("CreateProcessW(CommandLine '%w')\n", CommandLine->Buffer); DPRINT("CreateProcessW(CommandLine '%w')\n", CommandLine->Buffer);

View file

@ -1,4 +1,4 @@
/* $Id: init.c,v 1.11 2000/02/18 00:51:03 ekohl Exp $ /* $Id: init.c,v 1.12 2000/02/19 19:37:13 ekohl Exp $
* *
* init.c - Session Manager initialization * init.c - Session Manager initialization
* *
@ -65,6 +65,56 @@ SmCreatePagingFiles (VOID)
#endif #endif
static VOID
SmSetEnvironmentVariables (VOID)
{
UNICODE_STRING EnvVariable;
UNICODE_STRING EnvValue;
/*
* The following environment variables are read from the registry.
* Since the registry does not work yet, the environment variables
* are set one by one, using hard-coded default values.
*
* Variables:
* SystemRoot = C:\reactos
* SystemDrive = C:
*
* OS = ReactOS
* Path = %SystemRoot%\system32;%SystemRoot%
* windir = %SystemRoot%
*/
/* Set "SystemRoot = C:\reactos" */
RtlInitUnicodeString (&EnvVariable,
L"SystemRoot");
RtlInitUnicodeString (&EnvValue,
L"C:\\reactos");
RtlSetEnvironmentVariable (&SmSystemEnvironment,
&EnvVariable,
&EnvValue);
/* Set "SystemDrive = C:" */
RtlInitUnicodeString (&EnvVariable,
L"SystemDrive");
RtlInitUnicodeString (&EnvValue,
L"C:");
RtlSetEnvironmentVariable (&SmSystemEnvironment,
&EnvVariable,
&EnvValue);
/* Set "OS = ReactOS" */
RtlInitUnicodeString (&EnvVariable,
L"OS");
RtlInitUnicodeString (&EnvValue,
L"ReactOS");
RtlSetEnvironmentVariable (&SmSystemEnvironment,
&EnvVariable,
&EnvValue);
}
BOOL BOOL
InitSessionManager ( InitSessionManager (
HANDLE Children[] HANDLE Children[]
@ -77,9 +127,6 @@ InitSessionManager (
UNICODE_STRING CurrentDirectoryW; UNICODE_STRING CurrentDirectoryW;
PRTL_USER_PROCESS_PARAMETERS ProcessParameters; PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
UNICODE_STRING EnvVariable;
UNICODE_STRING EnvValue;
/* Create the "\SmApiPort" object (LPC) */ /* Create the "\SmApiPort" object (LPC) */
RtlInitUnicodeString (&UnicodeString, RtlInitUnicodeString (&UnicodeString,
L"\\SmApiPort"); L"\\SmApiPort");
@ -136,22 +183,6 @@ InitSessionManager (
DisplayString (L"SM: System Environment created\n"); DisplayString (L"SM: System Environment created\n");
#endif #endif
RtlInitUnicodeString (&EnvVariable,
L"OS");
RtlInitUnicodeString (&EnvValue,
L"Reactos 0.0.15");
RtlSetEnvironmentVariable (SmSystemEnvironment,
&EnvVariable,
&EnvValue);
// RtlSetCurrentEnvironment (SmSystemEnvironment,
// NULL);
#ifndef NDEBUG
DisplayString (L"System Environment set\n");
#endif
/* FIXME: Define symbolic links to kernel devices (MS-DOS names) */ /* FIXME: Define symbolic links to kernel devices (MS-DOS names) */
/* FIXME: Run all programs in the boot execution list */ /* FIXME: Run all programs in the boot execution list */
@ -167,10 +198,11 @@ InitSessionManager (
/* FIXME: Load missing registry hives */ /* FIXME: Load missing registry hives */
/* FIXME: Set environment variables from registry */ /* Set environment variables from registry */
SmSetEnvironmentVariables ();
/* Load the kernel mode driver win32k.sys */
#if 0 #if 0
/* Load the kernel mode driver win32k.sys */
RtlInitUnicodeString (&CmdLineW, RtlInitUnicodeString (&CmdLineW,
L"\\??\\C:\\reactos\\system32\\drivers\\win32k.sys"); L"\\??\\C:\\reactos\\system32\\drivers\\win32k.sys");
Status = NtLoadDriver (&CmdLineW); Status = NtLoadDriver (&CmdLineW);
@ -181,7 +213,7 @@ InitSessionManager (
} }
#endif #endif
#if 0 #if 0
/* Start the Win32 subsystem (csrss.exe) */ /* Start the Win32 subsystem (csrss.exe) */
DisplayString (L"SM: Executing csrss.exe\n"); DisplayString (L"SM: Executing csrss.exe\n");
RtlInitUnicodeString (&UnicodeString, RtlInitUnicodeString (&UnicodeString,