- Remove unneeded commented code;
- Fix few things related to committing the reserved low-memory VDM page by kernel32;
- Decommit this memory when we terminate NTVDM.

svn path=/trunk/; revision=65426
This commit is contained in:
Hermès Bélusca-Maïto 2014-11-17 02:08:12 +00:00
parent bc27bfaa6b
commit 0bbe7eda19
2 changed files with 45 additions and 15 deletions

View file

@ -560,7 +560,7 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
{
#ifdef STANDALONE
/* Allocate memory for the 16-bit address space */
/* Allocate 16 MB memory for the 16-bit address space */
BaseAddress = HeapAlloc(GetProcessHeap(), /*HEAP_ZERO_MEMORY*/ 0, MAX_ADDRESS);
if (BaseAddress == NULL)
{
@ -571,10 +571,19 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
#else
NTSTATUS Status;
SIZE_T MemorySize = MAX_ADDRESS;
SIZE_T MemorySize = MAX_ADDRESS; // See: kernel32/client/vdm.c!BaseGetVdmConfigInfo
/* The reserved region starts from the very first page */
BaseAddress = NULL;
/*
* The reserved region starts from the very first page.
* We need to commit the reserved first 16 MB virtual address.
*/
BaseAddress = (PVOID)1; // NULL has another signification for NtAllocateVirtualMemory
/*
* Since to get NULL, we allocated from 0x1, account for this.
* See also: kernel32/client/proc.c!CreateProcessInternalW
*/
MemorySize -= 1;
/* Commit the reserved memory */
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
@ -585,10 +594,12 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
PAGE_EXECUTE_READWRITE);
if (!NT_SUCCESS(Status))
{
wprintf(L"FATAL: Failed to commit VDM memory.\n");
wprintf(L"FATAL: Failed to commit VDM memory, Status 0x%08lx\n", Status);
return FALSE;
}
ASSERT(BaseAddress == NULL);
#endif
/*
@ -607,20 +618,12 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
if (!ClockInitialize())
{
wprintf(L"FATAL: Failed to initialize the clock\n");
EmulatorCleanup();
return FALSE;
}
/* Initialize the CPU */
CpuInitialize();
// Fast486Initialize(&EmulatorContext,
// EmulatorReadMemory,
// EmulatorWriteMemory,
// EmulatorReadIo,
// EmulatorWriteIo,
// NULL,
// EmulatorBiosOperation,
// EmulatorIntAcknowledge,
// NULL /* TODO: Use a TLB */);
/* Initialize DMA */
@ -659,6 +662,7 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
if (InputThread == NULL)
{
DisplayMessage(L"Failed to create the console input thread.");
EmulatorCleanup();
return FALSE;
}
/************************************************************/
@ -667,6 +671,7 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
if (!VgaInitialize(ConsoleOutput))
{
DisplayMessage(L"Failed to initialize VGA support.");
EmulatorCleanup();
return FALSE;
}
@ -683,6 +688,11 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
VOID EmulatorCleanup(VOID)
{
#ifndef STANDALONE
NTSTATUS Status;
SIZE_T MemorySize = MAX_ADDRESS;
#endif
VgaCleanup();
/* Close the input thread handle */
@ -698,8 +708,28 @@ VOID EmulatorCleanup(VOID)
CpuCleanup();
#ifdef STANDALONE
/* Free the memory allocated for the 16-bit address space */
if (BaseAddress != NULL) HeapFree(GetProcessHeap(), 0, BaseAddress);
#else
/* The reserved region starts from the very first page */
// BaseAddress = (PVOID)1;
/* Since to get NULL, we allocated from 0x1, account for this */
MemorySize -= 1;
Status = NtFreeVirtualMemory(NtCurrentProcess(),
&BaseAddress,
&MemorySize,
MEM_DECOMMIT);
if (!NT_SUCCESS(Status))
{
DPRINT1("NTVDM: Failed to decommit VDM memory, Status 0x%08lx\n", Status);
}
#endif
}

View file

@ -23,7 +23,7 @@
#define TO_LINEAR(seg, off) (((seg) << 4) + (off))
#define MAX_SEGMENT 0xFFFF
#define MAX_OFFSET 0xFFFF
#define MAX_ADDRESS 0x1000000 // 16 MB of RAM
#define MAX_ADDRESS 0x1000000 // 16 MB of RAM; see also: kernel32/client/vdm.c!BaseGetVdmConfigInfo
#define FAR_POINTER(x) \
(PVOID)((ULONG_PTR)BaseAddress + TO_LINEAR(HIWORD(x), LOWORD(x)))