mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 10:35:28 +00:00
[NTVDM]
- Add the possibility to dump the VM memory either in text or binary mode. - Initialize the VM memory to 0xFF to track potential memory misuses (diagnostics purposes). Things may crash, or not! svn path=/trunk/; revision=64367
This commit is contained in:
parent
beeb1048e8
commit
b0555a5004
13 changed files with 98 additions and 53 deletions
|
@ -430,13 +430,22 @@ static VOID EnableExtraHardware(HANDLE ConsoleInput)
|
||||||
|
|
||||||
/* PUBLIC FUNCTIONS ***********************************************************/
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
||||||
|
|
||||||
VOID DumpMemory(VOID)
|
static VOID
|
||||||
|
DumpMemoryRaw(HANDLE hFile)
|
||||||
{
|
{
|
||||||
static ULONG DumpNumber = 0;
|
PVOID Buffer;
|
||||||
|
SIZE_T Size;
|
||||||
|
|
||||||
HANDLE hFile;
|
/* Dump the VM memory */
|
||||||
WCHAR FileName[MAX_PATH];
|
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
|
||||||
|
Buffer = REAL_TO_PHYS(NULL);
|
||||||
|
Size = MAX_ADDRESS - (ULONG_PTR)(NULL);
|
||||||
|
WriteFile(hFile, Buffer, Size, &Size, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
DumpMemoryTxt(HANDLE hFile)
|
||||||
|
{
|
||||||
#define LINE_SIZE 75 + 2
|
#define LINE_SIZE 75 + 2
|
||||||
ULONG i;
|
ULONG i;
|
||||||
PBYTE Ptr1, Ptr2;
|
PBYTE Ptr1, Ptr2;
|
||||||
|
@ -444,28 +453,6 @@ VOID DumpMemory(VOID)
|
||||||
PCHAR Line;
|
PCHAR Line;
|
||||||
SIZE_T LineSize;
|
SIZE_T LineSize;
|
||||||
|
|
||||||
/* Build a suitable file name */
|
|
||||||
_snwprintf(FileName, MAX_PATH, L"memdump%lu.txt", DumpNumber);
|
|
||||||
++DumpNumber;
|
|
||||||
|
|
||||||
DPRINT1("Creating memory dump file '%S'...\n", FileName);
|
|
||||||
|
|
||||||
/* Always create the dump file */
|
|
||||||
hFile = CreateFileW(FileName,
|
|
||||||
GENERIC_WRITE,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
CREATE_ALWAYS,
|
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (hFile == INVALID_HANDLE_VALUE)
|
|
||||||
{
|
|
||||||
DPRINT1("Error when creating '%S' for memory dumping, GetLastError() = %u\n",
|
|
||||||
FileName, GetLastError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dump the VM memory */
|
/* Dump the VM memory */
|
||||||
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
|
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
|
||||||
Ptr1 = Ptr2 = REAL_TO_PHYS(NULL);
|
Ptr1 = Ptr2 = REAL_TO_PHYS(NULL);
|
||||||
|
@ -507,6 +494,45 @@ VOID DumpMemory(VOID)
|
||||||
LineSize = Line - LineBuffer;
|
LineSize = Line - LineBuffer;
|
||||||
WriteFile(hFile, LineBuffer, LineSize, &LineSize, NULL);
|
WriteFile(hFile, LineBuffer, LineSize, &LineSize, NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID DumpMemory(BOOLEAN TextFormat)
|
||||||
|
{
|
||||||
|
static ULONG DumpNumber = 0;
|
||||||
|
|
||||||
|
HANDLE hFile;
|
||||||
|
WCHAR FileName[MAX_PATH];
|
||||||
|
|
||||||
|
/* Build a suitable file name */
|
||||||
|
_snwprintf(FileName, MAX_PATH,
|
||||||
|
L"memdump%lu.%s",
|
||||||
|
DumpNumber,
|
||||||
|
TextFormat ? L"txt" : L"dat");
|
||||||
|
++DumpNumber;
|
||||||
|
|
||||||
|
DPRINT1("Creating memory dump file '%S'...\n", FileName);
|
||||||
|
|
||||||
|
/* Always create the dump file */
|
||||||
|
hFile = CreateFileW(FileName,
|
||||||
|
GENERIC_WRITE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
CREATE_ALWAYS,
|
||||||
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
DPRINT1("Error when creating '%S' for memory dumping, GetLastError() = %u\n",
|
||||||
|
FileName, GetLastError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dump the VM memory in the chosen format */
|
||||||
|
if (TextFormat)
|
||||||
|
DumpMemoryTxt(hFile);
|
||||||
|
else
|
||||||
|
DumpMemoryRaw(hFile);
|
||||||
|
|
||||||
/* Close the file */
|
/* Close the file */
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
|
@ -517,12 +543,14 @@ VOID DumpMemory(VOID)
|
||||||
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
|
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
|
||||||
{
|
{
|
||||||
/* Allocate memory for the 16-bit address space */
|
/* Allocate memory for the 16-bit address space */
|
||||||
BaseAddress = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_ADDRESS);
|
BaseAddress = HeapAlloc(GetProcessHeap(), /*HEAP_ZERO_MEMORY*/ 0, MAX_ADDRESS);
|
||||||
if (BaseAddress == NULL)
|
if (BaseAddress == NULL)
|
||||||
{
|
{
|
||||||
wprintf(L"FATAL: Failed to allocate VDM memory.\n");
|
wprintf(L"FATAL: Failed to allocate VDM memory.\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
// For diagnostics purposes!!
|
||||||
|
FillMemory(BaseAddress, MAX_ADDRESS, 0xFF);
|
||||||
|
|
||||||
/* Initialize I/O ports */
|
/* Initialize I/O ports */
|
||||||
/* Initialize RAM */
|
/* Initialize RAM */
|
||||||
|
|
|
@ -98,7 +98,7 @@ extern BOOLEAN VdmRunning;
|
||||||
|
|
||||||
/* FUNCTIONS ******************************************************************/
|
/* FUNCTIONS ******************************************************************/
|
||||||
|
|
||||||
VOID DumpMemory(VOID);
|
VOID DumpMemory(BOOLEAN TextFormat);
|
||||||
|
|
||||||
VOID WINAPI EmulatorReadMemory
|
VOID WINAPI EmulatorReadMemory
|
||||||
(
|
(
|
||||||
|
|
|
@ -15,6 +15,7 @@ END
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_VDM_DUMPMEM, "Dump &Memory"
|
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
|
||||||
IDS_VDM_QUIT , "&Ukončit ReactOS VDM"
|
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
|
||||||
|
IDS_VDM_QUIT , "&Ukončit ReactOS VDM"
|
||||||
END
|
END
|
||||||
|
|
|
@ -9,6 +9,7 @@ END
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_VDM_DUMPMEM, "Dump &Memory"
|
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
|
||||||
IDS_VDM_QUIT , "ReactOS VDM b&eenden"
|
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
|
||||||
|
IDS_VDM_QUIT , "ReactOS VDM b&eenden"
|
||||||
END
|
END
|
||||||
|
|
|
@ -9,6 +9,7 @@ END
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_VDM_DUMPMEM, "Dump &Memory"
|
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
|
||||||
IDS_VDM_QUIT , "&Quit the ReactOS VDM"
|
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
|
||||||
|
IDS_VDM_QUIT , "&Quit the ReactOS VDM"
|
||||||
END
|
END
|
||||||
|
|
|
@ -9,6 +9,7 @@ END
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_VDM_DUMPMEM, "Dump &Memory"
|
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
|
||||||
IDS_VDM_QUIT , "&Salir de ReactOS VDM"
|
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
|
||||||
|
IDS_VDM_QUIT , "&Salir de ReactOS VDM"
|
||||||
END
|
END
|
||||||
|
|
|
@ -9,6 +9,7 @@ END
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_VDM_DUMPMEM, "Vidage &Mémoire"
|
IDS_VDM_DUMPMEM_TXT, "Vidage Mémoire (&Texte)"
|
||||||
IDS_VDM_QUIT , "&Quitter la ReactOS VDM"
|
IDS_VDM_DUMPMEM_BIN, "Vidage Mémoire (&Binaire)"
|
||||||
|
IDS_VDM_QUIT , "&Quitter la ReactOS VDM"
|
||||||
END
|
END
|
||||||
|
|
|
@ -9,6 +9,7 @@ END
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_VDM_DUMPMEM, "Dump &Memory"
|
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
|
||||||
IDS_VDM_QUIT , "&Esci da ReactOS VDM"
|
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
|
||||||
|
IDS_VDM_QUIT , "&Esci da ReactOS VDM"
|
||||||
END
|
END
|
||||||
|
|
|
@ -11,6 +11,7 @@ END
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_VDM_DUMPMEM, "Zrzut &Pamięci"
|
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
|
||||||
IDS_VDM_QUIT , "&Wyjdź z ReactOS VDM"
|
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
|
||||||
|
IDS_VDM_QUIT , "&Wyjdź z ReactOS VDM"
|
||||||
END
|
END
|
||||||
|
|
|
@ -9,5 +9,7 @@ END
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_VDM_QUIT, "I&eșire din ReactOS VDM"
|
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
|
||||||
|
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
|
||||||
|
IDS_VDM_QUIT , "I&eșire din ReactOS VDM"
|
||||||
END
|
END
|
||||||
|
|
|
@ -9,6 +9,7 @@ END
|
||||||
|
|
||||||
STRINGTABLE
|
STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
IDS_VDM_DUMPMEM, "Дамп &памяти"
|
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
|
||||||
IDS_VDM_QUIT , "&Выйти из ReactOS VDM"
|
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
|
||||||
|
IDS_VDM_QUIT , "&Выйти из ReactOS VDM"
|
||||||
END
|
END
|
||||||
|
|
|
@ -51,8 +51,9 @@ typedef struct _VDM_MENUITEM
|
||||||
|
|
||||||
static const VDM_MENUITEM VdmMenuItems[] =
|
static const VDM_MENUITEM VdmMenuItems[] =
|
||||||
{
|
{
|
||||||
{ IDS_VDM_DUMPMEM, NULL, ID_VDM_DUMPMEM },
|
{ IDS_VDM_DUMPMEM_TXT, NULL, ID_VDM_DUMPMEM_TXT },
|
||||||
{ IDS_VDM_QUIT , NULL, ID_VDM_QUIT },
|
{ IDS_VDM_DUMPMEM_BIN, NULL, ID_VDM_DUMPMEM_BIN },
|
||||||
|
{ IDS_VDM_QUIT , NULL, ID_VDM_QUIT },
|
||||||
|
|
||||||
{ 0, NULL, 0 } /* End of list */
|
{ 0, NULL, 0 } /* End of list */
|
||||||
};
|
};
|
||||||
|
@ -337,8 +338,12 @@ VOID MenuEventHandler(PMENU_EVENT_RECORD MenuEvent)
|
||||||
ShowPointer = !ShowPointer;
|
ShowPointer = !ShowPointer;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_VDM_DUMPMEM:
|
case ID_VDM_DUMPMEM_TXT:
|
||||||
DumpMemory();
|
DumpMemory(TRUE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ID_VDM_DUMPMEM_BIN:
|
||||||
|
DumpMemory(FALSE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_VDM_QUIT:
|
case ID_VDM_QUIT:
|
||||||
|
|
|
@ -2,16 +2,18 @@
|
||||||
|
|
||||||
/* Menu IDs */
|
/* Menu IDs */
|
||||||
#define ID_SHOWHIDE_MOUSE 1000
|
#define ID_SHOWHIDE_MOUSE 1000
|
||||||
#define ID_VDM_DUMPMEM 1001
|
#define ID_VDM_DUMPMEM_TXT 1001
|
||||||
#define ID_VDM_QUIT 1002
|
#define ID_VDM_DUMPMEM_BIN 1002
|
||||||
|
#define ID_VDM_QUIT 1003
|
||||||
|
|
||||||
/* String IDs */
|
/* String IDs */
|
||||||
#define IDS_HIDE_MOUSE 100
|
#define IDS_HIDE_MOUSE 100
|
||||||
#define IDS_SHOW_MOUSE 101
|
#define IDS_SHOW_MOUSE 101
|
||||||
#define IDS_VDM_MENU 102
|
#define IDS_VDM_MENU 102
|
||||||
|
|
||||||
#define IDS_VDM_DUMPMEM 200
|
#define IDS_VDM_DUMPMEM_TXT 200
|
||||||
#define IDS_VDM_QUIT 201
|
#define IDS_VDM_DUMPMEM_BIN 201
|
||||||
|
#define IDS_VDM_QUIT 202
|
||||||
|
|
||||||
/* Icon */
|
/* Icon */
|
||||||
#define IDI_APPICON 1
|
#define IDI_APPICON 1
|
||||||
|
|
Loading…
Reference in a new issue