6#define ALIGN_DOWN_BY(size, align) \
7 ((ULONG_PTR)(size) & ~((ULONG_PTR)(align) - 1))
9#define ALIGN_UP_BY(size, align) \
10 (ALIGN_DOWN_BY(((ULONG_PTR)(size) + align - 1), align))
12#define ALIGN_DOWN_POINTER_BY(ptr, align) \
13 ((PVOID)ALIGN_DOWN_BY(ptr, align))
15#define ALIGN_UP_POINTER_BY(ptr, align) \
16 ((PVOID)ALIGN_UP_BY(ptr, align))
18#define ALIGN_DOWN(size, type) \
19 ALIGN_DOWN_BY(size, sizeof(type))
21#define ALIGN_UP(size, type) \
22 ALIGN_UP_BY(size, sizeof(type))
24#define ALIGN_DOWN_POINTER(ptr, type) \
25 ALIGN_DOWN_POINTER_BY(ptr, sizeof(type))
27#define ALIGN_UP_POINTER(ptr, type) \
28 ALIGN_UP_POINTER_BY(ptr, sizeof(type))
31#define FIELD_OFFSET(type, field) ((ULONG)&(((type *)0)->field))
35#define FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
41#define IF_DEBUG if (TRUE)
43#define IF_DEBUG if (FALSE)
50#define BYTE_OFFSET(Va) \
51 ((ULONG) ((ULONG_PTR) (Va) & (PAGE_SIZE - 1)))
59#define BYTES_TO_PAGES(Size) \
60 (((Size) >> PAGE_SHIFT) + (((Size) & (PAGE_SIZE - 1)) != 0))
66#define PAGE_ALIGN(Va) \
67 ((PVOID) ((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
73#define ROUND_TO_PAGES(Size) \
74 (((ULONG_PTR) (Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
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))
85#define COMPUTE_PAGES_SPANNED(Va, Size) \
86 ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
93#define MmGetMdlByteCount(_Mdl) \
101#define MmGetMdlByteOffset(_Mdl) \
104#define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
111#define MmGetMdlPfnArray(_Mdl) \
112 ((PPFN_NUMBER) ((_Mdl) + 1))
119#define MmGetMdlVirtualAddress(_Mdl) \
120 ((PVOID) ((PCHAR) ((_Mdl)->StartVa) + (_Mdl)->ByteOffset))
122#define MmGetProcedureAddress(Address) (Address)
123#define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
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)))
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)))
153#define MmInitializeMdl(_MemoryDescriptorList, \
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; \
171#define MmPrepareMdlForReuse(_Mdl) \
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); \
194#if (NTDDI_VERSION >= NTDDI_WIN2K)
288MmLockPagableDataSection(
371MmUnlockPagableImageSection(
393MmProbeAndLockProcessPages(
413MmAllocateContiguousMemorySpecifyCacheNode(
521MmLockPagableSectionByHandle(
622#if (NTDDI_VERSION >= NTDDI_WINXP)
640MmAllocateMappingAddress(
716#if (NTDDI_VERSION >= NTDDI_WS03)
740#if (NTDDI_VERSION >= NTDDI_WS03SP1)
756#if (NTDDI_VERSION >= NTDDI_VISTA)
762MmIsDriverVerifyingByAddress(
NTSTATUS NTAPI MmUnmapViewInSystemSpace(IN PVOID MappedBase)
BOOLEAN NTAPI MmForceSectionClosed(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN BOOLEAN DelayClose)
ULONG NTAPI MmDoesFileHaveUserWritableReferences(IN PSECTION_OBJECT_POINTERS SectionPointer)
NTSTATUS NTAPI MmUnmapViewInSessionSpace(IN PVOID MappedBase)
NTSTATUS NTAPI MmMapViewInSessionSpace(IN PVOID Section, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
PVOID NTAPI MmAllocateContiguousMemorySpecifyCache(IN SIZE_T NumberOfBytes, IN PHYSICAL_ADDRESS LowestAcceptableAddress OPTIONAL, IN PHYSICAL_ADDRESS HighestAcceptableAddress, IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL, IN MEMORY_CACHING_TYPE CacheType OPTIONAL)
VOID NTAPI MmFreeContiguousMemorySpecifyCache(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
PVOID NTAPI MmAllocateContiguousMemory(IN SIZE_T NumberOfBytes, IN PHYSICAL_ADDRESS HighestAcceptableAddress)
VOID NTAPI MmFreeContiguousMemory(IN PVOID BaseAddress)
#define __drv_strictType(typename, mode)
#define __drv_freesMem(kind)
#define _IRQL_requires_max_(irql)
#define __drv_allocatesMem(kind)
#define __drv_strictTypeMatch(mode)
NTSTATUS NTAPI MmAddVerifierThunks(IN PVOID ThunkBuffer, IN ULONG ThunkBufferSize)
NTSTATUS NTAPI MmIsVerifierEnabled(OUT PULONG VerifierFlags)
PPHYSICAL_MEMORY_RANGE NTAPI MmGetPhysicalMemoryRanges(VOID)
NTSTATUS NTAPI MmAddPhysicalMemory(IN PPHYSICAL_ADDRESS StartAddress, IN OUT PLARGE_INTEGER NumberOfBytes)
NTSTATUS NTAPI MmRemovePhysicalMemory(IN PPHYSICAL_ADDRESS StartAddress, IN OUT PLARGE_INTEGER NumberOfBytes)
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
PVOID NTAPI MmMapVideoDisplay(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
LOGICAL NTAPI MmIsIoSpaceActive(IN PHYSICAL_ADDRESS StartAddress, IN SIZE_T NumberOfBytes)
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
VOID NTAPI MmUnmapVideoDisplay(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
PVOID NTAPI MmMapLockedPagesWithReservedMapping(_In_ PVOID MappingAddress, _In_ ULONG PoolTag, _In_ PMDL Mdl, _In_ MEMORY_CACHING_TYPE CacheType)
PVOID NTAPI MmMapLockedPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode)
VOID NTAPI MmFreePagesFromMdl(IN PMDL Mdl)
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
VOID NTAPI MmUnmapReservedMapping(_In_ PVOID BaseAddress, _In_ ULONG PoolTag, _In_ PMDL Mdl)
PMDL NTAPI MmAllocatePagesForMdlEx(IN PHYSICAL_ADDRESS LowAddress, IN PHYSICAL_ADDRESS HighAddress, IN PHYSICAL_ADDRESS SkipBytes, IN SIZE_T TotalBytes, IN MEMORY_CACHING_TYPE CacheType, IN ULONG Flags)
NTSTATUS NTAPI MmPrefetchPages(IN ULONG NumberOfLists, IN PREAD_LIST *ReadLists)
PMDL NTAPI MmAllocatePagesForMdl(IN PHYSICAL_ADDRESS LowAddress, IN PHYSICAL_ADDRESS HighAddress, IN PHYSICAL_ADDRESS SkipBytes, IN SIZE_T TotalBytes)
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
PVOID NTAPI MmMapLockedPagesSpecifyCache(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN MEMORY_CACHING_TYPE CacheType, IN PVOID BaseAddress, IN ULONG BugCheckOnFailure, IN ULONG Priority)
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
NTSTATUS NTAPI MmProtectMdlSystemAddress(IN PMDL MemoryDescriptorList, IN ULONG NewProtect)
NTSTATUS NTAPI MmAdvanceMdl(IN PMDL Mdl, IN ULONG NumberOfBytes)
NTSTATUS NTAPI MmMapUserAddressesToPage(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes, IN PVOID PageAddress)
NTSTATUS NTAPI MmCreateMirror(VOID)
BOOLEAN NTAPI MmSetAddressRangeModified(IN PVOID Address, IN SIZE_T Length)
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
BOOLEAN NTAPI MmIsRecursiveIoFault(VOID)
VOID NTAPI MmFreeNonCachedMemory(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
PVOID NTAPI MmAllocateNonCachedMemory(IN SIZE_T NumberOfBytes)
_In_ HANDLE ProcessHandle
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR ZeroBits
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG AllocationType
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
__kernel_entry _Inout_ _Inout_ PSIZE_T RegionSize
__kernel_entry _Inout_ _Inout_ PSIZE_T _In_ ULONG FreeType
#define _In_reads_bytes_(s)
#define _Outptr_result_bytebuffer_(s)
#define _Field_size_bytes_opt_(s)
#define _Outptr_result_buffer_(s)
#define _Post_writable_byte_size_(s)
#define _Out_writes_bytes_opt_(s)
#define _Must_inspect_result_
#define _Maybe_raises_SEH_exception_
#define _In_reads_bytes_opt_(s)
#define HEAP_MAKE_TAG_FLAGS(b, o)
_In_ ULONG _In_ ULONG _In_ ULONG Length
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
VOID NTAPI MmUnsecureVirtualMemory(IN PVOID SecureMem)
PVOID NTAPI MmSecureVirtualMemory(IN PVOID Address, IN SIZE_T Length, IN ULONG Mode)
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
NTSTATUS NTAPI MmMapViewInSystemSpace(IN PVOID SectionObject, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
BOOLEAN NTAPI MmCanFileBeTruncated(_In_ PSECTION_OBJECT_POINTERS SectionObjectPointer, _In_opt_ PLARGE_INTEGER NewFileSize)
BOOLEAN NTAPI MmFlushImageSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN MMFLUSH_TYPE FlushType)
#define __in_data_source(src_sym)
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
VOID NTAPI MmResetDriverPaging(IN PVOID AddressWithinSection)
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
_Must_inspect_result_ _In_ ULONG Flags
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
enum _LOCK_OPERATION LOCK_OPERATION
_In_ PEPROCESS _In_ KPROCESSOR_MODE _In_ LOCK_OPERATION Operation
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
_In_ ULONG ThunkBufferSize
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS HighAddress
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS _In_opt_ PHYSICAL_ADDRESS BoundaryAddressMultiple
_Inout_ PMDL MemoryDescriptorList
_In_ SIZE_T NumberOfBytes
$endif(_NTIFS_) $if(_WDMDDK_) _Must_inspect_result_ _IRQL_requires_max_(DISPATCH_LEVEL) _When_(return !
NTKERNELAPI PVOID NTAPI MmGetVirtualForPhysical(_In_ PHYSICAL_ADDRESS PhysicalAddress)
NTKERNELAPI BOOLEAN NTAPI MmIsNonPagedSystemAddressValid(_In_ PVOID VirtualAddress)
_Must_inspect_result_ _In_ _In_ ULONG ProbeMode
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS _In_opt_ PHYSICAL_ADDRESS _In_ MEMORY_CACHING_TYPE _In_ NODE_REQUIREMENT PreferredNode
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
NTKERNELAPI BOOLEAN NTAPI MmIsThisAnNtAsSystem(VOID)
NTKERNELAPI PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(_In_ PVOID BaseAddress)
$if(_WDMDDK_) $endif(_WDMDDK_) $if(_NTIFS_) FORCEINLINE ULONG HEAP_MAKE_TAG_FLAGS(_In_ ULONG TagBase
_Inout_ PSIZE_T _In_opt_ PMDLX _In_ MM_ROTATE_DIRECTION Direction
_Inout_ PSIZE_T _In_opt_ PMDLX NewMdl
NTKERNELAPI SIZE_T NTAPI MmSizeOfMdl(_In_reads_bytes_opt_(Length) PVOID Base, _In_ SIZE_T Length)
NTKERNELAPI MM_SYSTEMSIZE NTAPI MmQuerySystemSize(VOID)
NTKERNELAPI LOGICAL NTAPI MmIsDriverVerifying(_In_ struct _DRIVER_OBJECT *DriverObject)
_Must_inspect_result_ _In_ ULONG NewProtect
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS LowestAcceptableAddress
_Must_inspect_result_ _In_ SIZE_T _In_ PVOID PageAddress
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
_In_opt_ PLARGE_INTEGER NewFileSize
_In_ MMFLUSH_TYPE FlushType
_In_ PHYSICAL_ADDRESS HighestAcceptableAddress
NTKERNELAPI PMDL NTAPI MmCreateMdl(_Out_writes_bytes_opt_(sizeof(MDL)+(sizeof(PFN_NUMBER) *ADDRESS_AND_SIZE_TO_SPAN_PAGES(Base, Length))) PMDL MemoryDescriptorList, _In_reads_bytes_opt_(Length) PVOID Base, _In_ SIZE_T Length)
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS SkipBytes
_Inout_ PSIZE_T _In_opt_ PMDLX _In_ MM_ROTATE_DIRECTION _In_ PMM_ROTATE_COPY_CALLBACK_FUNCTION CopyFunction
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS _In_opt_ PHYSICAL_ADDRESS _In_ MEMORY_CACHING_TYPE CacheType
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS _In_ SIZE_T TotalBytes
enum _MM_SYSTEM_SIZE MM_SYSTEMSIZE
enum _MEMORY_CACHING_TYPE MEMORY_CACHING_TYPE
enum _MM_ROTATE_DIRECTION MM_ROTATE_DIRECTION
NTSTATUS(NTAPI * PMM_ROTATE_COPY_CALLBACK_FUNCTION)(_In_ PMDL DestinationMdl, _In_ PMDL SourceMdl, _In_ PVOID Context)
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG _In_ ULONG Protect