Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. va.h
  5. Abstract:
  6. Include file for the helpers for the virtual memory thunks on platforms
  7. where page size is not equal to 4K.
  8. Author:
  9. Dave Hastings (daveh) creation-date 26-Feb-1996
  10. Revision History:
  11. --*/
  12. //
  13. // Don't want to include anything unless SOFTWARE_4K_PAGESIZE is enabled.
  14. //
  15. #ifdef SOFTWARE_4K_PAGESIZE
  16. //
  17. // Constants
  18. //
  19. #define INTEL_PAGESIZE 0x1000
  20. #ifdef _ALPHA_
  21. #define NATIVE_PAGESIZE 0x2000
  22. #endif
  23. #ifdef _WHNT32_C_
  24. #define NtAllocateVirtualMemory(a,b,c,d,e,f) VaAllocateVirtualMemory(a,b,c,d,e,f)
  25. #define NtFreeVirtualMemory(a,b,c,d) VaFreeVirtualMemory(a,b,c,d)
  26. #define NtProtectVirtualMemory(a,b,c,d,e) VaProtectVirtualMemory(a,b,c,d,e)
  27. #define NtQueryVirtualMemory(a,b,c,d,e,f) VaQueryVirtualMemory(a,b,c,d,e,f)
  28. #define NtMapViewOfSection(a,b,c,d,e,f,g,h,i,j) VaMapViewOfSection(a,b,c,d,e,f,g,h,i,j)
  29. #define NtUnmapViewOfSection(a,b) VaUnmapViewOfSection(a,b)
  30. #endif
  31. //
  32. // Useful macros
  33. //
  34. #define INTEL_PAGEROUND(a) (a & ~(INTEL_PAGESIZE - 1))
  35. #define INTEL_PAGEMASK(a) (a & (INTEL_PAGESIZE - 1))
  36. #define NATIVE_PAGEROUND(a) (a & ~(NATIVE_PAGESIZE - 1))
  37. #define NATIVE_PAGEMASK(a) (a & (NATIVE_PAGESIZE - 1))
  38. #define VaNextNode(n) n->Next
  39. typedef ULONG_PTR STATE;
  40. typedef PULONG_PTR PSTATE;
  41. typedef ULONG PROT;
  42. typedef PULONG PPROT;
  43. #if DBG
  44. #define ASSRT(e) if (!(e)) { \
  45. DbgBreakPoint(); \
  46. }
  47. #else
  48. #define ASSRT(e)
  49. #endif
  50. //
  51. // Value used to mark allocation sentinels. This is put in both
  52. // the IntelState field of the sentinal
  53. //
  54. // Things to know about sentinels
  55. //
  56. // IntelState == VA_SENTINEL
  57. // IntelEnd == 0
  58. // State == Intel ending address
  59. // Protect = Sentinel Flags
  60. //
  61. // The above have to be true for the sentinels to be inserted into the
  62. // list and function correctly. There are sentinels only at the beginning
  63. // of a memory allocation.
  64. //
  65. #define VA_SENTINEL 0xFFFFFFFF
  66. // Sentinal flags in NativeProtect
  67. #define VA_MAPFILE 0x80000000
  68. //
  69. // Structure to track the state of the virtual address space
  70. // An instance of this inclusively describes a portion of the
  71. // address space
  72. //
  73. typedef struct _VANODE {
  74. struct _VANODE *Prev;
  75. struct _VANODE *Next;
  76. PUCHAR Start;
  77. PUCHAR End;
  78. STATE State;
  79. STATE IntelState;
  80. PROT Protection;
  81. PROT IntelProtection;
  82. } VANODE, *PVANODE;
  83. //
  84. // structure used to figure out how to satisfy the requested memory function
  85. //
  86. typedef enum _MEMACTION {
  87. CallSystem,
  88. FillMem,
  89. None
  90. } MEMACTION, *PMEMACTION;
  91. typedef struct _MEMCHUNK {
  92. PUCHAR Start;
  93. PUCHAR End;
  94. STATE State;
  95. PROT Protection;
  96. MEMACTION Action;
  97. } MEMCHUNK, *PMEMCHUNK;
  98. //
  99. // Functions called by the thunks
  100. //
  101. BOOLEAN VaInit();
  102. NTSTATUS
  103. VaAllocateVirtualMemory(
  104. IN HANDLE ProcessHandle,
  105. IN OUT PVOID *BaseAddress,
  106. IN ULONG_PTR ZeroBits,
  107. IN OUT PSIZE_T RegionSize,
  108. IN ULONG AllocationType,
  109. IN ULONG Protect
  110. );
  111. NTSTATUS
  112. VaFreeVirtualMemory(
  113. IN HANDLE ProcessHandle,
  114. IN OUT PVOID *BaseAddress,
  115. IN OUT PSIZE_T RegionSize,
  116. IN ULONG FreeType
  117. );
  118. NTSTATUS
  119. VaQueryVirtualMemory(
  120. IN HANDLE ProcessHandle,
  121. IN PVOID BaseAddress,
  122. IN MEMORY_INFORMATION_CLASS MemoryInformationClass,
  123. OUT PVOID MemoryInformation,
  124. IN ULONG MemoryInformationLength,
  125. OUT PULONG ReturnLength OPTIONAL
  126. );
  127. NTSTATUS
  128. VaProtectVirtualMemory(
  129. IN HANDLE ProcessHandle,
  130. IN OUT PVOID *BaseAddress,
  131. IN OUT PSIZE_T RegionSize,
  132. IN ULONG NewProtect,
  133. OUT PULONG OldProtect
  134. );
  135. NTSTATUS
  136. VaMapViewOfSection(
  137. IN HANDLE SectionHandle,
  138. IN HANDLE ProcessHandle,
  139. IN OUT PVOID *BaseAddress,
  140. IN ULONG_PTR ZeroBits,
  141. IN SIZE_T CommitSize,
  142. IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  143. IN OUT PSIZE_T ViewSize,
  144. IN SECTION_INHERIT InheritDisposition,
  145. IN ULONG AllocationType,
  146. IN ULONG Protect
  147. );
  148. NTSTATUS
  149. VaUnmapViewOfSection(
  150. IN HANDLE ProcessHandle,
  151. IN PVOID BaseAddress
  152. );
  153. //
  154. // Internal functions used to implement the above
  155. //
  156. BOOL
  157. VaQueryIntelPages(
  158. IN PVOID Address,
  159. OUT PULONG NumberOfPages,
  160. OUT PSTATE IntelState,
  161. OUT PPROT IntelProtection,
  162. OUT PSTATE NativeState,
  163. OUT PPROT NativeProtection
  164. );
  165. BOOL
  166. VaRecordMemoryOperation(
  167. PVOID IntelStart,
  168. PVOID IntelEnd,
  169. STATE State,
  170. PROT Protection,
  171. PMEMCHUNK Pages,
  172. ULONG Number
  173. );
  174. PVANODE
  175. VaFindNode(
  176. PVOID Address
  177. );
  178. PVANODE
  179. VaRemoveNode(
  180. PVANODE VaNode
  181. );
  182. PVANODE
  183. VaInsertNode(
  184. PVANODE VaNode
  185. );
  186. BOOL
  187. VaGetAllocationInformation(
  188. PUCHAR Address,
  189. PUCHAR *IntelBase,
  190. PULONG NumberOfPages,
  191. PSTATE IntelState,
  192. PPROT IntelProtection
  193. );
  194. VOID
  195. VaDeleteRegion(
  196. PCHAR Start,
  197. PCHAR End
  198. );
  199. PVANODE
  200. VaFindSentinel(
  201. PCHAR Address
  202. );
  203. PVANODE
  204. VaFindContainingSentinel(
  205. PCHAR Address
  206. );
  207. PVANODE
  208. VaInsertSentinel(
  209. PVANODE VaNode
  210. );
  211. void
  212. VaAddMemoryRecords(
  213. HANDLE ProcessHandle,
  214. LPVOID lpvAddress
  215. );
  216. #ifdef DBG
  217. VOID VaDumpNode(PVANODE);
  218. VOID VaDumpList();
  219. VOID
  220. VaDumpState(
  221. STATE State
  222. );
  223. VOID
  224. VaDumpProtection(
  225. PROT Protection
  226. );
  227. #endif
  228. #endif // SOFTWARE_4K_PAGESIZE