summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ntapi/src/ntmmapi.rs
blob: 7cae677aad12d6b5044fd4053d0f6f187b302b20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
use crate::winapi_local::um::winnt::PMEM_EXTENDED_PARAMETER;
use winapi::shared::basetsd::{PSIZE_T, PULONG_PTR, SIZE_T, ULONG_PTR};
use winapi::shared::ntdef::{
    BOOLEAN, HANDLE, LARGE_INTEGER, NTSTATUS, PHANDLE, PLARGE_INTEGER, POBJECT_ATTRIBUTES, PULONG,
    PUNICODE_STRING, PVOID, UCHAR, ULONG, ULONGLONG, UNICODE_STRING, USHORT,
};
use winapi::um::winnt::{
    ACCESS_MASK, PCFG_CALL_TARGET_INFO, STANDARD_RIGHTS_REQUIRED, SYNCHRONIZE,
};
ENUM!{enum MEMORY_INFORMATION_CLASS {
    MemoryBasicInformation = 0,
    MemoryWorkingSetInformation = 1,
    MemoryMappedFilenameInformation = 2,
    MemoryRegionInformation = 3,
    MemoryWorkingSetExInformation = 4,
    MemorySharedCommitInformation = 5,
    MemoryImageInformation = 6,
    MemoryRegionInformationEx = 7,
    MemoryPrivilegedBasicInformation = 8,
    MemoryEnclaveImageInformation = 9,
    MemoryBasicInformationCapped = 10,
}}
STRUCT!{struct MEMORY_WORKING_SET_BLOCK {
    Bitfields: ULONG_PTR,
}}
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
BITFIELD!{MEMORY_WORKING_SET_BLOCK Bitfields: ULONG_PTR [
    Protection set_Protection[0..5],
    ShareCount set_ShareCount[5..8],
    Shared set_Shared[8..9],
    Node set_Node[9..12],
    VirtualPage set_VirtualPage[12..64],
]}
#[cfg(target_arch = "x86")]
BITFIELD!{MEMORY_WORKING_SET_BLOCK Bitfields: ULONG_PTR [
    Protection set_Protection[0..5],
    ShareCount set_ShareCount[5..8],
    Shared set_Shared[8..9],
    Node set_Node[9..12],
    VirtualPage set_VirtualPage[12..32],
]}
pub type PMEMORY_WORKING_SET_BLOCK = *mut MEMORY_WORKING_SET_BLOCK;
STRUCT!{struct MEMORY_WORKING_SET_INFORMATION {
    NumberOfEntries: ULONG_PTR,
    WorkingSetInfo: [MEMORY_WORKING_SET_BLOCK; 1],
}}
pub type PMEMORY_WORKING_SET_INFORMATION = *mut MEMORY_WORKING_SET_INFORMATION;
STRUCT!{struct MEMORY_REGION_INFORMATION {
    AllocationBase: PVOID,
    AllocationProtect: ULONG,
    RegionType: ULONG,
    RegionSize: SIZE_T,
    CommitSize: SIZE_T,
}}
BITFIELD!{MEMORY_REGION_INFORMATION RegionType: ULONG [
    Private set_Private[0..1],
    MappedDataFile set_MappedDataFile[1..2],
    MappedImage set_MappedImage[2..3],
    MappedPageFile set_MappedPageFile[3..4],
    MappedPhysical set_MappedPhysical[4..5],
    DirectMapped set_DirectMapped[5..6],
    SoftwareEnclave set_SoftwareEnclave[6..7],
    PageSize64K set_PageSize64K[7..8],
    PlaceholderReservation set_PlaceholderReservation[8..9],
    Reserved set_Reserved[9..32],
]}
pub type PMEMORY_REGION_INFORMATION = *mut MEMORY_REGION_INFORMATION;
ENUM!{enum MEMORY_WORKING_SET_EX_LOCATION {
    MemoryLocationInvalid = 0,
    MemoryLocationResident = 1,
    MemoryLocationPagefile = 2,
    MemoryLocationReserved = 3,
}}
UNION!{union MEMORY_WORKING_SET_EX_BLOCK_u {
    Bitfields: ULONG_PTR,
    Invalid: ULONG_PTR,
}}
STRUCT!{struct MEMORY_WORKING_SET_EX_BLOCK {
    u: MEMORY_WORKING_SET_EX_BLOCK_u,
}}
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
BITFIELD!{unsafe MEMORY_WORKING_SET_EX_BLOCK_u Bitfields: ULONG_PTR [
    Valid set_Valid[0..1],
    ShareCount set_ShareCount[1..4],
    Win32Protection set_Win32Protection[4..15],
    Shared set_Shared[15..16],
    Node set_Node[16..22],
    Locked set_Locked[22..23],
    LargePage set_LargePage[23..24],
    Priority set_Priority[24..27],
    Reserved set_Reserved[27..30],
    SharedOriginal set_SharedOriginal[30..31],
    Bad set_Bad[31..32],
    ReservedUlong set_ReservedUlong[32..64],
]}
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
BITFIELD!{unsafe MEMORY_WORKING_SET_EX_BLOCK_u Invalid: ULONG_PTR [
    Invalid_Valid set_Invalid_Valid[0..1],
    Invalid_Reserved0 set_Invalid_Reserved0[1..15],
    Invalid_Shared set_Invalid_Shared[15..16],
    Invalid_Reserved1 set_Invalid_Reserved1[16..21],
    Invalid_PageTable set_Invalid_PageTable[21..22],
    Invalid_Location set_Invalid_Location[22..24],
    Invalid_Priority set_Invalid_Priority[24..27],
    Invalid_ModifiedList set_Invalid_ModifiedList[27..28],
    Invalid_Reserved2 set_Invalid_Reserved2[28..30],
    Invalid_SharedOriginal set_Invalid_SharedOriginal[30..31],
    Invalid_Bad set_Invalid_Bad[31..32],
    Invalid_ReservedUlong set_Invalid_ReservedUlong[32..64],
]}
#[cfg(target_arch = "x86")]
BITFIELD!{unsafe MEMORY_WORKING_SET_EX_BLOCK_u Bitfields: ULONG_PTR [
    Valid set_Valid[0..1],
    ShareCount set_ShareCount[1..4],
    Win32Protection set_Win32Protection[4..15],
    Shared set_Shared[15..16],
    Node set_Node[16..22],
    Locked set_Locked[22..23],
    LargePage set_LargePage[23..24],
    Priority set_Priority[24..27],
    Reserved set_Reserved[27..30],
    SharedOriginal set_SharedOriginal[30..31],
    Bad set_Bad[31..32],
]}
#[cfg(target_arch = "x86")]
BITFIELD!{unsafe MEMORY_WORKING_SET_EX_BLOCK_u Invalid: ULONG_PTR [
    Invalid_Valid set_Invalid_Valid[0..1],
    Invalid_Reserved0 set_Invalid_Reserved0[1..15],
    Invalid_Shared set_Invalid_Shared[15..16],
    Invalid_Reserved1 set_Invalid_Reserved1[16..21],
    Invalid_PageTable set_Invalid_PageTable[21..22],
    Invalid_Location set_Invalid_Location[22..24],
    Invalid_Priority set_Invalid_Priority[24..27],
    Invalid_ModifiedList set_Invalid_ModifiedList[27..28],
    Invalid_Reserved2 set_Invalid_Reserved2[28..30],
    Invalid_SharedOriginal set_Invalid_SharedOriginal[30..31],
    Invalid_Bad set_Invalid_Bad[31..32],
]}
pub type PMEMORY_WORKING_SET_EX_BLOCK = *mut MEMORY_WORKING_SET_EX_BLOCK;
STRUCT!{struct MEMORY_WORKING_SET_EX_INFORMATION {
    VirtualAddress: PVOID,
    VirtualAttributes: MEMORY_WORKING_SET_EX_BLOCK,
}}
pub type PMEMORY_WORKING_SET_EX_INFORMATION = *mut MEMORY_WORKING_SET_EX_INFORMATION;
STRUCT!{struct MEMORY_SHARED_COMMIT_INFORMATION {
    CommitSize: SIZE_T,
}}
pub type PMEMORY_SHARED_COMMIT_INFORMATION = *mut MEMORY_SHARED_COMMIT_INFORMATION;
STRUCT!{struct MEMORY_IMAGE_INFORMATION {
    ImageBase: PVOID,
    SizeOfImage: SIZE_T,
    ImageFlags: ULONG,
}}
BITFIELD!{MEMORY_IMAGE_INFORMATION ImageFlags: ULONG [
    ImagePartialMap set_ImagePartialMap[0..1],
    ImageNotExecutable set_ImageNotExecutable[1..2],
    ImageSigningLevel set_ImageSigningLevel[2..6],
    Reserved set_Reserved[6..32],
]}
pub type PMEMORY_IMAGE_INFORMATION = *mut MEMORY_IMAGE_INFORMATION;
STRUCT!{struct MEMORY_ENCLAVE_IMAGE_INFORMATION {
    ImageInfo: MEMORY_IMAGE_INFORMATION,
    UniqueID: [UCHAR; 32],
    AuthorID: [UCHAR; 32],
}}
pub type PMEMORY_ENCLAVE_IMAGE_INFORMATION = *mut MEMORY_ENCLAVE_IMAGE_INFORMATION;
pub const MMPFNLIST_ZERO: u32 = 0;
pub const MMPFNLIST_FREE: u32 = 1;
pub const MMPFNLIST_STANDBY: u32 = 2;
pub const MMPFNLIST_MODIFIED: u32 = 3;
pub const MMPFNLIST_MODIFIEDNOWRITE: u32 = 4;
pub const MMPFNLIST_BAD: u32 = 5;
pub const MMPFNLIST_ACTIVE: u32 = 6;
pub const MMPFNLIST_TRANSITION: u32 = 7;
pub const MMPFNUSE_PROCESSPRIVATE: u32 = 0;
pub const MMPFNUSE_FILE: u32 = 1;
pub const MMPFNUSE_PAGEFILEMAPPED: u32 = 2;
pub const MMPFNUSE_PAGETABLE: u32 = 3;
pub const MMPFNUSE_PAGEDPOOL: u32 = 4;
pub const MMPFNUSE_NONPAGEDPOOL: u32 = 5;
pub const MMPFNUSE_SYSTEMPTE: u32 = 6;
pub const MMPFNUSE_SESSIONPRIVATE: u32 = 7;
pub const MMPFNUSE_METAFILE: u32 = 8;
pub const MMPFNUSE_AWEPAGE: u32 = 9;
pub const MMPFNUSE_DRIVERLOCKPAGE: u32 = 10;
pub const MMPFNUSE_KERNELSTACK: u32 = 11;
STRUCT!{struct MEMORY_FRAME_INFORMATION {
    Bitfields: ULONGLONG,
}}
BITFIELD!{MEMORY_FRAME_INFORMATION Bitfields: ULONGLONG [
    UseDescription set_UseDescription[0..4],
    ListDescription set_ListDescription[4..7],
    Reserved0 set_Reserved0[7..8],
    Pinned set_Pinned[8..9],
    DontUse set_DontUse[9..57],
    Priority set_Priority[57..60],
    Reserved set_Reserved[60..64],
]}
STRUCT!{struct FILEOFFSET_INFORMATION {
    Bitfields: ULONGLONG,
}}
BITFIELD!{FILEOFFSET_INFORMATION Bitfields: ULONGLONG [
    DontUse set_DontUse[0..9],
    Offset set_Offset[9..57],
    Reserved set_Reserved[57..64],
]}
STRUCT!{struct PAGEDIR_INFORMATION {
    Bitfields: ULONGLONG,
}}
BITFIELD!{PAGEDIR_INFORMATION Bitfields: ULONGLONG [
    DontUse set_DontUse[0..9],
    PageDirectoryBase set_PageDirectoryBase[9..57],
    Reserved set_Reserved[57..64],
]}
STRUCT!{struct UNIQUE_PROCESS_INFORMATION {
    Bitfields: ULONGLONG,
}}
BITFIELD!{UNIQUE_PROCESS_INFORMATION Bitfields: ULONGLONG [
    DontUse set_DontUse[0..9],
    UniqueProcessKey set_UniqueProcessKey[9..57],
    Reserved set_Reserved[57..64],
]}
pub type PUNIQUE_PROCESS_INFORMATION = *mut UNIQUE_PROCESS_INFORMATION;
UNION!{union MMPFN_IDENTITY_u1 {
    e1: MEMORY_FRAME_INFORMATION,
    e2: FILEOFFSET_INFORMATION,
    e3: PAGEDIR_INFORMATION,
    e4: UNIQUE_PROCESS_INFORMATION,
}}
UNION!{union MMPFN_IDENTITY_u2 {
    e1: ULONG_PTR,
    e2_CombinedPage: ULONG_PTR,
    FileObject: ULONG_PTR,
    UniqueFileObjectKey: ULONG_PTR,
    ProtoPteAddress: ULONG_PTR,
    VirtualAddress: ULONG_PTR,
}}
STRUCT!{struct MMPFN_IDENTITY {
    u1: MMPFN_IDENTITY_u1,
    PageFrameIndex: ULONG_PTR,
    u2: MMPFN_IDENTITY_u2,
}}
BITFIELD!{unsafe MMPFN_IDENTITY_u2 e1: ULONG_PTR [
    Image set_Image[0..1],
    Mismatch set_Mismatch[1..2],
]}
pub type PMMPFN_IDENTITY = *mut MMPFN_IDENTITY;
STRUCT!{struct MMPFN_MEMSNAP_INFORMATION {
    InitialPageFrameIndex: ULONG_PTR,
    Count: ULONG_PTR,
}}
pub type PMMPFN_MEMSNAP_INFORMATION = *mut MMPFN_MEMSNAP_INFORMATION;
ENUM!{enum SECTION_INFORMATION_CLASS {
    SectionBasicInformation = 0,
    SectionImageInformation = 1,
    SectionRelocationInformation = 2,
    SectionOriginalBaseInformation = 3,
    SectionInternalImageInformation = 4,
    MaxSectionInfoClass = 5,
}}
STRUCT!{struct SECTION_BASIC_INFORMATION {
    BaseAddress: PVOID,
    AllocationAttributes: ULONG,
    MaximumSize: LARGE_INTEGER,
}}
pub type PSECTION_BASIC_INFORMATION = *mut SECTION_BASIC_INFORMATION;
STRUCT!{struct SECTION_IMAGE_INFORMATION_u1_s {
    SubSystemMinorVersion: USHORT,
    SubSystemMajorVersion: USHORT,
}}
UNION!{union SECTION_IMAGE_INFORMATION_u1 {
    s: SECTION_IMAGE_INFORMATION_u1_s,
    SubSystemVersion: ULONG,
}}
STRUCT!{struct SECTION_IMAGE_INFORMATION_u2_s {
    MajorOperatingSystemVersion: USHORT,
    MinorOperatingSystemVersion: USHORT,
}}
UNION!{union SECTION_IMAGE_INFORMATION_u2 {
    s: SECTION_IMAGE_INFORMATION_u2_s,
    OperatingSystemVersion: ULONG,
}}
STRUCT!{struct SECTION_IMAGE_INFORMATION {
    TransferAddress: PVOID,
    ZeroBits: ULONG,
    MaximumStackSize: SIZE_T,
    CommittedStackSize: SIZE_T,
    SubSystemType: ULONG,
    u1: SECTION_IMAGE_INFORMATION_u1,
    u2: SECTION_IMAGE_INFORMATION_u2,
    ImageCharacteristics: USHORT,
    DllCharacteristics: USHORT,
    Machine: USHORT,
    ImageContainsCode: BOOLEAN,
    ImageFlags: UCHAR,
    LoaderFlags: ULONG,
    ImageFileSize: ULONG,
    CheckSum: ULONG,
}}
BITFIELD!{SECTION_IMAGE_INFORMATION ImageFlags: UCHAR [
    ComPlusNativeReady set_ComPlusNativeReady[0..1],
    ComPlusILOnly set_ComPlusILOnly[1..2],
    ImageDynamicallyRelocated set_ImageDynamicallyRelocated[2..3],
    ImageMappedFlat set_ImageMappedFlat[3..4],
    BaseBelow4gb set_BaseBelow4gb[4..5],
    ComPlusPrefer32bit set_ComPlusPrefer32bit[5..6],
    Reserved set_Reserved[6..8],
]}
pub type PSECTION_IMAGE_INFORMATION = *mut SECTION_IMAGE_INFORMATION;
STRUCT!{struct SECTION_INTERNAL_IMAGE_INFORMATION {
    SectionInformation: SECTION_IMAGE_INFORMATION,
    ExtendedFlags: ULONG,
}}
BITFIELD!{SECTION_INTERNAL_IMAGE_INFORMATION ExtendedFlags: ULONG [
    ImageExportSuppressionEnabled set_ImageExportSuppressionEnabled[0..1],
    Reserved set_Reserved[1..32],
]}
pub type PSECTION_INTERNAL_IMAGE_INFORMATION = *mut SECTION_INTERNAL_IMAGE_INFORMATION;
ENUM!{enum SECTION_INHERIT {
    ViewShare = 1,
    ViewUnmap = 2,
}}
pub const SEC_BASED: u32 = 0x200000;
pub const SEC_NO_CHANGE: u32 = 0x400000;
pub const SEC_GLOBAL: u32 = 0x20000000;
pub const MEM_EXECUTE_OPTION_DISABLE: u32 = 0x1;
pub const MEM_EXECUTE_OPTION_ENABLE: u32 = 0x2;
pub const MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION: u32 = 0x4;
pub const MEM_EXECUTE_OPTION_PERMANENT: u32 = 0x8;
pub const MEM_EXECUTE_OPTION_EXECUTE_DISPATCH_ENABLE: u32 = 0x10;
pub const MEM_EXECUTE_OPTION_IMAGE_DISPATCH_ENABLE: u32 = 0x20;
pub const MEM_EXECUTE_OPTION_VALID_FLAGS: u32 = 0x3f;
EXTERN!{extern "system" {
    fn NtAllocateVirtualMemory(
        ProcessHandle: HANDLE,
        BaseAddress: *mut PVOID,
        ZeroBits: ULONG_PTR,
        RegionSize: PSIZE_T,
        AllocationType: ULONG,
        Protect: ULONG,
    ) -> NTSTATUS;
    fn NtFreeVirtualMemory(
        ProcessHandle: HANDLE,
        BaseAddress: *mut PVOID,
        RegionSize: PSIZE_T,
        FreeType: ULONG,
    ) -> NTSTATUS;
    fn NtReadVirtualMemory(
        ProcessHandle: HANDLE,
        BaseAddress: PVOID,
        Buffer: PVOID,
        BufferSize: SIZE_T,
        NumberOfBytesRead: PSIZE_T,
    ) -> NTSTATUS;
    fn NtWriteVirtualMemory(
        ProcessHandle: HANDLE,
        BaseAddress: PVOID,
        Buffer: PVOID,
        BufferSize: SIZE_T,
        NumberOfBytesWritten: PSIZE_T,
    ) -> NTSTATUS;
    fn NtProtectVirtualMemory(
        ProcessHandle: HANDLE,
        BaseAddress: *mut PVOID,
        RegionSize: PSIZE_T,
        NewProtect: ULONG,
        OldProtect: PULONG,
    ) -> NTSTATUS;
    fn NtQueryVirtualMemory(
        ProcessHandle: HANDLE,
        BaseAddress: PVOID,
        MemoryInformationClass: MEMORY_INFORMATION_CLASS,
        MemoryInformation: PVOID,
        MemoryInformationLength: SIZE_T,
        ReturnLength: PSIZE_T,
    ) -> NTSTATUS;
}}
ENUM!{enum VIRTUAL_MEMORY_INFORMATION_CLASS {
    VmPrefetchInformation = 0,
    VmPagePriorityInformation = 1,
    VmCfgCallTargetInformation = 2,
    VmPageDirtyStateInformation = 3,
}}
STRUCT!{struct MEMORY_RANGE_ENTRY {
    VirtualAddress: PVOID,
    NumberOfBytes: SIZE_T,
}}
pub type PMEMORY_RANGE_ENTRY = *mut MEMORY_RANGE_ENTRY;
STRUCT!{struct CFG_CALL_TARGET_LIST_INFORMATION {
    NumberOfEntries: ULONG,
    Reserved: ULONG,
    NumberOfEntriesProcessed: PULONG,
    CallTargetInfo: PCFG_CALL_TARGET_INFO,
    Section: PVOID,
    FileOffset: ULONGLONG,
}}
pub type PCFG_CALL_TARGET_LIST_INFORMATION = *mut CFG_CALL_TARGET_LIST_INFORMATION;
EXTERN!{extern "system" {
    fn NtSetInformationVirtualMemory(
        ProcessHandle: HANDLE,
        VmInformationClass: VIRTUAL_MEMORY_INFORMATION_CLASS,
        NumberOfEntries: ULONG_PTR,
        VirtualAddresses: PMEMORY_RANGE_ENTRY,
        VmInformation: PVOID,
        VmInformationLength: ULONG,
    ) -> NTSTATUS;
    fn NtLockVirtualMemory(
        ProcessHandle: HANDLE,
        BaseAddress: *mut PVOID,
        RegionSize: PSIZE_T,
        MapType: ULONG,
    ) -> NTSTATUS;
    fn NtUnlockVirtualMemory(
        ProcessHandle: HANDLE,
        BaseAddress: *mut PVOID,
        RegionSize: PSIZE_T,
        MapType: ULONG,
    ) -> NTSTATUS;
    fn NtCreateSection(
        SectionHandle: PHANDLE,
        DesiredAccess: ACCESS_MASK,
        ObjectAttributes: POBJECT_ATTRIBUTES,
        MaximumSize: PLARGE_INTEGER,
        SectionPageProtection: ULONG,
        AllocationAttributes: ULONG,
        FileHandle: HANDLE,
    ) -> NTSTATUS;
    fn NtCreateSectionEx(
        SectionHandle: PHANDLE,
        DesiredAccess: ACCESS_MASK,
        ObjectAttributes: POBJECT_ATTRIBUTES,
        MaximumSize: PLARGE_INTEGER,
        SectionPageProtection: ULONG,
        AllocationAttributes: ULONG,
        FileHandle: HANDLE,
        ExtendedParameters: PMEM_EXTENDED_PARAMETER,
        ExtendedParameterCount: ULONG,
    ) -> NTSTATUS;
    fn NtOpenSection(
        SectionHandle: PHANDLE,
        DesiredAccess: ACCESS_MASK,
        ObjectAttributes: POBJECT_ATTRIBUTES,
    ) -> NTSTATUS;
    fn NtMapViewOfSection(
        SectionHandle: HANDLE,
        ProcessHandle: HANDLE,
        BaseAddress: *mut PVOID,
        ZeroBits: ULONG_PTR,
        CommitSize: SIZE_T,
        SectionOffset: PLARGE_INTEGER,
        ViewSize: PSIZE_T,
        InheritDisposition: SECTION_INHERIT,
        AllocationType: ULONG,
        Win32Protect: ULONG,
    ) -> NTSTATUS;
    fn NtUnmapViewOfSection(
        ProcessHandle: HANDLE,
        BaseAddress: PVOID,
    ) -> NTSTATUS;
    fn NtUnmapViewOfSectionEx(
        ProcessHandle: HANDLE,
        BaseAddress: PVOID,
        Flags: ULONG,
    ) -> NTSTATUS;
    fn NtExtendSection(
        SectionHandle: HANDLE,
        NewSectionSize: PLARGE_INTEGER,
    ) -> NTSTATUS;
    fn NtQuerySection(
        SectionHandle: HANDLE,
        SectionInformationClass: SECTION_INFORMATION_CLASS,
        SectionInformation: PVOID,
        SectionInformationLength: SIZE_T,
        ReturnLength: PSIZE_T,
    ) -> NTSTATUS;
    fn NtAreMappedFilesTheSame(
        File1MappedAsAnImage: PVOID,
        File2MappedAsFile: PVOID,
    ) -> NTSTATUS;
}}
pub const MEMORY_PARTITION_QUERY_ACCESS: u32 = 0x0001;
pub const MEMORY_PARTITION_MODIFY_ACCESS: u32 = 0x0002;
pub const MEMORY_PARTITION_ALL_ACCESS: u32 = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE
    | MEMORY_PARTITION_QUERY_ACCESS | MEMORY_PARTITION_MODIFY_ACCESS;
