From d8808ad153a107c2fceba03bbafd8585a9419a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 21 Nov 2014 02:26:53 +0000 Subject: [PATCH] [NTVDM]: Make the environment strings list optional for some Dos app start functions. svn path=/trunk/; revision=65438 --- reactos/subsystems/ntvdm/dos/dos32krnl/dos.c | 62 +++++++++++++------- reactos/subsystems/ntvdm/dos/dos32krnl/dos.h | 4 +- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c b/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c index 743b4b6112f..4e2fc189537 100644 --- a/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c +++ b/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c @@ -403,40 +403,60 @@ static VOID DosChangeMemoryOwner(WORD Segment, WORD NewOwner) Mcb->OwnerPsp = NewOwner; } -static WORD DosCopyEnvironmentBlock(LPCSTR Environment, LPCSTR ProgramName) +static WORD DosCopyEnvironmentBlock(LPCSTR Environment OPTIONAL, + LPCSTR ProgramName) { PCHAR Ptr, DestBuffer = NULL; ULONG TotalSize = 0; WORD DestSegment; - Ptr = (PCHAR)Environment; + /* If we have an environment strings list, compute its size */ + if (Environment) + { + /* Calculate the size of the environment block */ + Ptr = (PCHAR)Environment; + while (*Ptr) Ptr += strlen(Ptr) + 1; + TotalSize = (ULONG_PTR)Ptr - (ULONG_PTR)Environment; + } + else + { + /* Empty environment string */ + TotalSize = 1; + } + /* Add the final environment block NULL-terminator */ + TotalSize++; - /* Calculate the size of the environment block */ - while (*Ptr) Ptr += strlen(Ptr) + 1; - TotalSize = (ULONG_PTR)Ptr - (ULONG_PTR)Environment + 1; // Add final NULL-terminator + /* Add the two bytes for the program name tag */ + TotalSize += 2; /* Add the string buffer size */ TotalSize += strlen(ProgramName) + 1; - /* Add the two extra bytes */ - TotalSize += 2; - /* Allocate the memory for the environment block */ DestSegment = DosAllocateMemory((WORD)((TotalSize + 0x0F) >> 4), NULL); if (!DestSegment) return 0; - Ptr = (PCHAR)Environment; - DestBuffer = (PCHAR)SEG_OFF_TO_PTR(DestSegment, 0); - while (*Ptr) - { - /* Copy the string and NULL-terminate it */ - strcpy(DestBuffer, Ptr); - DestBuffer += strlen(Ptr); - *(DestBuffer++) = '\0'; - /* Move to the next string */ - Ptr += strlen(Ptr) + 1; + /* If we have an environment strings list, copy it */ + if (Environment) + { + Ptr = (PCHAR)Environment; + while (*Ptr) + { + /* Copy the string and NULL-terminate it */ + strcpy(DestBuffer, Ptr); + DestBuffer += strlen(Ptr); + *(DestBuffer++) = '\0'; + + /* Move to the next string */ + Ptr += strlen(Ptr) + 1; + } + } + else + { + /* Empty environment string */ + *(DestBuffer++) = '\0'; } /* NULL-terminate the environment block */ *(DestBuffer++) = '\0'; @@ -900,7 +920,7 @@ VOID DosInitializePsp(WORD PspSegment, LPCSTR CommandLine, WORD ProgramSize, WOR DWORD DosLoadExecutable(IN DOS_EXEC_TYPE LoadType, IN LPCSTR ExecutablePath, IN LPCSTR CommandLine, - IN LPCSTR Environment, + IN LPCSTR Environment OPTIONAL, OUT PDWORD StackLocation OPTIONAL, OUT PDWORD EntryPoint OPTIONAL) { @@ -920,7 +940,7 @@ DWORD DosLoadExecutable(IN DOS_EXEC_TYPE LoadType, LoadType, ExecutablePath, CommandLine, - Environment, + Environment ? Environment : "n/a", StackLocation, EntryPoint); @@ -1144,7 +1164,7 @@ Cleanup: DWORD DosStartProcess(IN LPCSTR ExecutablePath, IN LPCSTR CommandLine, - IN LPCSTR Environment) + IN LPCSTR Environment OPTIONAL) { DWORD Result; diff --git a/reactos/subsystems/ntvdm/dos/dos32krnl/dos.h b/reactos/subsystems/ntvdm/dos/dos32krnl/dos.h index 3da70b63242..a7da71b2099 100644 --- a/reactos/subsystems/ntvdm/dos/dos32krnl/dos.h +++ b/reactos/subsystems/ntvdm/dos/dos32krnl/dos.h @@ -224,7 +224,7 @@ DWORD DosLoadExecutable( IN DOS_EXEC_TYPE LoadType, IN LPCSTR ExecutablePath, IN LPCSTR CommandLine, - IN LPCSTR Environment, + IN LPCSTR Environment OPTIONAL, OUT PDWORD StackLocation OPTIONAL, OUT PDWORD EntryPoint OPTIONAL ); @@ -236,7 +236,7 @@ WORD DosCreateProcess( DWORD DosStartProcess( IN LPCSTR ExecutablePath, IN LPCSTR CommandLine, - IN LPCSTR Environment + IN LPCSTR Environment OPTIONAL ); VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode); BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);