- 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:
Hermès Bélusca-Maïto 2014-09-28 16:27:30 +00:00
parent beeb1048e8
commit b0555a5004
13 changed files with 98 additions and 53 deletions

View file

@ -430,13 +430,22 @@ static VOID EnableExtraHardware(HANDLE ConsoleInput)
/* PUBLIC FUNCTIONS ***********************************************************/
VOID DumpMemory(VOID)
static VOID
DumpMemoryRaw(HANDLE hFile)
{
static ULONG DumpNumber = 0;
PVOID Buffer;
SIZE_T Size;
HANDLE hFile;
WCHAR FileName[MAX_PATH];
/* Dump the VM memory */
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
ULONG i;
PBYTE Ptr1, Ptr2;
@ -444,28 +453,6 @@ VOID DumpMemory(VOID)
PCHAR Line;
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 */
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
Ptr1 = Ptr2 = REAL_TO_PHYS(NULL);
@ -507,6 +494,45 @@ VOID DumpMemory(VOID)
LineSize = Line - LineBuffer;
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 */
CloseHandle(hFile);
@ -517,12 +543,14 @@ VOID DumpMemory(VOID)
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
{
/* 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)
{
wprintf(L"FATAL: Failed to allocate VDM memory.\n");
return FALSE;
}
// For diagnostics purposes!!
FillMemory(BaseAddress, MAX_ADDRESS, 0xFF);
/* Initialize I/O ports */
/* Initialize RAM */

View file

@ -98,7 +98,7 @@ extern BOOLEAN VdmRunning;
/* FUNCTIONS ******************************************************************/
VOID DumpMemory(VOID);
VOID DumpMemory(BOOLEAN TextFormat);
VOID WINAPI EmulatorReadMemory
(

View file

@ -15,6 +15,7 @@ END
STRINGTABLE
BEGIN
IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "&Ukončit ReactOS VDM"
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
IDS_VDM_QUIT , "&Ukončit ReactOS VDM"
END

View file

@ -9,6 +9,7 @@ END
STRINGTABLE
BEGIN
IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "ReactOS VDM b&eenden"
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
IDS_VDM_QUIT , "ReactOS VDM b&eenden"
END

View file

@ -9,6 +9,7 @@ END
STRINGTABLE
BEGIN
IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "&Quit the ReactOS VDM"
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
IDS_VDM_QUIT , "&Quit the ReactOS VDM"
END

View file

@ -9,6 +9,7 @@ END
STRINGTABLE
BEGIN
IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "&Salir de ReactOS VDM"
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
IDS_VDM_QUIT , "&Salir de ReactOS VDM"
END

View file

@ -9,6 +9,7 @@ END
STRINGTABLE
BEGIN
IDS_VDM_DUMPMEM, "Vidage &Mémoire"
IDS_VDM_QUIT , "&Quitter la ReactOS VDM"
IDS_VDM_DUMPMEM_TXT, "Vidage Mémoire (&Texte)"
IDS_VDM_DUMPMEM_BIN, "Vidage Mémoire (&Binaire)"
IDS_VDM_QUIT , "&Quitter la ReactOS VDM"
END

View file

@ -9,6 +9,7 @@ END
STRINGTABLE
BEGIN
IDS_VDM_DUMPMEM, "Dump &Memory"
IDS_VDM_QUIT , "&Esci da ReactOS VDM"
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
IDS_VDM_QUIT , "&Esci da ReactOS VDM"
END

View file

@ -11,6 +11,7 @@ END
STRINGTABLE
BEGIN
IDS_VDM_DUMPMEM, "Zrzut &Pamięci"
IDS_VDM_QUIT , "&Wyjdź z ReactOS VDM"
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
IDS_VDM_QUIT , "&Wyjdź z ReactOS VDM"
END

View file

@ -9,5 +9,7 @@ END
STRINGTABLE
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

View file

@ -9,6 +9,7 @@ END
STRINGTABLE
BEGIN
IDS_VDM_DUMPMEM, "Дамп &памяти"
IDS_VDM_QUIT , "&Выйти из ReactOS VDM"
IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)"
IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)"
IDS_VDM_QUIT , "&Выйти из ReactOS VDM"
END

View file

@ -51,8 +51,9 @@ typedef struct _VDM_MENUITEM
static const VDM_MENUITEM VdmMenuItems[] =
{
{ IDS_VDM_DUMPMEM, NULL, ID_VDM_DUMPMEM },
{ IDS_VDM_QUIT , NULL, ID_VDM_QUIT },
{ IDS_VDM_DUMPMEM_TXT, NULL, ID_VDM_DUMPMEM_TXT },
{ IDS_VDM_DUMPMEM_BIN, NULL, ID_VDM_DUMPMEM_BIN },
{ IDS_VDM_QUIT , NULL, ID_VDM_QUIT },
{ 0, NULL, 0 } /* End of list */
};
@ -337,8 +338,12 @@ VOID MenuEventHandler(PMENU_EVENT_RECORD MenuEvent)
ShowPointer = !ShowPointer;
break;
case ID_VDM_DUMPMEM:
DumpMemory();
case ID_VDM_DUMPMEM_TXT:
DumpMemory(TRUE);
break;
case ID_VDM_DUMPMEM_BIN:
DumpMemory(FALSE);
break;
case ID_VDM_QUIT:

View file

@ -2,16 +2,18 @@
/* Menu IDs */
#define ID_SHOWHIDE_MOUSE 1000
#define ID_VDM_DUMPMEM 1001
#define ID_VDM_QUIT 1002
#define ID_VDM_DUMPMEM_TXT 1001
#define ID_VDM_DUMPMEM_BIN 1002
#define ID_VDM_QUIT 1003
/* String IDs */
#define IDS_HIDE_MOUSE 100
#define IDS_SHOW_MOUSE 101
#define IDS_VDM_MENU 102
#define IDS_VDM_DUMPMEM 200
#define IDS_VDM_QUIT 201
#define IDS_VDM_DUMPMEM_TXT 200
#define IDS_VDM_DUMPMEM_BIN 201
#define IDS_VDM_QUIT 202
/* Icon */
#define IDI_APPICON 1