ENUM!{enum MEMORY_PARTITION_INFORMATION_CLASS {
    SystemMemoryPartitionInformation = 0,
    SystemMemoryPartitionMoveMemory = 1,
    SystemMemoryPartitionAddPagefile = 2,
    SystemMemoryPartitionCombineMemory = 3,
    SystemMemoryPartitionInitialAddMemory = 4,
    SystemMemoryPartitionGetMemoryEvents = 5,
    SystemMemoryPartitionMax = 6,
}}
STRUCT!{struct MEMORY_PARTITION_CONFIGURATION_INFORMATION {
    Flags: ULONG,
    NumaNode: ULONG,
    Channel: ULONG,
    NumberOfNumaNodes: ULONG,
    ResidentAvailablePages: ULONG_PTR,
    CommittedPages: ULONG_PTR,
    CommitLimit: ULONG_PTR,
    PeakCommitment: ULONG_PTR,
    TotalNumberOfPages: ULONG_PTR,
    AvailablePages: ULONG_PTR,
    ZeroPages: ULONG_PTR,
    FreePages: ULONG_PTR,
    StandbyPages: ULONG_PTR,
    StandbyPageCountByPriority: [ULONG_PTR; 8],
    RepurposedPagesByPriority: [ULONG_PTR; 8],
    MaximumCommitLimit: ULONG_PTR,
    DonatedPagesToPartitions: ULONG_PTR,
    PartitionId: ULONG,
}}
pub type PMEMORY_PARTITION_CONFIGURATION_INFORMATION =
    *mut MEMORY_PARTITION_CONFIGURATION_INFORMATION;
