Leaked source code of windows server 2003
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.

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