xref: /reactos/sdk/include/xdk/mmfuncs.h (revision 83d74e74)
1 /******************************************************************************
2  *                       Memory manager Functions                             *
3  ******************************************************************************/
4 $if (_WDMDDK_)
5 /* Alignment Macros */
6 #define ALIGN_DOWN_BY(size, align) \
7     ((ULONG_PTR)(size) & ~((ULONG_PTR)(align) - 1))
8 
9 #define ALIGN_UP_BY(size, align) \
10     (ALIGN_DOWN_BY(((ULONG_PTR)(size) + align - 1), align))
11 
12 #define ALIGN_DOWN_POINTER_BY(ptr, align) \
13     ((PVOID)ALIGN_DOWN_BY(ptr, align))
14 
15 #define ALIGN_UP_POINTER_BY(ptr, align) \
16     ((PVOID)ALIGN_UP_BY(ptr, align))
17 
18 #define ALIGN_DOWN(size, type) \
19     ALIGN_DOWN_BY(size, sizeof(type))
20 
21 #define ALIGN_UP(size, type) \
22     ALIGN_UP_BY(size, sizeof(type))
23 
24 #define ALIGN_DOWN_POINTER(ptr, type) \
25     ALIGN_DOWN_POINTER_BY(ptr, sizeof(type))
26 
27 #define ALIGN_UP_POINTER(ptr, type) \
28     ALIGN_UP_POINTER_BY(ptr, sizeof(type))
29 
30 #ifndef FIELD_OFFSET
31 #define FIELD_OFFSET(type, field) ((ULONG)&(((type *)0)->field))
32 #endif
33 
34 #ifndef FIELD_SIZE
35 #define FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
36 #endif
37 
38 #define POOL_TAGGING                             1
39 
40 #if DBG
41 #define IF_DEBUG if (TRUE)
42 #else
43 #define IF_DEBUG if (FALSE)
44 #endif /* DBG */
45 
46 /* ULONG
47  * BYTE_OFFSET(
48  *     _In_ PVOID Va)
49  */
50 #define BYTE_OFFSET(Va) \
51   ((ULONG) ((ULONG_PTR) (Va) & (PAGE_SIZE - 1)))
52 
53 /* ULONG
54  * BYTES_TO_PAGES(
55  *     _In_ ULONG Size)
56  *
57  * Note: This needs to be like this to avoid overflows!
58  */
59 #define BYTES_TO_PAGES(Size) \
60   (((Size) >> PAGE_SHIFT) + (((Size) & (PAGE_SIZE - 1)) != 0))
61 
62 /* PVOID
63  * PAGE_ALIGN(
64  *     _In_ PVOID Va)
65  */
66 #define PAGE_ALIGN(Va) \
67   ((PVOID) ((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
68 
69 /* ULONG_PTR
70  * ROUND_TO_PAGES(
71  *     _In_ ULONG_PTR Size)
72  */
73 #define ROUND_TO_PAGES(Size) \
74   (((ULONG_PTR) (Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
75 
76 /* ULONG
77  * ADDRESS_AND_SIZE_TO_SPAN_PAGES(
78  *     _In_ PVOID Va,
79  *     _In_ ULONG Size)
80  */
81 #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size) \
82   ((ULONG) ((((ULONG_PTR) (_Va) & (PAGE_SIZE - 1)) \
83     + (_Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
84 
85 #define COMPUTE_PAGES_SPANNED(Va, Size) \
86     ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
87 
88 /*
89  * ULONG
90  * MmGetMdlByteCount(
91  *     _In_ PMDL  Mdl)
92  */
93 #define MmGetMdlByteCount(_Mdl) \
94   ((_Mdl)->ByteCount)
95 
96 /*
97  * ULONG
98  * MmGetMdlByteOffset(
99  *   IN PMDL  Mdl)
100  */
101 #define MmGetMdlByteOffset(_Mdl) \
102   ((_Mdl)->ByteOffset)
103 
104 #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
105 
106 /*
107  * PPFN_NUMBER
108  * MmGetMdlPfnArray(
109  *     _In_ PMDL  Mdl)
110  */
111 #define MmGetMdlPfnArray(_Mdl) \
112   ((PPFN_NUMBER) ((_Mdl) + 1))
113 
114 /*
115  * PVOID
116  * MmGetMdlVirtualAddress(
117  *     _In_ PMDL  Mdl)
118  */
119 #define MmGetMdlVirtualAddress(_Mdl) \
120   ((PVOID) ((PCHAR) ((_Mdl)->StartVa) + (_Mdl)->ByteOffset))
121 
122 #define MmGetProcedureAddress(Address) (Address)
123 #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
124 
125 /* PVOID MmGetSystemAddressForMdl(
126  *     _In_ PMDL Mdl);
127  */
128 #define MmGetSystemAddressForMdl(Mdl) \
129   (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
130     MDL_SOURCE_IS_NONPAGED_POOL)) ? \
131       ((Mdl)->MappedSystemVa) : \
132       (MmMapLockedPages((Mdl), KernelMode)))
133 
134 /* PVOID
135  * MmGetSystemAddressForMdlSafe(
136  *     _In_ PMDL Mdl,
137  *     _In_ MM_PAGE_PRIORITY Priority)
138  */
139 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
140   (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
141     | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
142     (_Mdl)->MappedSystemVa : \
143     (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
144       KernelMode, MmCached, NULL, FALSE, (_Priority)))
145 
146 /*
147  * VOID
148  * MmInitializeMdl(
149  *     _In_ PMDL MemoryDescriptorList,
150  *     _In_ PVOID BaseVa,
151  *     _In_ SIZE_T Length)
152  */
153 #define MmInitializeMdl(_MemoryDescriptorList, \
154                         _BaseVa, \
155                         _Length) \
156 { \
157   (_MemoryDescriptorList)->Next = (PMDL) NULL; \
158   (_MemoryDescriptorList)->Size = (CSHORT) (sizeof(MDL) + \
159     (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES(_BaseVa, _Length))); \
160   (_MemoryDescriptorList)->MdlFlags = 0; \
161   (_MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN(_BaseVa); \
162   (_MemoryDescriptorList)->ByteOffset = BYTE_OFFSET(_BaseVa); \
163   (_MemoryDescriptorList)->ByteCount = (ULONG) _Length; \
164 }
165 
166 /*
167  * VOID
168  * MmPrepareMdlForReuse(
169  *     _In_ PMDL Mdl)
170  */
171 #define MmPrepareMdlForReuse(_Mdl) \
172 { \
173   if (((_Mdl)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
174     ASSERT(((_Mdl)->MdlFlags & MDL_PARTIAL) != 0); \
175     MmUnmapLockedPages((_Mdl)->MappedSystemVa, (_Mdl)); \
176   } else if (((_Mdl)->MdlFlags & MDL_PARTIAL) == 0) { \
177     ASSERT(((_Mdl)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
178   } \
179 }
$endif(_WDMDDK_)180 $endif (_WDMDDK_)
181 $if (_NTIFS_)
182 
183 FORCEINLINE
184 ULONG
185 HEAP_MAKE_TAG_FLAGS(
186   _In_ ULONG TagBase,
187   _In_ ULONG Tag)
188 {
189   //__assume_bound(TagBase); // FIXME
190   return ((ULONG)((TagBase) + ((Tag) << HEAP_TAG_SHIFT)));
191 }
192 $endif (_NTIFS_)
193 
194 #if (NTDDI_VERSION >= NTDDI_WIN2K)
195 $if (_WDMDDK_)
196 _Must_inspect_result_
197 _IRQL_requires_max_(DISPATCH_LEVEL)
198 _When_ (return != NULL, _Post_writable_byte_size_ (NumberOfBytes))
199 NTKERNELAPI
200 PVOID
201 NTAPI
202 MmAllocateContiguousMemory(
203   _In_ SIZE_T NumberOfBytes,
204   _In_ PHYSICAL_ADDRESS HighestAcceptableAddress);
205 
206 _Must_inspect_result_
207 _IRQL_requires_max_(DISPATCH_LEVEL)
208 _When_ (return != NULL, _Post_writable_byte_size_ (NumberOfBytes))
209 NTKERNELAPI
210 PVOID
211 NTAPI
212 MmAllocateContiguousMemorySpecifyCache(
213   _In_ SIZE_T NumberOfBytes,
214   _In_ PHYSICAL_ADDRESS LowestAcceptableAddress,
215   _In_ PHYSICAL_ADDRESS HighestAcceptableAddress,
216   _In_opt_ PHYSICAL_ADDRESS BoundaryAddressMultiple,
217   _In_ MEMORY_CACHING_TYPE CacheType);
218 
219 _Must_inspect_result_
220 _IRQL_requires_max_(DISPATCH_LEVEL)
221 NTKERNELAPI
222 PMDL
223 NTAPI
224 MmAllocatePagesForMdl(
225   _In_ PHYSICAL_ADDRESS LowAddress,
226   _In_ PHYSICAL_ADDRESS HighAddress,
227   _In_ PHYSICAL_ADDRESS SkipBytes,
228   _In_ SIZE_T TotalBytes);
229 
230 _IRQL_requires_max_(DISPATCH_LEVEL)
231 NTKERNELAPI
232 VOID
233 NTAPI
234 MmBuildMdlForNonPagedPool(
235   _Inout_ PMDL MemoryDescriptorList);
236 
237 //DECLSPEC_DEPRECATED_DDK
238 NTKERNELAPI
239 PMDL
240 NTAPI
241 MmCreateMdl(
242   _Out_writes_bytes_opt_ (sizeof (MDL) + (sizeof (PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES (Base, Length)))
243     PMDL MemoryDescriptorList,
244   _In_reads_bytes_opt_ (Length) PVOID Base,
245   _In_ SIZE_T Length);
246 
247 _IRQL_requires_max_(DISPATCH_LEVEL)
248 NTKERNELAPI
249 VOID
250 NTAPI
251 MmFreeContiguousMemory(
252   _In_ PVOID BaseAddress);
253 
254 _IRQL_requires_max_ (DISPATCH_LEVEL)
255 NTKERNELAPI
256 VOID
257 NTAPI
258 MmFreeContiguousMemorySpecifyCache(
259   _In_reads_bytes_ (NumberOfBytes) PVOID BaseAddress,
260   _In_ SIZE_T NumberOfBytes,
261   _In_ MEMORY_CACHING_TYPE CacheType);
262 
263 _IRQL_requires_max_(DISPATCH_LEVEL)
264 NTKERNELAPI
265 VOID
266 NTAPI
267 MmFreePagesFromMdl(
268   _Inout_ PMDL MemoryDescriptorList);
269 
270 _IRQL_requires_max_(PASSIVE_LEVEL)
271 NTKERNELAPI
272 PVOID
273 NTAPI
274 MmGetSystemRoutineAddress(
275   _In_ PUNICODE_STRING SystemRoutineName);
276 
277 NTKERNELAPI
278 LOGICAL
279 NTAPI
280 MmIsDriverVerifying(
281   _In_ struct _DRIVER_OBJECT *DriverObject);
282 
283 _Must_inspect_result_
284 _IRQL_requires_max_(APC_LEVEL)
285 NTKERNELAPI
286 PVOID
287 NTAPI
288 MmLockPagableDataSection(
289   _In_ PVOID AddressWithinSection);
290 
291 _Must_inspect_result_
292 _IRQL_requires_max_(DISPATCH_LEVEL)
293 _Out_writes_bytes_opt_ (NumberOfBytes)
294 NTKERNELAPI
295 PVOID
296 NTAPI
297 MmMapIoSpace(
298   _In_ PHYSICAL_ADDRESS PhysicalAddress,
299   _In_ SIZE_T NumberOfBytes,
300   _In_ MEMORY_CACHING_TYPE CacheType);
301 
302 _Must_inspect_result_
303 _When_(AccessMode==KernelMode, _IRQL_requires_max_(DISPATCH_LEVEL))
304 _When_(AccessMode==UserMode, _Maybe_raises_SEH_exception_ _IRQL_requires_max_(APC_LEVEL))
305 NTKERNELAPI
306 PVOID
307 NTAPI
308 MmMapLockedPages(
309   _Inout_ PMDL MemoryDescriptorList,
310   _In_ __drv_strictType(KPROCESSOR_MODE/enum _MODE,__drv_typeConst)
311     KPROCESSOR_MODE AccessMode);
312 
313 _Post_writable_byte_size_(MemoryDescriptorList->ByteCount)
314 _When_(AccessMode==KernelMode, _IRQL_requires_max_(DISPATCH_LEVEL))
315 _When_(AccessMode==UserMode, _Maybe_raises_SEH_exception_ _IRQL_requires_max_(APC_LEVEL) _Post_notnull_)
316 _At_(MemoryDescriptorList->MappedSystemVa, _Post_writable_byte_size_(MemoryDescriptorList->ByteCount))
317 _Must_inspect_result_
318 _Success_(return != NULL)
319 NTKERNELAPI
320 PVOID
321 NTAPI
322 MmMapLockedPagesSpecifyCache(
323   _Inout_ PMDL MemoryDescriptorList,
324   _In_ __drv_strictType(KPROCESSOR_MODE/enum _MODE,__drv_typeConst) KPROCESSOR_MODE AccessMode,
325   _In_ __drv_strictTypeMatch(__drv_typeCond) MEMORY_CACHING_TYPE CacheType,
326   _In_opt_ PVOID RequestedAddress,
327   _In_ ULONG BugCheckOnFailure,
328   _In_ ULONG Priority);
329 
330 _IRQL_requires_max_(APC_LEVEL)
331 NTKERNELAPI
332 PVOID
333 NTAPI
334 MmPageEntireDriver(
335   _In_ PVOID AddressWithinSection);
336 
337 _IRQL_requires_max_(DISPATCH_LEVEL)
338 _At_(MemoryDescriptorList->StartVa + MemoryDescriptorList->ByteOffset,
339   _Field_size_bytes_opt_(MemoryDescriptorList->ByteCount))
340 NTKERNELAPI
341 VOID
342 NTAPI
343 MmProbeAndLockPages(
344   _Inout_ PMDL MemoryDescriptorList,
345   _In_ KPROCESSOR_MODE AccessMode,
346   _In_ LOCK_OPERATION Operation);
347 
348 NTKERNELAPI
349 MM_SYSTEMSIZE
350 NTAPI
351 MmQuerySystemSize(VOID);
352 
353 _IRQL_requires_max_(APC_LEVEL)
354 NTKERNELAPI
355 VOID
356 NTAPI
357 MmResetDriverPaging(
358   _In_ PVOID AddressWithinSection);
359 
360 NTKERNELAPI
361 SIZE_T
362 NTAPI
363 MmSizeOfMdl(
364   _In_reads_bytes_opt_ (Length) PVOID Base,
365   _In_ SIZE_T Length);
366 
367 _IRQL_requires_max_(DISPATCH_LEVEL)
368 NTKERNELAPI
369 VOID
370 NTAPI
371 MmUnlockPagableImageSection(
372   _In_ PVOID ImageSectionHandle);
373 
374 _IRQL_requires_max_(DISPATCH_LEVEL)
375 NTKERNELAPI
376 VOID
377 NTAPI
378 MmUnlockPages(
379   _Inout_ PMDL MemoryDescriptorList);
380 
381 _IRQL_requires_max_(DISPATCH_LEVEL)
382 NTKERNELAPI
383 VOID
384 NTAPI
385 MmUnmapIoSpace(
386   _In_reads_bytes_ (NumberOfBytes) PVOID BaseAddress,
387   _In_ SIZE_T NumberOfBytes);
388 
389 _IRQL_requires_max_ (APC_LEVEL)
390 NTKERNELAPI
391 VOID
392 NTAPI
393 MmProbeAndLockProcessPages(
394   _Inout_ PMDL MemoryDescriptorList,
395   _In_ PEPROCESS Process,
396   _In_ KPROCESSOR_MODE AccessMode,
397   _In_ LOCK_OPERATION Operation);
398 
399 _IRQL_requires_max_(DISPATCH_LEVEL)
400 NTKERNELAPI
401 VOID
402 NTAPI
403 MmUnmapLockedPages(
404   _In_ PVOID BaseAddress,
405   _Inout_ PMDL MemoryDescriptorList);
406 
407 _Must_inspect_result_
408 _IRQL_requires_max_(DISPATCH_LEVEL)
409 _When_ (return != NULL, _Post_writable_byte_size_ (NumberOfBytes))
410 NTKERNELAPI
411 PVOID
412 NTAPI
413 MmAllocateContiguousMemorySpecifyCacheNode(
414   _In_ SIZE_T NumberOfBytes,
415   _In_ PHYSICAL_ADDRESS LowestAcceptableAddress,
416   _In_ PHYSICAL_ADDRESS HighestAcceptableAddress,
417   _In_opt_ PHYSICAL_ADDRESS BoundaryAddressMultiple,
418   _In_ MEMORY_CACHING_TYPE CacheType,
419   _In_ NODE_REQUIREMENT PreferredNode);
420 $endif (_WDMDDK_)
421 $if (_NTDDK_)
422 
423 _IRQL_requires_max_ (PASSIVE_LEVEL)
424 NTKERNELAPI
425 PPHYSICAL_MEMORY_RANGE
426 NTAPI
427 MmGetPhysicalMemoryRanges(VOID);
428 
429 NTKERNELAPI
430 PHYSICAL_ADDRESS
431 NTAPI
432 MmGetPhysicalAddress(
433   _In_ PVOID BaseAddress);
434 
435 NTKERNELAPI
436 BOOLEAN
437 NTAPI
438 MmIsNonPagedSystemAddressValid(
439   _In_ PVOID VirtualAddress);
440 
441 _Must_inspect_result_
442 _IRQL_requires_max_(APC_LEVEL)
443 _Out_writes_bytes_opt_(NumberOfBytes)
444 NTKERNELAPI
445 PVOID
446 NTAPI
447 MmAllocateNonCachedMemory(
448   _In_ SIZE_T NumberOfBytes);
449 
450 _IRQL_requires_max_(APC_LEVEL)
451 NTKERNELAPI
452 VOID
453 NTAPI
454 MmFreeNonCachedMemory(
455   _In_reads_bytes_(NumberOfBytes) PVOID BaseAddress,
456   _In_ SIZE_T NumberOfBytes);
457 
458 NTKERNELAPI
459 PVOID
460 NTAPI
461 MmGetVirtualForPhysical(
462   _In_ PHYSICAL_ADDRESS PhysicalAddress);
463 
464 _Must_inspect_result_
465 _IRQL_requires_max_(APC_LEVEL)
466 NTKERNELAPI
467 NTSTATUS
468 NTAPI
469 MmMapUserAddressesToPage(
470   _In_reads_bytes_(NumberOfBytes) PVOID BaseAddress,
471   _In_ SIZE_T NumberOfBytes,
472   _In_ PVOID PageAddress);
473 
474 _Must_inspect_result_
475 _IRQL_requires_max_(APC_LEVEL)
476 _Out_writes_bytes_opt_(NumberOfBytes)
477 NTKERNELAPI
478 PVOID
479 NTAPI
480 MmMapVideoDisplay(
481   _In_ PHYSICAL_ADDRESS PhysicalAddress,
482   _In_ SIZE_T NumberOfBytes,
483   _In_ MEMORY_CACHING_TYPE CacheType);
484 
485 _Must_inspect_result_
486 _IRQL_requires_max_(APC_LEVEL)
487 NTKERNELAPI
488 NTSTATUS
489 NTAPI
490 MmMapViewInSessionSpace(
491   _In_ PVOID Section,
492   _Outptr_result_bytebuffer_(*ViewSize) PVOID *MappedBase,
493   _Inout_ PSIZE_T ViewSize);
494 
495 _Must_inspect_result_
496 _IRQL_requires_max_(APC_LEVEL)
497 NTKERNELAPI
498 NTSTATUS
499 NTAPI
500 MmMapViewInSystemSpace(
501   _In_ PVOID Section,
502   _Outptr_result_bytebuffer_(*ViewSize) PVOID *MappedBase,
503   _Inout_ PSIZE_T ViewSize);
504 
505 _IRQL_requires_max_(DISPATCH_LEVEL)
506 NTKERNELAPI
507 BOOLEAN
508 NTAPI
509 MmIsAddressValid(
510   _In_ PVOID VirtualAddress);
511 
512 NTKERNELAPI
513 BOOLEAN
514 NTAPI
515 MmIsThisAnNtAsSystem(VOID);
516 
517 _IRQL_requires_max_(APC_LEVEL)
518 NTKERNELAPI
519 VOID
520 NTAPI
521 MmLockPagableSectionByHandle(
522   _In_ PVOID ImageSectionHandle);
523 
524 _IRQL_requires_max_(APC_LEVEL)
525 NTKERNELAPI
526 NTSTATUS
527 NTAPI
528 MmUnmapViewInSessionSpace(
529   _In_ PVOID MappedBase);
530 
531 _IRQL_requires_max_(APC_LEVEL)
532 NTKERNELAPI
533 NTSTATUS
534 NTAPI
535 MmUnmapViewInSystemSpace(
536   _In_ PVOID MappedBase);
537 
538 _IRQL_requires_max_(APC_LEVEL)
539 NTKERNELAPI
540 VOID
541 NTAPI
542 MmUnsecureVirtualMemory(
543   _In_ HANDLE SecureHandle);
544 
545 _IRQL_requires_max_ (PASSIVE_LEVEL)
546 NTKERNELAPI
547 NTSTATUS
548 NTAPI
549 MmRemovePhysicalMemory(
550   _In_ PPHYSICAL_ADDRESS StartAddress,
551   _Inout_ PLARGE_INTEGER NumberOfBytes);
552 
553 _Must_inspect_result_
554 _IRQL_requires_max_(APC_LEVEL)
555 NTKERNELAPI
556 HANDLE
557 NTAPI
558 MmSecureVirtualMemory(
559   __in_data_source(USER_MODE) _In_reads_bytes_ (Size) PVOID Address,
560   _In_ __in_data_source(USER_MODE) SIZE_T Size,
561   _In_ ULONG ProbeMode);
562 
563 _IRQL_requires_max_(APC_LEVEL)
564 NTKERNELAPI
565 VOID
566 NTAPI
567 MmUnmapVideoDisplay(
568   _In_reads_bytes_(NumberOfBytes) PVOID BaseAddress,
569   _In_ SIZE_T NumberOfBytes);
570 
571 _IRQL_requires_max_ (PASSIVE_LEVEL)
572 NTKERNELAPI
573 NTSTATUS
574 NTAPI
575 MmAddPhysicalMemory(
576   _In_ PPHYSICAL_ADDRESS StartAddress,
577   _Inout_ PLARGE_INTEGER NumberOfBytes);
578 $endif (_NTDDK_)
579 $if (_NTIFS_)
580 
581 NTKERNELAPI
582 BOOLEAN
583 NTAPI
584 MmIsRecursiveIoFault(VOID);
585 
586 _IRQL_requires_max_ (APC_LEVEL)
587 NTKERNELAPI
588 BOOLEAN
589 NTAPI
590 MmForceSectionClosed(
591   _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer,
592   _In_ BOOLEAN DelayClose);
593 
594 _IRQL_requires_max_ (APC_LEVEL)
595 NTKERNELAPI
596 BOOLEAN
597 NTAPI
598 MmFlushImageSection(
599   _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer,
600   _In_ MMFLUSH_TYPE FlushType);
601 
602 _IRQL_requires_max_ (APC_LEVEL)
603 NTKERNELAPI
604 BOOLEAN
605 NTAPI
606 MmCanFileBeTruncated(
607   _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer,
608   _In_opt_ PLARGE_INTEGER NewFileSize);
609 
610 _IRQL_requires_max_ (APC_LEVEL)
611 NTKERNELAPI
612 BOOLEAN
613 NTAPI
614 MmSetAddressRangeModified(
615   _In_reads_bytes_ (Length) PVOID Address,
616   _In_ SIZE_T Length);
617 $endif (_NTIFS_)
618 
619 #endif /* (NTDDI_VERSION >= NTDDI_WIN2K) */
620 
621 $if (_WDMDDK_ || _NTIFS_)
622 #if (NTDDI_VERSION >= NTDDI_WINXP)
623 $endif (_WDMDDK_ || _NTIFS_)
624 
625 $if (_WDMDDK_)
626 _IRQL_requires_max_(DISPATCH_LEVEL)
627 NTKERNELAPI
628 NTSTATUS
629 NTAPI
630 MmAdvanceMdl(
631   _Inout_ PMDL Mdl,
632   _In_ ULONG NumberOfBytes);
633 
634 _Must_inspect_result_
635 _IRQL_requires_max_(APC_LEVEL)
636 _Ret_maybenull_
637 NTKERNELAPI
638 PVOID
639 NTAPI
640 MmAllocateMappingAddress(
641   _In_ SIZE_T NumberOfBytes,
642   _In_ ULONG PoolTag);
643 
644 _IRQL_requires_max_(APC_LEVEL)
645 NTKERNELAPI
646 VOID
647 NTAPI
648 MmFreeMappingAddress(
649   _In_ __drv_freesMem(Mem) _Post_invalid_ PVOID BaseAddress,
650   _In_ ULONG PoolTag);
651 
652 _IRQL_requires_max_ (APC_LEVEL)
653 NTKERNELAPI
654 NTSTATUS
655 NTAPI
656 MmIsVerifierEnabled(
657   _Out_ PULONG VerifierFlags);
658 
659 _Post_writable_byte_size_(MemoryDescriptorList->ByteCount)
660 _IRQL_requires_max_(DISPATCH_LEVEL)
661 _At_(MemoryDescriptorList->MappedSystemVa + MemoryDescriptorList->ByteOffset,
662   _Post_writable_byte_size_(MemoryDescriptorList->ByteCount))
663 _Must_inspect_result_
664 _Success_(return != NULL)
665 NTKERNELAPI
666 PVOID
667 NTAPI
668 MmMapLockedPagesWithReservedMapping(
669   _In_ PVOID MappingAddress,
670   _In_ ULONG PoolTag,
671   _Inout_ PMDL MemoryDescriptorList,
672   _In_ __drv_strictTypeMatch(__drv_typeCond)
673     MEMORY_CACHING_TYPE CacheType);
674 
675 _Must_inspect_result_
676 _IRQL_requires_max_(DISPATCH_LEVEL)
677 NTKERNELAPI
678 NTSTATUS
679 NTAPI
680 MmProtectMdlSystemAddress(
681   _In_ PMDL MemoryDescriptorList,
682   _In_ ULONG NewProtect);
683 
684 _IRQL_requires_max_(DISPATCH_LEVEL)
685 NTKERNELAPI
686 VOID
687 NTAPI
688 MmUnmapReservedMapping(
689   _In_ PVOID BaseAddress,
690   _In_ ULONG PoolTag,
691   _Inout_ PMDL MemoryDescriptorList);
692 
693 _IRQL_requires_max_ (APC_LEVEL)
694 NTKERNELAPI
695 NTSTATUS
696 NTAPI
697 MmAddVerifierThunks(
698   _In_reads_bytes_ (ThunkBufferSize) PVOID ThunkBuffer,
699   _In_ ULONG ThunkBufferSize);
700 $endif (_WDMDDK_)
701 $if (_NTIFS_)
702 
703 _IRQL_requires_max_ (PASSIVE_LEVEL)
704 NTKERNELAPI
705 NTSTATUS
706 NTAPI
707 MmPrefetchPages(
708   _In_ ULONG NumberOfLists,
709   _In_reads_ (NumberOfLists) PREAD_LIST *ReadLists);
710 $endif (_NTIFS_)
711 
712 $if (_WDMDDK_ || _NTIFS_)
713 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
714 $endif (_WDMDDK_ || _NTIFS_)
715 $if (_WDMDDK_ || _NTDDK_)
716 #if (NTDDI_VERSION >= NTDDI_WS03)
717 $endif (_WDMDDK_ || _NTDDK_)
718 $if (_WDMDDK_)
719 _IRQL_requires_max_ (DISPATCH_LEVEL)
720 NTKERNELAPI
721 LOGICAL
722 NTAPI
723 MmIsIoSpaceActive(
724   _In_ PHYSICAL_ADDRESS StartAddress,
725   _In_ SIZE_T NumberOfBytes);
726 $endif (_WDMDDK_)
727 
728 $if (_NTDDK_)
729 _Must_inspect_result_
730 _IRQL_requires_max_(PASSIVE_LEVEL)
731 NTKERNELAPI
732 NTSTATUS
733 NTAPI
734 MmCreateMirror(VOID);
735 $endif (_NTDDK_)
736 $if (_WDMDDK_ || _NTDDK_)
737 #endif /* (NTDDI_VERSION >= NTDDI_WS03) */
738 $endif (_WDMDDK_ || _NTDDK_)
739 $if (_WDMDDK_)
740 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
741 _Must_inspect_result_
742 _IRQL_requires_max_ (DISPATCH_LEVEL)
743 NTKERNELAPI
744 PMDL
745 NTAPI
746 MmAllocatePagesForMdlEx(
747   _In_ PHYSICAL_ADDRESS LowAddress,
748   _In_ PHYSICAL_ADDRESS HighAddress,
749   _In_ PHYSICAL_ADDRESS SkipBytes,
750   _In_ SIZE_T TotalBytes,
751   _In_ MEMORY_CACHING_TYPE CacheType,
752   _In_ ULONG Flags);
753 #endif
754 $endif (_WDMDDK_)
755 
756 #if (NTDDI_VERSION >= NTDDI_VISTA)
757 $if (_WDMDDK_)
758 _IRQL_requires_max_ (APC_LEVEL)
759 NTKERNELAPI
760 LOGICAL
761 NTAPI
762 MmIsDriverVerifyingByAddress(
763   _In_ PVOID AddressWithinSection);
764 $endif (_WDMDDK_)
765 $if (_NTDDK_)
766 _Must_inspect_result_
767 _IRQL_requires_max_(APC_LEVEL)
768 NTSTATUS
769 NTAPI
770 MmRotatePhysicalView(
771   _In_ PVOID VirtualAddress,
772   _Inout_ PSIZE_T NumberOfBytes,
773   _In_opt_ PMDLX NewMdl,
774   _In_ MM_ROTATE_DIRECTION Direction,
775   _In_ PMM_ROTATE_COPY_CALLBACK_FUNCTION CopyFunction,
776   _In_opt_ PVOID Context);
777 $endif (_NTDDK_)
778 $if (_NTIFS_)
779 
780 _IRQL_requires_max_ (APC_LEVEL)
781 NTKERNELAPI
782 ULONG
783 NTAPI
784 MmDoesFileHaveUserWritableReferences(
785   _In_ PSECTION_OBJECT_POINTERS SectionPointer);
786 
787 _Must_inspect_result_
788 _At_(*BaseAddress, __drv_allocatesMem(Mem))
789 __kernel_entry
790 NTSYSCALLAPI
791 NTSTATUS
792 NTAPI
793 NtAllocateVirtualMemory(
794     _In_ HANDLE ProcessHandle,
795     _Inout_ _Outptr_result_buffer_(*RegionSize) PVOID *BaseAddress,
796     _In_ ULONG_PTR ZeroBits,
797     _Inout_ PSIZE_T RegionSize,
798     _In_ ULONG AllocationType,
799     _In_ ULONG Protect);
800 
801 __kernel_entry
802 _IRQL_requires_max_(PASSIVE_LEVEL)
803 NTSYSCALLAPI
804 NTSTATUS
805 NTAPI
806 NtFreeVirtualMemory(
807     _In_ HANDLE ProcessHandle,
808     _Inout_ __drv_freesMem(Mem) PVOID *BaseAddress,
809     _Inout_ PSIZE_T RegionSize,
810     _In_ ULONG FreeType);
811 
812 $endif (_NTIFS_)
813 #endif /* (NTDDI_VERSION >= NTDDI_VISTA) */
814 
815