STRUCT!{struct MEMORY_PARTITION_TRANSFER_INFORMATION {
    NumberOfPages: ULONG_PTR,
    NumaNode: ULONG,
    Flags: ULONG,
}}
pub type PMEMORY_PARTITION_TRANSFER_INFORMATION = *mut MEMORY_PARTITION_TRANSFER_INFORMATION;
STRUCT!{struct MEMORY_PARTITION_PAGEFILE_INFORMATION {
    PageFileName: UNICODE_STRING,
    MinimumSize: LARGE_INTEGER,
    MaximumSize: LARGE_INTEGER,
    Flags: ULONG,
}}
pub type PMEMORY_PARTITION_PAGEFILE_INFORMATION = *mut MEMORY_PARTITION_PAGEFILE_INFORMATION;
STRUCT!{struct MEMORY_PARTITION_PAGE_COMBINE_INFORMATION {
    StopHandle: HANDLE,
    Flags: ULONG,
    TotalNumberOfPages: ULONG_PTR,
}}
pub type PMEMORY_PARTITION_PAGE_COMBINE_INFORMATION =
    *mut MEMORY_PARTITION_PAGE_COMBINE_INFORMATION;
STRUCT!{struct MEMORY_PARTITION_PAGE_RANGE {
    StartPage: ULONG_PTR,
    NumberOfPages: ULONG_PTR,
}}
pub type PMEMORY_PARTITION_PAGE_RANGE = *mut MEMORY_PARTITION_PAGE_RANGE;
STRUCT!{struct MEMORY_PARTITION_INITIAL_ADD_INFORMATION {
    Flags: ULONG,
    NumberOfRanges: ULONG,
    NumberOfPagesAdded: ULONG_PTR,
    PartitionRanges: [MEMORY_PARTITION_PAGE_RANGE; 1],
}}
pub type PMEMORY_PARTITION_INITIAL_ADD_INFORMATION = *mut MEMORY_PARTITION_INITIAL_ADD_INFORMATION;
STRUCT!{struct MEMORY_PARTITION_MEMORY_EVENTS_INFORMATION {
    Flags: ULONG,
    HandleAttributes: ULONG,
    DesiredAccess: ULONG,
    LowCommitCondition: HANDLE,
    HighCommitCondition: HANDLE,
    MaximumCommitCondition: HANDLE,
}}
BITFIELD!{MEMORY_PARTITION_MEMORY_EVENTS_INFORMATION Flags: ULONG [
    CommitEvents set_CommitEvents[0..1],
    Spare set_Spare[1..32],
]}
pub type PMEMORY_PARTITION_MEMORY_EVENTS_INFORMATION =
    *mut MEMORY_PARTITION_MEMORY_EVENTS_INFORMATION;
