[NTVDM]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 28 Sep 2014 16:27:30 +0000 (16:27 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 28 Sep 2014 16:27:30 +0000 (16:27 +0000)
- 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

13 files changed:
reactos/subsystems/ntvdm/emulator.c
reactos/subsystems/ntvdm/emulator.h
reactos/subsystems/ntvdm/lang/cs-CZ.rc
reactos/subsystems/ntvdm/lang/de-DE.rc
reactos/subsystems/ntvdm/lang/en-US.rc
reactos/subsystems/ntvdm/lang/es-ES.rc
reactos/subsystems/ntvdm/lang/fr-FR.rc
reactos/subsystems/ntvdm/lang/it-IT.rc
reactos/subsystems/ntvdm/lang/pl-PL.rc
reactos/subsystems/ntvdm/lang/ro-RO.rc
reactos/subsystems/ntvdm/lang/ru-RU.rc
reactos/subsystems/ntvdm/ntvdm.c
reactos/subsystems/ntvdm/resource.h

index ff01f25..21a0644 100644 (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 */
index 38450ec..b405c00 100644 (file)
@@ -98,7 +98,7 @@ extern BOOLEAN VdmRunning;
 
 /* FUNCTIONS ******************************************************************/
 
-VOID DumpMemory(VOID);
+VOID DumpMemory(BOOLEAN TextFormat);
 
 VOID WINAPI EmulatorReadMemory
 (
index 20d62ec..1e6df31 100644 (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
index b6ee81a..7ea43b3 100644 (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
index a6373b8..518cb88 100644 (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
index 00f6909..becd7c3 100644 (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
index 01a1d52..39f708b 100644 (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
index 9bce376..800a8db 100644 (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
index ab931ef..d393fbb 100644 (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
index 80da090..8212934 100644 (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
index 404bc9f..813d972 100644 (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
index 42ed45b..ecdaa7d 100644 (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:
index 2534ff9..b635cf9 100644 (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