From bc0b6aa8fc1f9ea1a527a465dc0fa446a4d59623 Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Sat, 15 Nov 2014 01:35:28 +0000 Subject: [PATCH] [NTVDM] In non-standalone mode, commit the memory reserved in CreateProcessInternalW instead of allocating from the heap. svn path=/trunk/; revision=65403 --- reactos/subsystems/ntvdm/emulator.c | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/reactos/subsystems/ntvdm/emulator.c b/reactos/subsystems/ntvdm/emulator.c index 696a5406046..a67b77558c8 100644 --- a/reactos/subsystems/ntvdm/emulator.c +++ b/reactos/subsystems/ntvdm/emulator.c @@ -33,6 +33,10 @@ #include "vddsup.h" #include "io.h" +/* Extra PSDK/NDK Headers */ +#include +#include + /* PRIVATE VARIABLES **********************************************************/ LPVOID BaseAddress = NULL; @@ -554,6 +558,8 @@ VOID DumpMemory(BOOLEAN TextFormat) BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput) { +#ifdef STANDALONE + /* Allocate memory for the 16-bit address space */ BaseAddress = HeapAlloc(GetProcessHeap(), /*HEAP_ZERO_MEMORY*/ 0, MAX_ADDRESS); if (BaseAddress == NULL) @@ -561,6 +567,30 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput) wprintf(L"FATAL: Failed to allocate VDM memory.\n"); return FALSE; } + +#else + + NTSTATUS Status; + SIZE_T MemorySize = MAX_ADDRESS; + + /* The reserved region starts from the very first page */ + BaseAddress = NULL; + + /* Commit the reserved memory */ + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &MemorySize, + MEM_COMMIT, + PAGE_EXECUTE_READWRITE); + if (!NT_SUCCESS(Status)) + { + wprintf(L"FATAL: Failed to commit VDM memory.\n"); + return FALSE; + } + +#endif + /* * For diagnostics purposes, we fill the memory with INT 0x03 codes * so that if a program wants to execute random code in memory, we can