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.

561 lines
13 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntmmapi.h
  5. Abstract:
  6. This is the include file for the Memory Management sub-component of NTOS
  7. Author:
  8. Lou Perazzoli (loup) 10-May-1989
  9. Revision History:
  10. --*/
  11. #ifndef _NTMMAPI_
  12. #define _NTMMAPI_
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. typedef enum _MEMORY_INFORMATION_CLASS {
  20. MemoryBasicInformation
  21. #if DEVL
  22. ,MemoryWorkingSetInformation
  23. #endif
  24. ,MemoryMappedFilenameInformation
  25. } MEMORY_INFORMATION_CLASS;
  26. //
  27. // Memory information structures.
  28. //
  29. // begin_winnt
  30. typedef struct _MEMORY_BASIC_INFORMATION {
  31. PVOID BaseAddress;
  32. PVOID AllocationBase;
  33. ULONG AllocationProtect;
  34. SIZE_T RegionSize;
  35. ULONG State;
  36. ULONG Protect;
  37. ULONG Type;
  38. } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
  39. typedef struct _MEMORY_BASIC_INFORMATION32 {
  40. ULONG BaseAddress;
  41. ULONG AllocationBase;
  42. ULONG AllocationProtect;
  43. ULONG RegionSize;
  44. ULONG State;
  45. ULONG Protect;
  46. ULONG Type;
  47. } MEMORY_BASIC_INFORMATION32, *PMEMORY_BASIC_INFORMATION32;
  48. typedef struct _MEMORY_BASIC_INFORMATION64 {
  49. ULONGLONG BaseAddress;
  50. ULONGLONG AllocationBase;
  51. ULONG AllocationProtect;
  52. ULONG __alignment1;
  53. ULONGLONG RegionSize;
  54. ULONG State;
  55. ULONG Protect;
  56. ULONG Type;
  57. ULONG __alignment2;
  58. } MEMORY_BASIC_INFORMATION64, *PMEMORY_BASIC_INFORMATION64;
  59. // end_winnt
  60. typedef struct _MEMORY_WORKING_SET_BLOCK {
  61. ULONG_PTR Protection : 5;
  62. ULONG_PTR ShareCount : 3;
  63. ULONG_PTR Shared : 1;
  64. ULONG_PTR Node : 3;
  65. #if defined(_WIN64)
  66. ULONG_PTR VirtualPage : 52;
  67. #else
  68. ULONG VirtualPage : 20;
  69. #endif
  70. } MEMORY_WORKING_SET_BLOCK, *PMEMORY_WORKING_SET_BLOCK;
  71. typedef struct _MEMORY_WORKING_SET_INFORMATION {
  72. ULONG_PTR NumberOfEntries;
  73. MEMORY_WORKING_SET_BLOCK WorkingSetInfo[1];
  74. } MEMORY_WORKING_SET_INFORMATION, *PMEMORY_WORKING_SET_INFORMATION;
  75. //
  76. // MMPFNLIST_ and MMPFNUSE_ are used to characterize what
  77. // a physical page is being used for.
  78. //
  79. #define MMPFNLIST_ZERO 0
  80. #define MMPFNLIST_FREE 1
  81. #define MMPFNLIST_STANDBY 2
  82. #define MMPFNLIST_MODIFIED 3
  83. #define MMPFNLIST_MODIFIEDNOWRITE 4
  84. #define MMPFNLIST_BAD 5
  85. #define MMPFNLIST_ACTIVE 6
  86. #define MMPFNLIST_TRANSITION 7
  87. #define MMPFNUSE_PROCESSPRIVATE 0
  88. #define MMPFNUSE_FILE 1
  89. #define MMPFNUSE_PAGEFILEMAPPED 2
  90. #define MMPFNUSE_PAGETABLE 3
  91. #define MMPFNUSE_PAGEDPOOL 4
  92. #define MMPFNUSE_NONPAGEDPOOL 5
  93. #define MMPFNUSE_SYSTEMPTE 6
  94. #define MMPFNUSE_SESSIONPRIVATE 7
  95. #define MMPFNUSE_METAFILE 8
  96. #define MMPFNUSE_AWEPAGE 9
  97. #define MMPFNUSE_DRIVERLOCKPAGE 10
  98. typedef struct _MEMORY_FRAME_INFORMATION {
  99. ULONGLONG UseDescription : 4; // MMPFNUSE_*
  100. ULONGLONG ListDescription : 3; // MMPFNLIST_*
  101. ULONGLONG Reserved0 : 1; // Reserved for future expansion
  102. ULONGLONG Pinned : 1; // 1 indicates pinned, 0 means not pinned
  103. ULONGLONG DontUse : 48; // overlaid with INFORMATION structures
  104. ULONGLONG Reserved : 7; // Reserved for future expansion
  105. } MEMORY_FRAME_INFORMATION;
  106. typedef struct _FILEOFFSET_INFORMATION {
  107. ULONGLONG DontUse : 9; // overlaid with MEMORY_FRAME_INFORMATION
  108. ULONGLONG Offset : 48; // used for mapped files only.
  109. ULONGLONG Reserved : 7; // Reserved for future expansion
  110. } FILEOFFSET_INFORMATION;
  111. typedef struct _PAGEDIR_INFORMATION {
  112. ULONGLONG DontUse : 9; // overlaid with MEMORY_FRAME_INFORMATION
  113. ULONGLONG PageDirectoryBase : 48; // used for private pages only.
  114. ULONGLONG Reserved : 7; // Reserved for future expansion
  115. } PAGEDIR_INFORMATION;
  116. typedef struct _MMPFN_IDENTITY {
  117. union {
  118. MEMORY_FRAME_INFORMATION e1; // used for all cases.
  119. FILEOFFSET_INFORMATION e2; // used for mapped files only.
  120. PAGEDIR_INFORMATION e3; // used for private pages only.
  121. } u1;
  122. ULONG_PTR PageFrameIndex; // used for all cases.
  123. union {
  124. PVOID FileObject; // used for mapped files only.
  125. PVOID VirtualAddress; // used for everything but mapped files.
  126. } u2;
  127. } MMPFN_IDENTITY, *PMMPFN_IDENTITY;
  128. typedef struct _MMPFN_MEMSNAP_INFORMATION {
  129. ULONG_PTR InitialPageFrameIndex;
  130. ULONG_PTR Count;
  131. } MMPFN_MEMSNAP_INFORMATION, *PMMPFN_MEMSNAP_INFORMATION;
  132. typedef enum _SECTION_INFORMATION_CLASS {
  133. SectionBasicInformation,
  134. SectionImageInformation
  135. } SECTION_INFORMATION_CLASS;
  136. // begin_ntddk begin_wdm
  137. //
  138. // Section Information Structures.
  139. //
  140. // end_ntddk end_wdm
  141. typedef struct _SECTIONBASICINFO {
  142. PVOID BaseAddress;
  143. ULONG AllocationAttributes;
  144. LARGE_INTEGER MaximumSize;
  145. } SECTION_BASIC_INFORMATION, *PSECTION_BASIC_INFORMATION;
  146. #if _MSC_VER >= 1200
  147. #pragma warning(push)
  148. #endif
  149. #pragma warning(disable:4201) // unnamed struct
  150. typedef struct _SECTION_IMAGE_INFORMATION {
  151. PVOID TransferAddress;
  152. ULONG ZeroBits;
  153. SIZE_T MaximumStackSize;
  154. SIZE_T CommittedStackSize;
  155. ULONG SubSystemType;
  156. union {
  157. struct {
  158. USHORT SubSystemMinorVersion;
  159. USHORT SubSystemMajorVersion;
  160. };
  161. ULONG SubSystemVersion;
  162. };
  163. ULONG GpValue;
  164. USHORT ImageCharacteristics;
  165. USHORT DllCharacteristics;
  166. USHORT Machine;
  167. BOOLEAN ImageContainsCode;
  168. BOOLEAN Spare1;
  169. ULONG LoaderFlags;
  170. ULONG Reserved[ 2 ];
  171. } SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;
  172. #if _MSC_VER >= 1200
  173. #pragma warning(pop)
  174. #else
  175. #pragma warning( default : 4201 )
  176. #endif
  177. // begin_ntddk begin_wdm
  178. typedef enum _SECTION_INHERIT {
  179. ViewShare = 1,
  180. ViewUnmap = 2
  181. } SECTION_INHERIT;
  182. //
  183. // Section Access Rights.
  184. //
  185. // begin_winnt
  186. #define SECTION_QUERY 0x0001
  187. #define SECTION_MAP_WRITE 0x0002
  188. #define SECTION_MAP_READ 0x0004
  189. #define SECTION_MAP_EXECUTE 0x0008
  190. #define SECTION_EXTEND_SIZE 0x0010
  191. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  192. SECTION_MAP_WRITE | \
  193. SECTION_MAP_READ | \
  194. SECTION_MAP_EXECUTE | \
  195. SECTION_EXTEND_SIZE)
  196. // end_winnt
  197. #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
  198. #define PAGE_NOACCESS 0x01 // winnt
  199. #define PAGE_READONLY 0x02 // winnt
  200. #define PAGE_READWRITE 0x04 // winnt
  201. #define PAGE_WRITECOPY 0x08 // winnt
  202. #define PAGE_EXECUTE 0x10 // winnt
  203. #define PAGE_EXECUTE_READ 0x20 // winnt
  204. #define PAGE_EXECUTE_READWRITE 0x40 // winnt
  205. #define PAGE_EXECUTE_WRITECOPY 0x80 // winnt
  206. #define PAGE_GUARD 0x100 // winnt
  207. #define PAGE_NOCACHE 0x200 // winnt
  208. #define PAGE_WRITECOMBINE 0x400 // winnt
  209. // end_ntddk end_wdm
  210. #define MEM_COMMIT 0x1000 // winnt ntddk wdm
  211. #define MEM_RESERVE 0x2000 // winnt ntddk wdm
  212. #define MEM_DECOMMIT 0x4000 // winnt ntddk wdm
  213. #define MEM_RELEASE 0x8000 // winnt ntddk wdm
  214. #define MEM_FREE 0x10000 // winnt ntddk wdm
  215. #define MEM_PRIVATE 0x20000 // winnt ntddk wdm
  216. #define MEM_MAPPED 0x40000 // winnt ntddk wdm
  217. #define MEM_RESET 0x80000 // winnt ntddk wdm
  218. #define MEM_TOP_DOWN 0x100000 // winnt ntddk wdm
  219. #define MEM_WRITE_WATCH 0x200000 // winnt
  220. #define MEM_PHYSICAL 0x400000 // winnt
  221. #define MEM_LARGE_PAGES 0x20000000 // ntddk wdm
  222. #define MEM_DOS_LIM 0x40000000
  223. #define MEM_4MB_PAGES 0x80000000 // winnt ntddk wdm
  224. #define SEC_BASED 0x200000
  225. #define SEC_NO_CHANGE 0x400000
  226. #define SEC_FILE 0x800000 // winnt
  227. #define SEC_IMAGE 0x1000000 // winnt
  228. #define SEC_RESERVE 0x4000000 // winnt ntddk wdm
  229. #define SEC_COMMIT 0x8000000 // winnt ntifs
  230. #define SEC_NOCACHE 0x10000000 // winnt
  231. #define SEC_GLOBAL 0x20000000
  232. #define MEM_IMAGE SEC_IMAGE // winnt
  233. #define WRITE_WATCH_FLAG_RESET 0x01 // winnt
  234. #define MAP_PROCESS 1L
  235. #define MAP_SYSTEM 2L
  236. #define MEM_EXECUTE_OPTION_STACK 0x0001
  237. #define MEM_EXECUTE_OPTION_DATA 0x0002
  238. // begin_ntifs
  239. NTSYSCALLAPI
  240. NTSTATUS
  241. NTAPI
  242. NtCreateSection (
  243. OUT PHANDLE SectionHandle,
  244. IN ACCESS_MASK DesiredAccess,
  245. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  246. IN PLARGE_INTEGER MaximumSize OPTIONAL,
  247. IN ULONG SectionPageProtection,
  248. IN ULONG AllocationAttributes,
  249. IN HANDLE FileHandle OPTIONAL
  250. );
  251. // end_ntifs
  252. NTSYSCALLAPI
  253. NTSTATUS
  254. NTAPI
  255. NtOpenSection(
  256. OUT PHANDLE SectionHandle,
  257. IN ACCESS_MASK DesiredAccess,
  258. IN POBJECT_ATTRIBUTES ObjectAttributes
  259. );
  260. NTSYSCALLAPI
  261. NTSTATUS
  262. NTAPI
  263. NtMapViewOfSection(
  264. IN HANDLE SectionHandle,
  265. IN HANDLE ProcessHandle,
  266. IN OUT PVOID *BaseAddress,
  267. IN ULONG_PTR ZeroBits,
  268. IN SIZE_T CommitSize,
  269. IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  270. IN OUT PSIZE_T ViewSize,
  271. IN SECTION_INHERIT InheritDisposition,
  272. IN ULONG AllocationType,
  273. IN ULONG Protect
  274. );
  275. NTSYSCALLAPI
  276. NTSTATUS
  277. NTAPI
  278. NtUnmapViewOfSection(
  279. IN HANDLE ProcessHandle,
  280. IN PVOID BaseAddress
  281. );
  282. NTSYSCALLAPI
  283. NTSTATUS
  284. NTAPI
  285. NtExtendSection(
  286. IN HANDLE SectionHandle,
  287. IN OUT PLARGE_INTEGER NewSectionSize
  288. );
  289. NTSYSCALLAPI
  290. NTSTATUS
  291. NTAPI
  292. NtAreMappedFilesTheSame (
  293. IN PVOID File1MappedAsAnImage,
  294. IN PVOID File2MappedAsFile
  295. );
  296. // begin_ntifs
  297. NTSYSCALLAPI
  298. NTSTATUS
  299. NTAPI
  300. NtAllocateVirtualMemory(
  301. IN HANDLE ProcessHandle,
  302. IN OUT PVOID *BaseAddress,
  303. IN ULONG_PTR ZeroBits,
  304. IN OUT PSIZE_T RegionSize,
  305. IN ULONG AllocationType,
  306. IN ULONG Protect
  307. );
  308. NTSYSCALLAPI
  309. NTSTATUS
  310. NTAPI
  311. NtFreeVirtualMemory(
  312. IN HANDLE ProcessHandle,
  313. IN OUT PVOID *BaseAddress,
  314. IN OUT PSIZE_T RegionSize,
  315. IN ULONG FreeType
  316. );
  317. // end_ntifs
  318. NTSYSCALLAPI
  319. NTSTATUS
  320. NTAPI
  321. NtReadVirtualMemory(
  322. IN HANDLE ProcessHandle,
  323. IN PVOID BaseAddress,
  324. OUT PVOID Buffer,
  325. IN SIZE_T BufferSize,
  326. OUT PSIZE_T NumberOfBytesRead OPTIONAL
  327. );
  328. NTSYSCALLAPI
  329. NTSTATUS
  330. NTAPI
  331. NtWriteVirtualMemory(
  332. IN HANDLE ProcessHandle,
  333. OUT PVOID BaseAddress,
  334. IN CONST VOID *Buffer,
  335. IN SIZE_T BufferSize,
  336. OUT PSIZE_T NumberOfBytesWritten OPTIONAL
  337. );
  338. NTSYSCALLAPI
  339. NTSTATUS
  340. NTAPI
  341. NtFlushVirtualMemory(
  342. IN HANDLE ProcessHandle,
  343. IN OUT PVOID *BaseAddress,
  344. IN OUT PSIZE_T RegionSize,
  345. OUT PIO_STATUS_BLOCK IoStatus
  346. );
  347. NTSYSCALLAPI
  348. NTSTATUS
  349. NTAPI
  350. NtLockVirtualMemory(
  351. IN HANDLE ProcessHandle,
  352. IN OUT PVOID *BaseAddress,
  353. IN OUT PSIZE_T RegionSize,
  354. IN ULONG MapType
  355. );
  356. NTSYSCALLAPI
  357. NTSTATUS
  358. NTAPI
  359. NtUnlockVirtualMemory(
  360. IN HANDLE ProcessHandle,
  361. IN OUT PVOID *BaseAddress,
  362. IN OUT PSIZE_T RegionSize,
  363. IN ULONG MapType
  364. );
  365. NTSYSCALLAPI
  366. NTSTATUS
  367. NTAPI
  368. NtProtectVirtualMemory(
  369. IN HANDLE ProcessHandle,
  370. IN OUT PVOID *BaseAddress,
  371. IN OUT PSIZE_T RegionSize,
  372. IN ULONG NewProtect,
  373. OUT PULONG OldProtect
  374. );
  375. NTSYSCALLAPI
  376. NTSTATUS
  377. NTAPI
  378. NtQueryVirtualMemory(
  379. IN HANDLE ProcessHandle,
  380. IN PVOID BaseAddress,
  381. IN MEMORY_INFORMATION_CLASS MemoryInformationClass,
  382. OUT PVOID MemoryInformation,
  383. IN SIZE_T MemoryInformationLength,
  384. OUT PSIZE_T ReturnLength OPTIONAL
  385. );
  386. NTSYSCALLAPI
  387. NTSTATUS
  388. NTAPI
  389. NtQuerySection(
  390. IN HANDLE SectionHandle,
  391. IN SECTION_INFORMATION_CLASS SectionInformationClass,
  392. OUT PVOID SectionInformation,
  393. IN SIZE_T SectionInformationLength,
  394. OUT PSIZE_T ReturnLength OPTIONAL
  395. );
  396. NTSYSCALLAPI
  397. NTSTATUS
  398. NTAPI
  399. NtMapUserPhysicalPages(
  400. IN PVOID VirtualAddress,
  401. IN OUT ULONG_PTR NumberOfPages,
  402. IN OUT PULONG_PTR UserPfnArray OPTIONAL
  403. );
  404. NTSYSCALLAPI
  405. NTSTATUS
  406. NTAPI
  407. NtMapUserPhysicalPagesScatter(
  408. IN PVOID *VirtualAddresses,
  409. IN OUT ULONG_PTR NumberOfPages,
  410. IN OUT PULONG_PTR UserPfnArray OPTIONAL
  411. );
  412. NTSYSCALLAPI
  413. NTSTATUS
  414. NTAPI
  415. NtAllocateUserPhysicalPages(
  416. IN HANDLE ProcessHandle,
  417. IN OUT PULONG_PTR NumberOfPages,
  418. OUT PULONG_PTR UserPfnArray
  419. );
  420. NTSYSCALLAPI
  421. NTSTATUS
  422. NTAPI
  423. NtFreeUserPhysicalPages(
  424. IN HANDLE ProcessHandle,
  425. IN OUT PULONG_PTR NumberOfPages,
  426. IN PULONG_PTR UserPfnArray
  427. );
  428. NTSYSCALLAPI
  429. NTSTATUS
  430. NTAPI
  431. NtGetWriteWatch (
  432. IN HANDLE ProcessHandle,
  433. IN ULONG Flags,
  434. IN PVOID BaseAddress,
  435. IN SIZE_T RegionSize,
  436. IN OUT PVOID *UserAddressArray,
  437. IN OUT PULONG_PTR EntriesInUserAddressArray,
  438. OUT PULONG Granularity
  439. );
  440. NTSYSCALLAPI
  441. NTSTATUS
  442. NTAPI
  443. NtResetWriteWatch (
  444. IN HANDLE ProcessHandle,
  445. IN PVOID BaseAddress,
  446. IN SIZE_T RegionSize
  447. );
  448. NTSYSCALLAPI
  449. NTSTATUS
  450. NTAPI
  451. NtCreatePagingFile (
  452. IN PUNICODE_STRING PageFileName,
  453. IN PLARGE_INTEGER MinimumSize,
  454. IN PLARGE_INTEGER MaximumSize,
  455. IN ULONG Priority OPTIONAL
  456. );
  457. NTSYSCALLAPI
  458. NTSTATUS
  459. NTAPI
  460. NtFlushInstructionCache (
  461. IN HANDLE ProcessHandle,
  462. IN PVOID BaseAddress OPTIONAL,
  463. IN SIZE_T Length
  464. );
  465. //
  466. // Coherency related function prototype definitions.
  467. //
  468. NTSYSCALLAPI
  469. NTSTATUS
  470. NTAPI
  471. NtFlushWriteBuffer (
  472. VOID
  473. );
  474. #ifdef __cplusplus
  475. }
  476. #endif
  477. #endif // _NTMMAPI_