Author: hbelusca
Date: Fri Mar 13 22:38:44 2015
New Revision: 66669
URL:
http://svn.reactos.org/svn/reactos?rev=66669&view=rev
Log:
[NTVDM]
- Move the VDD memory handler API prototypes to the corresponding DDK header.
- Fix few function arguments types and add few more comments :)
- Move all NTVDM-memory related functions to memory.c
- Prefer checking for !IsListEmpty(&list) instead of doing list.Flink != &list
(ehh! NTVDM is not win32k!!)
Modified:
trunk/reactos/include/ddk/nt_vdd.h
trunk/reactos/subsystems/mvdm/ntvdm/cpu/cpu.c
trunk/reactos/subsystems/mvdm/ntvdm/emulator.c
trunk/reactos/subsystems/mvdm/ntvdm/memory.c
trunk/reactos/subsystems/mvdm/ntvdm/memory.h
Modified: trunk/reactos/include/ddk/nt_vdd.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/nt_vdd.h?rev=6…
==============================================================================
--- trunk/reactos/include/ddk/nt_vdd.h [iso-8859-1] (original)
+++ trunk/reactos/include/ddk/nt_vdd.h [iso-8859-1] Fri Mar 13 22:38:44 2015
@@ -179,6 +179,13 @@
#define getMODE() ((getMSW() & MSW_PE) ? VDM_PM : VDM_V86)
+typedef VOID
+(WINAPI *PVDD_MEMORY_HANDLER)
+(
+ PVOID FaultAddress,
+ ULONG RWMode
+);
+
PBYTE
WINAPI
Sim32pGetVDMPointer
@@ -225,6 +232,25 @@
IN VDM_MODE Mode
);
+BOOL
+WINAPI
+VDDInstallMemoryHook
+(
+ IN HANDLE hVdd,
+ IN PVOID pStart,
+ IN DWORD dwCount,
+ IN PVDD_MEMORY_HANDLER MemoryHandler
+);
+
+BOOL
+WINAPI
+VDDDeInstallMemoryHook
+(
+ IN HANDLE hVdd,
+ IN PVOID pStart,
+ IN DWORD dwCount
+);
+
#ifdef __cplusplus
}
#endif
Modified: trunk/reactos/subsystems/mvdm/ntvdm/cpu/cpu.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/cpu/…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/cpu/cpu.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/cpu/cpu.c [iso-8859-1] Fri Mar 13 22:38:44 2015
@@ -139,7 +139,7 @@
EXCEPTION_EXECUTE_HANDLER)
{
BOOLEAN Writing = (LocalExceptionRecord.ExceptionInformation[0] == 1);
- DWORD FaultingAddress = (DWORD)LocalExceptionRecord.ExceptionInformation[1];
+ ULONG FaultAddress = (ULONG)LocalExceptionRecord.ExceptionInformation[1];
/* Make sure this was an access violation */
ASSERT(LocalExceptionRecord.ExceptionCode == EXCEPTION_ACCESS_VIOLATION);
@@ -148,7 +148,7 @@
Fast486Rewind(&EmulatorContext);
/* Call the handler */
- MemExceptionHandler(FaultingAddress, Writing);
+ MemExceptionHandler(FaultAddress, Writing);
}
_SEH2_END;
}
Modified: trunk/reactos/subsystems/mvdm/ntvdm/emulator.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/emul…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/emulator.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/emulator.c [iso-8859-1] Fri Mar 13 22:38:44 2015
@@ -586,66 +586,4 @@
EmulatorTerminate();
}
-PBYTE
-WINAPI
-Sim32pGetVDMPointer(IN ULONG Address,
- IN BOOLEAN ProtectedMode)
-{
- // FIXME
- UNREFERENCED_PARAMETER(ProtectedMode);
-
- /*
- * HIWORD(Address) == Segment (if ProtectedMode == FALSE)
- * or Selector (if ProtectedMode == TRUE )
- * LOWORD(Address) == Offset
- */
- return (PBYTE)FAR_POINTER(Address);
-}
-
-PBYTE
-WINAPI
-MGetVdmPointer(IN ULONG Address,
- IN ULONG Size,
- IN BOOLEAN ProtectedMode)
-{
- UNREFERENCED_PARAMETER(Size);
- return Sim32pGetVDMPointer(Address, ProtectedMode);
-}
-
-PVOID
-WINAPI
-VdmMapFlat(IN USHORT Segment,
- IN ULONG Offset,
- IN VDM_MODE Mode)
-{
- // FIXME
- UNREFERENCED_PARAMETER(Mode);
-
- return SEG_OFF_TO_PTR(Segment, Offset);
-}
-
-BOOL
-WINAPI
-VdmFlushCache(IN USHORT Segment,
- IN ULONG Offset,
- IN ULONG Size,
- IN VDM_MODE Mode)
-{
- // FIXME
- UNIMPLEMENTED;
- return TRUE;
-}
-
-BOOL
-WINAPI
-VdmUnmapFlat(IN USHORT Segment,
- IN ULONG Offset,
- IN PVOID Buffer,
- IN VDM_MODE Mode)
-{
- // FIXME
- UNIMPLEMENTED;
- return TRUE;
-}
-
/* EOF */
Modified: trunk/reactos/subsystems/mvdm/ntvdm/memory.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/memo…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/memory.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/memory.c [iso-8859-1] Fri Mar 13 22:38:44 2015
@@ -17,6 +17,24 @@
/* PRIVATE VARIABLES **********************************************************/
+typedef struct _MEM_HOOK
+{
+ LIST_ENTRY Entry;
+ HANDLE hVdd;
+ ULONG Count;
+
+ union
+ {
+ PVDD_MEMORY_HANDLER VddHandler;
+
+ struct
+ {
+ PMEMORY_READ_HANDLER FastReadHandler;
+ PMEMORY_WRITE_HANDLER FastWriteHandler;
+ };
+ };
+} MEM_HOOK, *PMEM_HOOK;
+
static LIST_ENTRY HookList;
static PMEM_HOOK PageTable[TOTAL_PAGES];
@@ -171,16 +189,16 @@
}
VOID
-MemExceptionHandler(DWORD Address, BOOLEAN Writing)
-{
- PMEM_HOOK Hook = PageTable[Address >> 12];
- DPRINT("The memory at 0x%08X could not be %s.\n", Address, Writing ?
"written" : "read");
+MemExceptionHandler(ULONG FaultAddress, BOOLEAN Writing)
+{
+ PMEM_HOOK Hook = PageTable[FaultAddress >> 12];
+ DPRINT("The memory at 0x%08X could not be %s.\n", FaultAddress, Writing ?
"written" : "read");
/* Exceptions are only supposed to happen when using VDD-style memory hooks */
- ASSERT(Address < MAX_ADDRESS && Hook != NULL && Hook->hVdd !=
NULL);
+ ASSERT(FaultAddress < MAX_ADDRESS && Hook != NULL && Hook->hVdd
!= NULL);
/* Call the VDD handler */
- Hook->VddHandler(Address, Writing);
+ Hook->VddHandler((PVOID)FaultAddress, (ULONG)Writing);
}
BOOL
@@ -191,8 +209,8 @@
{
PMEM_HOOK Hook;
ULONG i;
- ULONG FirstPage = (ULONG)Address >> 12;
- ULONG LastPage = ((ULONG)Address + Size - 1) >> 12;
+ ULONG FirstPage = (ULONG_PTR)Address >> 12;
+ ULONG LastPage = ((ULONG_PTR)Address + Size - 1) >> 12;
/* Make sure none of these pages are already allocated */
for (i = FirstPage; i <= LastPage; i++)
@@ -200,7 +218,8 @@
if (PageTable[i] != NULL) return FALSE;
}
- Hook = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(MEM_HOOK));
+ /* Create and initialize a new hook entry */
+ Hook = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(*Hook));
if (Hook == NULL) return FALSE;
Hook->hVdd = NULL;
@@ -208,8 +227,10 @@
Hook->FastReadHandler = ReadHandler;
Hook->FastWriteHandler = WriteHandler;
+ /* Add the hook entry to the page table... */
for (i = FirstPage; i <= LastPage; i++) PageTable[i] = Hook;
+ /* ... and to the list of hooks */
InsertTailList(&HookList, &Hook->Entry);
return TRUE;
}
@@ -217,15 +238,16 @@
BOOL
MemRemoveFastMemoryHook(PVOID Address, ULONG Size)
{
+ PMEM_HOOK Hook;
ULONG i;
- ULONG FirstPage = (ULONG)Address >> 12;
- ULONG LastPage = ((ULONG)Address + Size - 1) >> 12;
+ ULONG FirstPage = (ULONG_PTR)Address >> 12;
+ ULONG LastPage = ((ULONG_PTR)Address + Size - 1) >> 12;
if (Size == 0) return FALSE;
for (i = FirstPage; i <= LastPage; i++)
{
- PMEM_HOOK Hook = PageTable[i];
+ Hook = PageTable[i];
if (Hook == NULL || Hook->hVdd != NULL) continue;
if (--Hook->Count == 0)
@@ -241,18 +263,82 @@
return TRUE;
}
+
+
+PBYTE
+WINAPI
+Sim32pGetVDMPointer(IN ULONG Address,
+ IN BOOLEAN ProtectedMode)
+{
+ // FIXME
+ UNREFERENCED_PARAMETER(ProtectedMode);
+
+ /*
+ * HIWORD(Address) == Segment (if ProtectedMode == FALSE)
+ * or Selector (if ProtectedMode == TRUE )
+ * LOWORD(Address) == Offset
+ */
+ return (PBYTE)FAR_POINTER(Address);
+}
+
+PBYTE
+WINAPI
+MGetVdmPointer(IN ULONG Address,
+ IN ULONG Size,
+ IN BOOLEAN ProtectedMode)
+{
+ UNREFERENCED_PARAMETER(Size);
+ return Sim32pGetVDMPointer(Address, ProtectedMode);
+}
+
+PVOID
+WINAPI
+VdmMapFlat(IN USHORT Segment,
+ IN ULONG Offset,
+ IN VDM_MODE Mode)
+{
+ // FIXME
+ UNREFERENCED_PARAMETER(Mode);
+
+ return SEG_OFF_TO_PTR(Segment, Offset);
+}
+
BOOL
WINAPI
-VDDInstallMemoryHook(HANDLE hVdd,
- PVOID pStart,
- DWORD dwCount,
- PVDD_MEMORY_HANDLER pHandler)
+VdmFlushCache(IN USHORT Segment,
+ IN ULONG Offset,
+ IN ULONG Size,
+ IN VDM_MODE Mode)
+{
+ // FIXME
+ UNIMPLEMENTED;
+ return TRUE;
+}
+
+BOOL
+WINAPI
+VdmUnmapFlat(IN USHORT Segment,
+ IN ULONG Offset,
+ IN PVOID Buffer,
+ IN VDM_MODE Mode)
+{
+ // FIXME
+ UNIMPLEMENTED;
+ return TRUE;
+}
+
+BOOL
+WINAPI
+VDDInstallMemoryHook(IN HANDLE hVdd,
+ IN PVOID pStart,
+ IN DWORD dwCount,
+ IN PVDD_MEMORY_HANDLER MemoryHandler)
{
NTSTATUS Status;
PMEM_HOOK Hook;
ULONG i;
- ULONG FirstPage = (ULONG)pStart >> 12;
- ULONG LastPage = ((ULONG)pStart + dwCount - 1) >> 12;
+ ULONG FirstPage = (ULONG_PTR)pStart >> 12;
+ ULONG LastPage = ((ULONG_PTR)pStart + dwCount - 1) >> 12;
PVOID Address = (PVOID)(FirstPage * PAGE_SIZE);
SIZE_T Size = (LastPage - FirstPage + 1) * PAGE_SIZE;
@@ -266,12 +352,13 @@
if (PageTable[i] != NULL) return FALSE;
}
- Hook = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(MEM_HOOK));
+ /* Create and initialize a new hook entry */
+ Hook = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(*Hook));
if (Hook == NULL) return FALSE;
Hook->hVdd = hVdd;
Hook->Count = LastPage - FirstPage + 1;
- Hook->VddHandler = pHandler;
+ Hook->VddHandler = MemoryHandler;
/* Decommit the pages */
Status = NtFreeVirtualMemory(NtCurrentProcess(), &Address, &Size,
MEM_DECOMMIT);
@@ -281,22 +368,25 @@
return FALSE;
}
+ /* Add the hook entry to the page table... */
for (i = FirstPage; i <= LastPage; i++) PageTable[i] = Hook;
+ /* ... and to the list of hooks */
InsertTailList(&HookList, &Hook->Entry);
return TRUE;
}
BOOL
WINAPI
-VDDDeInstallMemoryHook(HANDLE hVdd,
- PVOID pStart,
- DWORD dwCount)
+VDDDeInstallMemoryHook(IN HANDLE hVdd,
+ IN PVOID pStart,
+ IN DWORD dwCount)
{
NTSTATUS Status;
+ PMEM_HOOK Hook;
ULONG i;
- ULONG FirstPage = (ULONG)pStart >> 12;
- ULONG LastPage = ((ULONG)pStart + dwCount - 1) >> 12;
+ ULONG FirstPage = (ULONG_PTR)pStart >> 12;
+ ULONG LastPage = ((ULONG_PTR)pStart + dwCount - 1) >> 12;
PVOID Address = (PVOID)(FirstPage * PAGE_SIZE);
SIZE_T Size = (LastPage - FirstPage + 1) * PAGE_SIZE;
@@ -313,7 +403,7 @@
for (i = FirstPage; i <= LastPage; i++)
{
- PMEM_HOOK Hook = PageTable[i];
+ Hook = PageTable[i];
if (Hook == NULL) continue;
if (Hook->hVdd != hVdd)
@@ -335,6 +425,8 @@
return TRUE;
}
+
+
BOOLEAN
MemInitialize(VOID)
{
@@ -346,6 +438,8 @@
/*
* The reserved region starts from the very first page.
* We need to commit the reserved first 16 MB virtual address.
+ *
+ * NOTE: NULL has another signification for NtAllocateVirtualMemory.
*/
BaseAddress = (PVOID)1;
@@ -398,10 +492,11 @@
{
NTSTATUS Status;
SIZE_T MemorySize = MAX_ADDRESS;
-
- while (HookList.Flink != &HookList)
- {
- PLIST_ENTRY Pointer = RemoveHeadList(&HookList);
+ PLIST_ENTRY Pointer;
+
+ while (!IsListEmpty(&HookList))
+ {
+ Pointer = RemoveHeadList(&HookList);
RtlFreeHeap(RtlGetProcessHeap(), 0, CONTAINING_RECORD(Pointer, MEM_HOOK,
Entry));
}
@@ -420,3 +515,5 @@
DPRINT1("NTVDM: Failed to decommit VDM memory, Status 0x%08lx\n",
Status);
}
}
+
+/* EOF */
Modified: trunk/reactos/subsystems/mvdm/ntvdm/memory.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/memo…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/memory.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/memory.h [iso-8859-1] Fri Mar 13 22:38:44 2015
@@ -12,13 +12,6 @@
/* DEFINITIONS ****************************************************************/
#define TOTAL_PAGES (MAX_ADDRESS / PAGE_SIZE)
-
-typedef VOID
-(WINAPI *PVDD_MEMORY_HANDLER)
-(
- DWORD FaultingAddress,
- BOOLEAN Writing
-);
typedef VOID
(WINAPI *PMEMORY_READ_HANDLER)
@@ -36,29 +29,11 @@
ULONG Size
);
-typedef struct _MEM_HOOK
-{
- LIST_ENTRY Entry;
- HANDLE hVdd;
- ULONG Count;
-
- union
- {
- PVDD_MEMORY_HANDLER VddHandler;
-
- struct
- {
- PMEMORY_READ_HANDLER FastReadHandler;
- PMEMORY_WRITE_HANDLER FastWriteHandler;
- };
- };
-} MEM_HOOK, *PMEM_HOOK;
-
/* FUNCTIONS ******************************************************************/
BOOLEAN MemInitialize(VOID);
VOID MemCleanup(VOID);
-VOID MemExceptionHandler(DWORD Address, BOOLEAN Writing);
+VOID MemExceptionHandler(ULONG FaultAddress, BOOLEAN Writing);
VOID
MemRead
@@ -92,25 +67,6 @@
ULONG Size
);
-BOOL
-WINAPI
-VDDInstallMemoryHook
-(
- HANDLE hVdd,
- PVOID pStart,
- DWORD dwCount,
- PVDD_MEMORY_HANDLER pHandler
-);
-
-BOOL
-WINAPI
-VDDDeInstallMemoryHook
-(
- HANDLE hVdd,
- PVOID pStart,
- DWORD dwCount
-);
-
#endif // _MEMORY_H_
/* EOF */