ReactOS  0.4.13-dev-982-g9853eab
memory.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: GPLv2+ - See COPYING in the top level directory
3  * PROJECT: ReactOS Virtual DOS Machine
4  * FILE: subsystems/mvdm/ntvdm/memory.c
5  * PURPOSE: Memory Management
6  * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "ntvdm.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 #include "emulator.h"
17 #include "memory.h"
18 
19 /* PRIVATE VARIABLES **********************************************************/
20 
21 typedef struct _MEM_HOOK
22 {
26 
27  union
28  {
30 
31  struct
32  {
35  };
36  };
38 
42 
43 /* PRIVATE FUNCTIONS **********************************************************/
44 
45 static inline VOID
47  IN const VOID UNALIGNED *Source,
49 {
50 #if 1
51  /*
52  * We use a switch here to detect small moves of memory, as these
53  * constitute the bulk of our moves.
54  * Using RtlMoveMemory for all these small moves would be slow otherwise.
55  */
56  switch (Length)
57  {
58  case 0:
59  return;
60 
61  case sizeof(UCHAR):
63  return;
64 
65  case sizeof(USHORT):
67  return;
68 
69  case sizeof(ULONG):
71  return;
72 
73  case sizeof(ULONGLONG):
75  return;
76 
77  default:
78 #if defined(__GNUC__)
79  __builtin_memmove(Destination, Source, Length);
80 #else
82 #endif
83  }
84 
85 #else // defined(_MSC_VER)
86 
87  PUCHAR Dest = (PUCHAR)Destination;
88  PUCHAR Src = (PUCHAR)Source;
89 
91 
92  /* Move dword */
93  Count = NewSize >> 2; // NewSize / sizeof(ULONG);
94  NewSize = NewSize & 3; // NewSize % sizeof(ULONG);
95  __movsd(Dest, Src, Count);
96  Dest += Count << 2; // Count * sizeof(ULONG);
97  Src += Count << 2;
98 
99  /* Move word */
100  Count = NewSize >> 1; // NewSize / sizeof(USHORT);
101  NewSize = NewSize & 1; // NewSize % sizeof(USHORT);
102  __movsw(Dest, Src, Count);
103  Dest += Count << 1; // Count * sizeof(USHORT);
104  Src += Count << 1;
105 
106  /* Move byte */
107  Count = NewSize; // NewSize / sizeof(UCHAR);
108  // NewSize = NewSize; // NewSize % sizeof(UCHAR);
109  __movsb(Dest, Src, Count);
110 
111 #endif
112 }
113 
114 static inline VOID
116 {
117  if (Hook && !Hook->hVdd && Hook->FastReadHandler)
118  {
120  }
121 
123 }
124 
125 static inline VOID
127 {
128  if (!Hook
129  || Hook->hVdd
130  || !Hook->FastWriteHandler
131  || Hook->FastWriteHandler(Address, Buffer, Size))
132  {
134  }
135 }
136 
137 /* PUBLIC FUNCTIONS ***********************************************************/
138 
140 {
141  ULONG i, Offset, Length;
142  ULONG FirstPage, LastPage;
143 
145 
146  /* Mirror 0x000FFFF0 at 0xFFFFFFF0 */
147  if (Address >= 0xFFFFFFF0) Address -= 0xFFF00000;
148 
149  /* If the A20 line is disabled, mask bit 20 */
150  if (!A20Line) Address &= ~(1 << 20);
151 
152  if ((Address + Size - 1) >= MAX_ADDRESS)
153  {
154  ULONG ExtraStart = (Address < MAX_ADDRESS) ? MAX_ADDRESS - Address : 0;
155 
156  /* Fill the memory that was above the limit with 0xFF */
157  RtlFillMemory((PVOID)((ULONG_PTR)Buffer + ExtraStart), Size - ExtraStart, 0xFF);
158 
160  else return;
161  }
162 
163  FirstPage = Address >> 12;
164  LastPage = (Address + Size - 1) >> 12;
165 
166  if (FirstPage == LastPage)
167  {
168  ReadPage(PageTable[FirstPage], Address, Buffer, Size);
169  }
170  else
171  {
172  for (i = FirstPage; i <= LastPage; i++)
173  {
174  Offset = (i == FirstPage) ? (Address & (PAGE_SIZE - 1)) : 0;
175  Length = ((i == LastPage) ? (Address + Size - (LastPage << 12)) : PAGE_SIZE) - Offset;
176 
177  ReadPage(PageTable[i], (i << 12) + Offset, Buffer, Length);
179  }
180  }
181 }
182 
184 {
185  ULONG i, Offset, Length;
186  ULONG FirstPage, LastPage;
187 
189 
190  /* If the A20 line is disabled, mask bit 20 */
191  if (!A20Line) Address &= ~(1 << 20);
192 
193  if (Address >= MAX_ADDRESS) return;
195 
196  FirstPage = Address >> 12;
197  LastPage = (Address + Size - 1) >> 12;
198 
199  if (FirstPage == LastPage)
200  {
201  WritePage(PageTable[FirstPage], Address, Buffer, Size);
202  }
203  else
204  {
205  for (i = FirstPage; i <= LastPage; i++)
206  {
207  Offset = (i == FirstPage) ? (Address & (PAGE_SIZE - 1)) : 0;
208  Length = ((i == LastPage) ? (Address + Size - (LastPage << 12)) : PAGE_SIZE) - Offset;
209 
210  WritePage(PageTable[i], (i << 12) + Offset, Buffer, Length);
212  }
213  }
214 }
215 
216 VOID FASTCALL EmulatorCopyMemory(PFAST486_STATE State, ULONG DestAddress, ULONG SrcAddress, ULONG Size)
217 {
218  /*
219  * Guest-to-guest memory copy
220  */
221 
222  // FIXME: This is a temporary implementation of a more useful functionality
223  // which should be a merge of EmulatorReadMemory & EmulatorWriteMemory without
224  // any local external buffer.
225  // NOTE: Process heap is by default serialized (unless one specifies it shouldn't).
226  static BYTE StaticBuffer[8192]; // Smallest static buffer we can use.
227  static PVOID HeapBuffer = NULL; // Always-growing heap buffer. Use it in case StaticBuffer is too small.
228  static ULONG HeapBufferSize = 0;
229  PVOID LocalBuffer; // Points to either StaticBuffer or HeapBuffer
230 
231  if (Size <= sizeof(StaticBuffer))
232  {
233  /* Use the static buffer */
234  LocalBuffer = StaticBuffer;
235  }
236  else if (/* sizeof(StaticBuffer) <= Size && */ Size <= HeapBufferSize)
237  {
238  /* Use the heap buffer */
239  ASSERT(HeapBufferSize > 0 && HeapBuffer != NULL);
240  LocalBuffer = HeapBuffer;
241  }
242  else // if (Size > HeapBufferSize)
243  {
244  /* Enlarge the heap buffer and use it */
245 
246  if (HeapBuffer == NULL)
247  {
248  /* First allocation */
249  LocalBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Size);
250  }
251  else
252  {
253  /* Reallocation */
254  LocalBuffer = RtlReAllocateHeap(RtlGetProcessHeap(), 0 /* HEAP_GENERATE_EXCEPTIONS */, HeapBuffer, Size);
255  }
256  ASSERT(LocalBuffer != NULL); // We must succeed! TODO: Handle it more properly.
257  HeapBuffer = LocalBuffer; // HeapBuffer is now reallocated.
258  HeapBufferSize = Size;
259  }
260 
261  /* Perform memory copy */
262  EmulatorReadMemory( State, SrcAddress , LocalBuffer, Size);
263  EmulatorWriteMemory(State, DestAddress, LocalBuffer, Size);
264 
265  // if (LocalBuffer != StaticBuffer)
266  // RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer);
267 
268  // Note that we don't free HeapBuffer since it's an always-growing buffer.
269  // It is freed when NTVDM termiantes.
270 }
271 
273 {
274  A20Line = Enabled;
275 }
276 
278 {
279  return A20Line;
280 }
281 
282 VOID
283 MemExceptionHandler(ULONG FaultAddress, BOOLEAN Writing)
284 {
285  PMEM_HOOK Hook = PageTable[FaultAddress >> 12];
286  DPRINT("The memory at 0x%08X could not be %s.\n", FaultAddress, Writing ? "written" : "read");
287 
288  /* Exceptions are only supposed to happen when using VDD-style memory hooks */
289  ASSERT(FaultAddress < MAX_ADDRESS && Hook != NULL && Hook->hVdd != NULL);
290 
291  /* Call the VDD handler */
292  Hook->VddHandler(REAL_TO_PHYS(FaultAddress), (ULONG)Writing);
293 }
294 
295 BOOL
297  ULONG Size,
298  PMEMORY_READ_HANDLER ReadHandler,
299  PMEMORY_WRITE_HANDLER WriteHandler)
300 {
301  PMEM_HOOK Hook;
302  ULONG i;
303  ULONG FirstPage = (ULONG_PTR)Address >> 12;
304  ULONG LastPage = ((ULONG_PTR)Address + Size - 1) >> 12;
305  PLIST_ENTRY Pointer;
306 
307  /* Make sure none of these pages are already allocated */
308  for (i = FirstPage; i <= LastPage; i++)
309  {
310  if (PageTable[i] != NULL) return FALSE;
311  }
312 
313  for (Pointer = HookList.Flink; Pointer != &HookList; Pointer = Pointer->Flink)
314  {
315  Hook = CONTAINING_RECORD(Pointer, MEM_HOOK, Entry);
316 
317  if (Hook->hVdd == NULL
318  && Hook->FastReadHandler == ReadHandler
319  && Hook->FastWriteHandler == WriteHandler)
320  {
321  break;
322  }
323  }
324 
325  if (Pointer == &HookList)
326  {
327  /* Create and initialize a new hook entry... */
328  Hook = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(*Hook));
329  if (Hook == NULL) return FALSE;
330 
331  Hook->hVdd = NULL;
332  Hook->Count = 0;
333  Hook->FastReadHandler = ReadHandler;
334  Hook->FastWriteHandler = WriteHandler;
335 
336  /* ... and add it to the list of hooks */
337  InsertTailList(&HookList, &Hook->Entry);
338  }
339 
340  /* Increase the number of pages this hook has */
341  Hook->Count += LastPage - FirstPage + 1;
342 
343  /* Add the hook entry to the page table */
344  for (i = FirstPage; i <= LastPage; i++) PageTable[i] = Hook;
345 
346  return TRUE;
347 }
348 
349 BOOL
351 {
352  PMEM_HOOK Hook;
353  ULONG i;
354  ULONG FirstPage = (ULONG_PTR)Address >> 12;
355  ULONG LastPage = ((ULONG_PTR)Address + Size - 1) >> 12;
356 
357  if (Size == 0) return FALSE;
358 
359  for (i = FirstPage; i <= LastPage; i++)
360  {
361  Hook = PageTable[i];
362  if (Hook == NULL || Hook->hVdd != NULL) continue;
363 
364  if (--Hook->Count == 0)
365  {
366  /* This hook has no more pages */
367  RemoveEntryList(&Hook->Entry);
368  RtlFreeHeap(RtlGetProcessHeap(), 0, Hook);
369  }
370 
371  PageTable[i] = NULL;
372  }
373 
374  return TRUE;
375 }
376 
377 BOOLEAN
379 {
380  ULONG Page = StartAddress >> 12;
381  if (Page >= TOTAL_PAGES) return FALSE;
382 
383  *Length = 0;
384  *Hooked = PageTable[Page] != NULL;
385 
386  while (Page < TOTAL_PAGES && (PageTable[Page] != NULL) == *Hooked)
387  {
388  *Length += PAGE_SIZE;
389  Page++;
390  }
391 
392  return TRUE;
393 }
394 
395 PBYTE
396 WINAPI
398  IN BOOLEAN ProtectedMode)
399 {
400  // FIXME
401  UNREFERENCED_PARAMETER(ProtectedMode);
402 
403  /*
404  * HIWORD(Address) == Segment (if ProtectedMode == FALSE)
405  * or Selector (if ProtectedMode == TRUE )
406  * LOWORD(Address) == Offset
407  */
408  return (PBYTE)FAR_POINTER(Address);
409 }
410 
411 PBYTE
412 WINAPI
414  IN ULONG Size,
415  IN BOOLEAN ProtectedMode)
416 {
418  return Sim32pGetVDMPointer(Address, ProtectedMode);
419 }
420 
421 PVOID
422 WINAPI
424  IN ULONG Offset,
425  IN VDM_MODE Mode)
426 {
427  // FIXME
429 
430  return SEG_OFF_TO_PTR(Segment, Offset);
431 }
432 
433 #ifndef VdmFlushCache
434 
435 BOOL
436 WINAPI
438  IN ULONG Offset,
439  IN ULONG Size,
440  IN VDM_MODE Mode)
441 {
442  // FIXME
444  return TRUE;
445 }
446 
447 #endif
448 
449 #ifndef VdmUnmapFlat
450 
451 BOOL
452 WINAPI
454  IN ULONG Offset,
455  IN PVOID Buffer,
456  IN VDM_MODE Mode)
457 {
458  // FIXME
460  return TRUE;
461 }
462 
463 #endif
464 
465 BOOL
466 WINAPI
468  IN PVOID pStart,
469  IN DWORD dwCount,
471 {
473  PMEM_HOOK Hook;
474  ULONG i;
475  ULONG FirstPage = (ULONG_PTR)PHYS_TO_REAL(pStart) >> 12;
476  ULONG LastPage = ((ULONG_PTR)PHYS_TO_REAL(pStart) + dwCount - 1) >> 12;
477  PVOID Address = (PVOID)REAL_TO_PHYS(FirstPage * PAGE_SIZE);
478  SIZE_T Size = (LastPage - FirstPage + 1) * PAGE_SIZE;
479  PLIST_ENTRY Pointer;
480 
481  /* Check validity of the VDD handle */
482  if (hVdd == NULL || hVdd == INVALID_HANDLE_VALUE)
483  {
485  return FALSE;
486  }
487 
488  if (dwCount == 0) return FALSE;
489 
490  /* Make sure none of these pages are already allocated */
491  for (i = FirstPage; i <= LastPage; i++)
492  {
493  if (PageTable[i] != NULL) return FALSE;
494  }
495 
496  for (Pointer = HookList.Flink; Pointer != &HookList; Pointer = Pointer->Flink)
497  {
498  Hook = CONTAINING_RECORD(Pointer, MEM_HOOK, Entry);
499  if (Hook->hVdd == hVdd && Hook->VddHandler == MemoryHandler) break;
500  }
501 
502  if (Pointer == &HookList)
503  {
504  /* Create and initialize a new hook entry... */
505  Hook = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(*Hook));
506  if (Hook == NULL)
507  {
509  return FALSE;
510  }
511 
512  Hook->hVdd = hVdd;
513  Hook->Count = 0;
514  Hook->VddHandler = MemoryHandler;
515 
516  /* ... and add it to the list of hooks */
517  InsertTailList(&HookList, &Hook->Entry);
518  }
519 
520  /* Decommit the pages */
522  &Address,
523  &Size,
524  MEM_DECOMMIT);
525  if (!NT_SUCCESS(Status))
526  {
527  if (Pointer == &HookList)
528  {
529  RemoveEntryList(&Hook->Entry);
530  RtlFreeHeap(RtlGetProcessHeap(), 0, Hook);
531  }
532 
533  return FALSE;
534  }
535 
536  /* Increase the number of pages this hook has */
537  Hook->Count += LastPage - FirstPage + 1;
538 
539  /* Add the hook entry to the page table */
540  for (i = FirstPage; i <= LastPage; i++) PageTable[i] = Hook;
541 
542  return TRUE;
543 }
544 
545 BOOL
546 WINAPI
548  IN PVOID pStart,
549  IN DWORD dwCount)
550 {
552  PMEM_HOOK Hook;
553  ULONG i;
554  ULONG FirstPage = (ULONG_PTR)PHYS_TO_REAL(pStart) >> 12;
555  ULONG LastPage = ((ULONG_PTR)PHYS_TO_REAL(pStart) + dwCount - 1) >> 12;
556  PVOID Address = (PVOID)REAL_TO_PHYS(FirstPage * PAGE_SIZE);
557  SIZE_T Size = (LastPage - FirstPage + 1) * PAGE_SIZE;
558 
559  /* Check validity of the VDD handle */
560  if (hVdd == NULL || hVdd == INVALID_HANDLE_VALUE)
561  {
563  return FALSE;
564  }
565 
566  if (dwCount == 0) return FALSE;
567 
568  /* Commit the pages */
570  &Address,
571  0,
572  &Size,
573  MEM_COMMIT,
575  if (!NT_SUCCESS(Status)) return FALSE;
576 
577  for (i = FirstPage; i <= LastPage; i++)
578  {
579  Hook = PageTable[i];
580  if (Hook == NULL) continue;
581 
582  if (Hook->hVdd != hVdd)
583  {
584  DPRINT1("VDDDeInstallMemoryHook: Page %u owned by someone else.\n", i);
585  continue;
586  }
587 
588  if (--Hook->Count == 0)
589  {
590  /* This hook has no more pages */
591  RemoveEntryList(&Hook->Entry);
592  RtlFreeHeap(RtlGetProcessHeap(), 0, Hook);
593  }
594 
595  PageTable[i] = NULL;
596  }
597 
598  return TRUE;
599 }
600 
601 BOOL
602 WINAPI
604  IN PVOID Address,
605  IN ULONG Size)
606 {
608  PMEM_HOOK Hook;
609  ULONG i;
610  ULONG FirstPage = (ULONG_PTR)PHYS_TO_REAL(Address) >> 12;
611  ULONG LastPage = ((ULONG_PTR)PHYS_TO_REAL(Address) + Size - 1) >> 12;
612  SIZE_T RealSize = (LastPage - FirstPage + 1) * PAGE_SIZE;
613 
614  /* Check validity of the VDD handle */
615  if (hVdd == NULL || hVdd == INVALID_HANDLE_VALUE)
616  {
618  return FALSE;
619  }
620 
621  if (Size == 0) return FALSE;
622 
623  /* Fixup the address */
624  Address = (PVOID)REAL_TO_PHYS(FirstPage * PAGE_SIZE);
625 
626  /* Be sure that all the region is held by the VDD */
627  for (i = FirstPage; i <= LastPage; i++)
628  {
629  Hook = PageTable[i];
630  if (Hook == NULL) return FALSE;
631 
632  if (Hook->hVdd != hVdd)
633  {
634  DPRINT1("VDDAllocMem: Page %u owned by someone else.\n", i);
635  return FALSE;
636  }
637  }
638 
639  /* OK, all the range is held by the VDD. Commit the pages. */
641  &Address,
642  0,
643  &RealSize,
644  MEM_COMMIT,
646  return NT_SUCCESS(Status);
647 }
648 
649 BOOL
650 WINAPI
652  IN PVOID Address,
653  IN ULONG Size)
654 {
656  PMEM_HOOK Hook;
657  ULONG i;
658  ULONG FirstPage = (ULONG_PTR)PHYS_TO_REAL(Address) >> 12;
659  ULONG LastPage = ((ULONG_PTR)PHYS_TO_REAL(Address) + Size - 1) >> 12;
660  SIZE_T RealSize = (LastPage - FirstPage + 1) * PAGE_SIZE;
661 
662  /* Check validity of the VDD handle */
663  if (hVdd == NULL || hVdd == INVALID_HANDLE_VALUE)
664  {
666  return FALSE;
667  }
668 
669  if (Size == 0) return FALSE;
670 
671  /* Fixup the address */
672  Address = (PVOID)REAL_TO_PHYS(FirstPage * PAGE_SIZE);
673 
674  /* Be sure that all the region is held by the VDD */
675  for (i = FirstPage; i <= LastPage; i++)
676  {
677  Hook = PageTable[i];
678  if (Hook == NULL) return FALSE;
679 
680  if (Hook->hVdd != hVdd)
681  {
682  DPRINT1("VDDFreeMem: Page %u owned by someone else.\n", i);
683  return FALSE;
684  }
685  }
686 
687  /* OK, all the range is held by the VDD. Decommit the pages. */
689  &Address,
690  &RealSize,
691  MEM_DECOMMIT);
692  return NT_SUCCESS(Status);
693 }
694 
695 BOOL
696 WINAPI
698  IN PVOID Address,
699  IN ULONG Size)
700 {
701  // FIXME
703  return FALSE;
704 }
705 
706 BOOL
707 WINAPI
709  IN PVOID Address,
710  IN ULONG Size)
711 {
712  // FIXME
714  return FALSE;
715 }
716 
717 
718 
719 BOOLEAN
721 {
723  SIZE_T MemorySize = MAX_ADDRESS; // See: kernel32/client/vdm.c!BaseGetVdmConfigInfo
724 
726 
727 #ifndef STANDALONE
728 
729  /*
730  * The reserved region starts from the very first page.
731  * We need to commit the reserved first 16 MB virtual address.
732  *
733  * NOTE: NULL has another signification for NtAllocateVirtualMemory.
734  */
735  BaseAddress = (PVOID)1;
736 
737  /*
738  * Since to get NULL, we allocated from 0x1, account for this.
739  * See also: kernel32/client/proc.c!CreateProcessInternalW
740  */
741  MemorySize -= 1;
742 
743 #else
744 
745  /* Allocate it anywhere */
746  BaseAddress = NULL;
747 
748 #endif
749 
751  &BaseAddress,
752  0,
753  &MemorySize,
754 #ifndef STANDALONE
755  MEM_COMMIT,
756 #else
758 #endif
760  if (!NT_SUCCESS(Status))
761  {
762  wprintf(L"FATAL: Failed to commit VDM memory, Status 0x%08lx\n", Status);
763  return FALSE;
764  }
765 
766 #ifndef STANDALONE
767  ASSERT(BaseAddress == NULL);
768 #endif
769 
770  /*
771  * For diagnostics purposes, we fill the memory with INT 0x03 codes
772  * so that if a program wants to execute random code in memory, we can
773  * retrieve the exact CS:IP where the problem happens.
774  */
776  return TRUE;
777 }
778 
779 VOID
781 {
784  PLIST_ENTRY Pointer;
785 
786  while (!IsListEmpty(&HookList))
787  {
788  Pointer = RemoveHeadList(&HookList);
789  RtlFreeHeap(RtlGetProcessHeap(), 0, CONTAINING_RECORD(Pointer, MEM_HOOK, Entry));
790  }
791 
792  /* Decommit the VDM memory */
794  &BaseAddress,
795  &MemorySize,
796 #ifndef STANDALONE
798 #else
800 #endif
801  );
802  if (!NT_SUCCESS(Status))
803  {
804  DPRINT1("NTVDM: Failed to decommit VDM memory, Status 0x%08lx\n", Status);
805  }
806 }
807 
808 /* EOF */
BOOL WINAPI VDDDeInstallMemoryHook(IN HANDLE hVdd, IN PVOID pStart, IN DWORD dwCount)
Definition: memory.c:547
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define IN
Definition: typedefs.h:38
BOOLEAN MemQueryMemoryZone(ULONG StartAddress, PULONG Length, PBOOLEAN Hooked)
Definition: memory.c:378
#define TRUE
Definition: types.h:120
BOOLEAN EmulatorGetA20(VOID)
Definition: memory.c:277
_In_ ULONG Mode
Definition: hubbusif.h:303
static PMEM_HOOK PageTable[TOTAL_PAGES]
Definition: memory.c:40
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
VOID(FASTCALL * PMEMORY_READ_HANDLER)(ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.h:18
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG Count
Definition: memory.c:25
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
LIST_ENTRY Entry
Definition: memory.c:23
BOOL MemRemoveFastMemoryHook(PVOID Address, ULONG Size)
Definition: memory.c:350
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define PHYS_TO_REAL(ptr)
Definition: emulator.h:34
VOID FASTCALL EmulatorWriteMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:183
BOOL WINAPI VDDExcludeMem(IN HANDLE hVdd, IN PVOID Address, IN ULONG Size)
Definition: memory.c:708
PVOID WINAPI VdmMapFlat(IN USHORT Segment, IN ULONG Offset, IN VDM_MODE Mode)
Definition: memory.c:423
BOOLEAN(FASTCALL * PMEMORY_WRITE_HANDLER)(ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.h:26
#define wprintf(...)
Definition: whoami.c:18
#define InsertTailList(ListHead, Entry)
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T)
Definition: heap.c:2561
#define SEG_OFF_TO_PTR(seg, off)
Definition: emulator.h:28
#define FASTCALL
Definition: nt_native.h:50
#define MEM_COMMIT
Definition: nt_native.h:1313
#define STANDALONE
Definition: testlist.c:3
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
VDM_MODE
Definition: nt_vdd.h:219
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
BOOL WINAPI VDDInstallMemoryHook(IN HANDLE hVdd, IN PVOID pStart, IN DWORD dwCount, IN PVDD_MEMORY_HANDLER MemoryHandler)
Definition: memory.c:467
uint32_t ULONG_PTR
Definition: typedefs.h:63
struct _MEM_HOOK * PMEM_HOOK
BOOL WINAPI VDDFreeMem(IN HANDLE hVdd, IN PVOID Address, IN ULONG Size)
Definition: memory.c:651
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define MAX_ADDRESS
#define MEM_DECOMMIT
Definition: nt_native.h:1315
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
#define MEM_RESERVE
Definition: nt_native.h:1314
BOOL WINAPI VDDAllocMem(IN HANDLE hVdd, IN PVOID Address, IN ULONG Size)
Definition: memory.c:603
VOID FASTCALL EmulatorCopyMemory(PFAST486_STATE State, ULONG DestAddress, ULONG SrcAddress, ULONG Size)
Definition: memory.c:216
#define REAL_TO_PHYS(ptr)
Definition: emulator.h:33
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
BOOL WINAPI VDDIncludeMem(IN HANDLE hVdd, IN PVOID Address, IN ULONG Size)
Definition: memory.c:697
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
#define FAR_POINTER(x)
Definition: emulator.h:31
void * PVOID
Definition: retypes.h:9
static LIST_ENTRY HookList
Definition: memory.c:39
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_Inout_ PVOID Segment
Definition: exfuncs.h:893
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
PPC_QUAL void __movsb(unsigned char *Destination, const unsigned char *Source, unsigned long Count)
Definition: intrin_ppc.h:323
HANDLE hVdd
Definition: memory.c:24
BOOL WINAPI VdmUnmapFlat(IN USHORT Segment, IN ULONG Offset, IN PVOID Buffer, IN VDM_MODE Mode)
Definition: memory.c:453
static VOID ReadPage(PMEM_HOOK Hook, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:115
#define UNALIGNED
Definition: crtdefs.h:132
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:65
BOOL MemInstallFastMemoryHook(PVOID Address, ULONG Size, PMEMORY_READ_HANDLER ReadHandler, PMEMORY_WRITE_HANDLER WriteHandler)
Definition: memory.c:296
VOID EmulatorSetA20(BOOLEAN Enabled)
Definition: memory.c:272
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2891
#define SetLastError(x)
Definition: compat.h:409
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
PBYTE WINAPI MGetVdmPointer(IN ULONG Address, IN ULONG Size, IN BOOLEAN ProtectedMode)
Definition: memory.c:413
VOID(WINAPI * PVDD_MEMORY_HANDLER)(PVOID FaultAddress, ULONG RWMode)
Definition: nt_vdd.h:231
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
char * PBOOLEAN
Definition: retypes.h:11
static VOID WritePage(PMEM_HOOK Hook, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:126
VOID MemCleanup(VOID)
Definition: memory.c:780
static const WCHAR L[]
Definition: oid.c:1250
static CONST DWORD MemorySize[]
Definition: svga.c:32
PBYTE WINAPI Sim32pGetVDMPointer(IN ULONG Address, IN BOOLEAN ProtectedMode)
Definition: memory.c:397
VOID MemExceptionHandler(ULONG FaultAddress, BOOLEAN Writing)
Definition: memory.c:283
unsigned char BYTE
Definition: mem.h:68
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:117
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
BOOLEAN MemInitialize(VOID)
Definition: memory.c:720
Status
Definition: gdiplustypes.h:24
struct _MEM_HOOK MEM_HOOK
ULONG_PTR SIZE_T
Definition: typedefs.h:78
PPC_QUAL void __movsw(unsigned short *Destination, const unsigned short *Source, unsigned long Count)
Definition: intrin_ppc.h:328
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4367
#define TOTAL_PAGES
Definition: memory.h:14
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
PMEMORY_READ_HANDLER FastReadHandler
Definition: memory.c:33
#define DPRINT1
Definition: precomp.h:8
#define MEM_RELEASE
Definition: nt_native.h:1316
PPC_QUAL void __movsd(unsigned long *Destination, const unsigned long *Source, unsigned long Count)
Definition: intrin_ppc.h:333
#define OUT
Definition: typedefs.h:39
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:390
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
#define ULONG_PTR
Definition: config.h:101
static BOOLEAN A20Line
Definition: memory.c:41
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
PMEMORY_WRITE_HANDLER FastWriteHandler
Definition: memory.c:34
VOID WINAPI MemoryHandler(IN PVOID FaultAddress, IN ULONG RWMode)
Definition: testvdd.c:217
static VOID MemFastMoveMemory(OUT VOID UNALIGNED *Destination, IN const VOID UNALIGNED *Source, IN SIZE_T Length)
Definition: memory.c:46
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
BOOL WINAPI VdmFlushCache(IN USHORT Segment, IN ULONG Offset, IN ULONG Size, IN VDM_MODE Mode)
Definition: memory.c:437
BYTE * PBYTE
Definition: pedump.c:66
unsigned short * PUSHORT
Definition: retypes.h:2
base of all file and directory entries
Definition: entries.h:82
PVDD_MEMORY_HANDLER VddHandler
Definition: memory.c:29
VOID FASTCALL EmulatorReadMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:139
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
HANDLE hVdd
Definition: testvdd.c:87
#define PAGE_READWRITE
Definition: nt_native.h:1304
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5090