Author: hbelusca Date: Sun Nov 9 00:49:17 2014 New Revision: 65335
URL: http://svn.reactos.org/svn/reactos?rev=65335&view=rev Log: [NTVDM:DOS] - Use the correct environment strings block when starting DOS programs. - When building the DOS master env block, remove the current directory env strings (they start with '='), upcase the environment names (not their values) and remove the WINDIR environment that we inherited when we started NTVDM DOS.
Modified: trunk/reactos/subsystems/ntvdm/dos/dem.c trunk/reactos/subsystems/ntvdm/dos/dos32krnl/bios.c trunk/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c trunk/reactos/subsystems/ntvdm/dos/dos32krnl/dos.h
Modified: trunk/reactos/subsystems/ntvdm/dos/dem.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/dos/dem.c?... ============================================================================== --- trunk/reactos/subsystems/ntvdm/dos/dem.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/dos/dem.c [iso-8859-1] Sun Nov 9 00:49:17 2014 @@ -462,7 +462,7 @@ DPRINT1("Starting '%s' ('%s')...\n", ApplicationName, CommandLine); Result = DosStartProcess(ApplicationName, CommandLine, - GetEnvironmentStrings()); + SEG_OFF_TO_PTR(SYSTEM_ENV_BLOCK, 0)); if (Result != ERROR_SUCCESS) { DisplayMessage(L"Could not start '%S'. Error: %u", ApplicationName, Result);
Modified: trunk/reactos/subsystems/ntvdm/dos/dos32krnl/bios.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/dos/dos32k... ============================================================================== --- trunk/reactos/subsystems/ntvdm/dos/dos32krnl/bios.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/dos/dos32krnl/bios.c [iso-8859-1] Sun Nov 9 00:49:17 2014 @@ -14,8 +14,18 @@ #include "int32.h"
#include "dos.h" - #include "bios/bios.h" + +// This is needed because on UNICODE this symbol is redirected to +// GetEnvironmentStringsW whereas on ANSI it corresponds to the real +// "ANSI" function (and GetEnvironmentStringsA is aliased to it). +#undef GetEnvironmentStrings + +// Symmetrize the dumbness of the previous symbol: on UNICODE +// FreeEnvironmentStrings aliases to FreeEnvironmentStringsW but +// on "ANSI" FreeEnvironmentStrings aliases to FreeEnvironmentStringsA +#undef FreeEnvironmentStrings +#define FreeEnvironmentStrings FreeEnvironmentStringsA
/* PRIVATE VARIABLES **********************************************************/
@@ -81,9 +91,7 @@ { PDOS_MCB Mcb = SEGMENT_TO_MCB(FIRST_MCB_SEGMENT);
- LPWSTR SourcePtr, Environment; - LPSTR AsciiString; - DWORD AsciiSize; + LPSTR SourcePtr, Environment; LPSTR DestPtr = (LPSTR)SEG_OFF_TO_PTR(SYSTEM_ENV_BLOCK, 0);
#if 0 @@ -114,55 +122,46 @@ Mcb->OwnerPsp = 0;
/* Get the environment strings */ - SourcePtr = Environment = GetEnvironmentStringsW(); + SourcePtr = Environment = GetEnvironmentStrings(); if (Environment == NULL) return FALSE;
/* Fill the DOS system environment block */ while (*SourcePtr) { - /* Get the size of the ASCII string */ - AsciiSize = WideCharToMultiByte(CP_ACP, - 0, - SourcePtr, - -1, - NULL, - 0, - NULL, - NULL); - - /* Allocate memory for the ASCII string */ - AsciiString = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, AsciiSize); - if (AsciiString == NULL) + /* + * - Ignore environment strings starting with a '=', + * they describe current directories. + * - Ignore also the WINDIR environment variable since + * DOS apps should ignore that we started from ReactOS. + * - Upper-case the environment names, not their values. + */ + if (*SourcePtr != '=' && _strnicmp(SourcePtr, "WINDIR", 6) != 0) { - FreeEnvironmentStringsW(Environment); - return FALSE; + PCHAR Delim = NULL; + + /* Copy the environment string */ + strcpy(DestPtr, SourcePtr); + + /* Upper-case the environment name */ + Delim = strchr(DestPtr, '='); // Find the '=' delimiter + if (Delim) *Delim = '\0'; // Temporarily replace it by NULL + _strupr(DestPtr); // Upper-case + if (Delim) *Delim = '='; // Restore the delimiter + + DestPtr += strlen(SourcePtr); + + /* NULL-terminate the environment string */ + *(DestPtr++) = '\0'; }
- /* Convert to ASCII */ - WideCharToMultiByte(CP_ACP, - 0, - SourcePtr, - -1, - AsciiString, - AsciiSize, - NULL, - NULL); - - /* Copy the string into DOS memory */ - strcpy(DestPtr, AsciiString); - /* Move to the next string */ - SourcePtr += wcslen(SourcePtr) + 1; - DestPtr += strlen(AsciiString); - *(DestPtr++) = 0; - - /* Free the memory */ - HeapFree(GetProcessHeap(), 0, AsciiString); - } - *DestPtr = 0; + SourcePtr += strlen(SourcePtr) + 1; + } + /* NULL-terminate the environment block */ + *DestPtr = '\0';
/* Free the memory allocated for environment strings */ - FreeEnvironmentStringsW(Environment); + FreeEnvironmentStrings(Environment);
#if 0
Modified: trunk/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/dos/dos32k... ============================================================================== --- trunk/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] Sun Nov 9 00:49:17 2014 @@ -403,7 +403,7 @@ Mcb->OwnerPsp = NewOwner; }
-static WORD DosCopyEnvironmentBlock(LPCVOID Environment, LPCSTR ProgramName) +static WORD DosCopyEnvironmentBlock(LPCSTR Environment, LPCSTR ProgramName) { PCHAR Ptr, DestBuffer = NULL; ULONG TotalSize = 0; @@ -412,12 +412,8 @@ Ptr = (PCHAR)Environment;
/* Calculate the size of the environment block */ - while (*Ptr) - { - TotalSize += strlen(Ptr) + 1; - Ptr += strlen(Ptr) + 1; - } - TotalSize++; + while (*Ptr) Ptr += strlen(Ptr) + 1; + TotalSize = (ULONG_PTR)Ptr - (ULONG_PTR)Environment + 1; // Add final NULL-terminator
/* Add the string buffer size */ TotalSize += strlen(ProgramName) + 1; @@ -434,19 +430,16 @@ DestBuffer = (PCHAR)SEG_OFF_TO_PTR(DestSegment, 0); while (*Ptr) { - /* Copy the string */ + /* Copy the string and NULL-terminate it */ strcpy(DestBuffer, Ptr); - - /* Advance to the next string */ DestBuffer += strlen(Ptr); + *(DestBuffer++) = '\0'; + + /* Move to the next string */ Ptr += strlen(Ptr) + 1; - - /* Put a zero after the string */ - *(DestBuffer++) = 0; - } - - /* Set the final zero */ - *(DestBuffer++) = 0; + } + /* NULL-terminate the environment block */ + *(DestBuffer++) = '\0';
/* Store the special program name tag */ *(DestBuffer++) = LOBYTE(DOS_PROGRAM_NAME_TAG); @@ -907,7 +900,7 @@ DWORD DosLoadExecutable(IN DOS_EXEC_TYPE LoadType, IN LPCSTR ExecutablePath, IN LPCSTR CommandLine, - IN PVOID Environment, + IN LPCSTR Environment, OUT PDWORD StackLocation OPTIONAL, OUT PDWORD EntryPoint OPTIONAL) { @@ -1151,7 +1144,7 @@
DWORD DosStartProcess(IN LPCSTR ExecutablePath, IN LPCSTR CommandLine, - IN PVOID Environment) + IN LPCSTR Environment) { DWORD Result;
Modified: trunk/reactos/subsystems/ntvdm/dos/dos32krnl/dos.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/dos/dos32k... ============================================================================== --- trunk/reactos/subsystems/ntvdm/dos/dos32krnl/dos.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/dos/dos32krnl/dos.h [iso-8859-1] Sun Nov 9 00:49:17 2014 @@ -224,7 +224,7 @@ IN DOS_EXEC_TYPE LoadType, IN LPCSTR ExecutablePath, IN LPCSTR CommandLine, - IN PVOID Environment, + IN LPCSTR Environment, OUT PDWORD StackLocation OPTIONAL, OUT PDWORD EntryPoint OPTIONAL ); @@ -233,9 +233,11 @@ LPCSTR ProgramName, PDOS_EXEC_PARAM_BLOCK Parameters ); -DWORD DosStartProcess(IN LPCSTR ExecutablePath, - IN LPCSTR CommandLine, - IN PVOID Environment); +DWORD DosStartProcess( + IN LPCSTR ExecutablePath, + IN LPCSTR CommandLine, + IN LPCSTR Environment +); VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode); BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);