EXTERN!{extern "system" {
    fn NtCreatePartition(
        PartitionHandle: PHANDLE,
        DesiredAccess: ACCESS_MASK,
        ObjectAttributes: POBJECT_ATTRIBUTES,
        PreferredNode: ULONG,
    ) -> NTSTATUS;
    fn NtOpenPartition(
        PartitionHandle: PHANDLE,
        DesiredAccess: ACCESS_MASK,
        ObjectAttributes: POBJECT_ATTRIBUTES,
    ) -> NTSTATUS;
    fn NtManagePartition(
        PartitionInformationClass: MEMORY_PARTITION_INFORMATION_CLASS,
        PartitionInformation: PVOID,
        PartitionInformationLength: ULONG,
    ) -> NTSTATUS;
    fn NtMapUserPhysicalPages(
        VirtualAddress: PVOID,
        NumberOfPages: ULONG_PTR,
        UserPfnArray: PULONG_PTR,
    ) -> NTSTATUS;
    fn NtMapUserPhysicalPagesScatter(
        VirtualAddresses: *mut PVOID,
        NumberOfPages: ULONG_PTR,
        UserPfnArray: PULONG_PTR,
    ) -> NTSTATUS;
    fn NtAllocateUserPhysicalPages(
        ProcessHandle: HANDLE,
        NumberOfPages: PULONG_PTR,
        UserPfnArray: PULONG_PTR,
    ) -> NTSTATUS;
    fn NtFreeUserPhysicalPages(
        ProcessHandle: HANDLE,
        NumberOfPages: PULONG_PTR,
        UserPfnArray: PULONG_PTR,
    ) -> NTSTATUS;
    fn NtOpenSession(
        SessionHandle: PHANDLE,
        DesiredAccess: ACCESS_MASK,
        ObjectAttributes: POBJECT_ATTRIBUTES,
    ) -> NTSTATUS;
    fn NtGetWriteWatch(
        ProcessHandle: HANDLE,
        Flags: ULONG,
        BaseAddress: PVOID,
        RegionSize: SIZE_T,
        UserAddressArray: *mut PVOID,
        EntriesInUserAddressArray: PULONG_PTR,
        Granularity: PULONG,
    ) -> NTSTATUS;
    fn NtResetWriteWatch(
        ProcessHandle: HANDLE,
        BaseAddress: PVOID,
        RegionSize: SIZE_T,
    ) -> NTSTATUS;
    fn NtCreatePagingFile(
        PageFileName: PUNICODE_STRING,
        MinimumSize: PLARGE_INTEGER,
        MaximumSize: PLARGE_INTEGER,
        Priority: ULONG,
    ) -> NTSTATUS;
    fn NtFlushInstructionCache(
        ProcessHandle: HANDLE,
        BaseAddress: PVOID,
        Length: SIZE_T,
    ) -> NTSTATUS;
    fn NtFlushWriteBuffer() -> NTSTATUS;
}}