2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/mm/ARM3/mdlsup.c
5 * PURPOSE: ARM Memory Manager Memory Descriptor List (MDL) Management
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
15 #define MODULE_INVOLVED_IN_ARM3
16 #include "../ARM3/miarm.h"
18 /* GLOBALS ********************************************************************/
21 BOOLEAN MmTrackLockedPages
;
22 SIZE_T MmSystemLockPagesCount
;
24 /* PUBLIC FUNCTIONS ***********************************************************/
31 MmCreateMdl(IN PMDL Mdl
,
38 // Check if we don't have an MDL built
43 // Calculate the size we'll need and allocate the MDL
45 Size
= MmSizeOfMdl(Base
, Length
);
46 Mdl
= ExAllocatePoolWithTag(NonPagedPool
, Size
, TAG_MDL
);
47 if (!Mdl
) return NULL
;
53 MmInitializeMdl(Mdl
, Base
, Length
);
62 MmSizeOfMdl(IN PVOID Base
,
66 // Return the MDL size
69 (ADDRESS_AND_SIZE_TO_SPAN_PAGES(Base
, Length
) * sizeof(PFN_NUMBER
));
77 MmBuildMdlForNonPagedPool(IN PMDL Mdl
)
79 PPFN_NUMBER MdlPages
, EndPage
;
80 PFN_NUMBER Pfn
, PageCount
;
87 ASSERT(Mdl
->ByteCount
!= 0);
88 ASSERT((Mdl
->MdlFlags
& (MDL_PAGES_LOCKED
|
89 MDL_MAPPED_TO_SYSTEM_VA
|
90 MDL_SOURCE_IS_NONPAGED_POOL
|
94 // We know the MDL isn't associated to a process now
99 // Get page and VA information
101 MdlPages
= (PPFN_NUMBER
)(Mdl
+ 1);
105 // Set the system address and now get the page count
107 Mdl
->MappedSystemVa
= (PVOID
)((ULONG_PTR
)Base
+ Mdl
->ByteOffset
);
108 PageCount
= ADDRESS_AND_SIZE_TO_SPAN_PAGES(Mdl
->MappedSystemVa
,
110 ASSERT(PageCount
!= 0);
111 EndPage
= MdlPages
+ PageCount
;
116 PointerPte
= MiAddressToPte(Base
);
122 Pfn
= PFN_FROM_PTE(PointerPte
++);
124 } while (MdlPages
< EndPage
);
127 // Set the nonpaged pool flag
129 Mdl
->MdlFlags
|= MDL_SOURCE_IS_NONPAGED_POOL
;
132 // Check if this is an I/O mapping
134 if (!MiGetPfnEntry(Pfn
)) Mdl
->MdlFlags
|= MDL_IO_SPACE
;
142 MmAllocatePagesForMdl(IN PHYSICAL_ADDRESS LowAddress
,
143 IN PHYSICAL_ADDRESS HighAddress
,
144 IN PHYSICAL_ADDRESS SkipBytes
,
145 IN SIZE_T TotalBytes
)
148 // Call the internal routine
150 return MiAllocatePagesForMdl(LowAddress
,
163 MmAllocatePagesForMdlEx(IN PHYSICAL_ADDRESS LowAddress
,
164 IN PHYSICAL_ADDRESS HighAddress
,
165 IN PHYSICAL_ADDRESS SkipBytes
,
166 IN SIZE_T TotalBytes
,
167 IN MEMORY_CACHING_TYPE CacheType
,
170 MI_PFN_CACHE_ATTRIBUTE CacheAttribute
;
173 // Check for invalid cache type
175 if (CacheType
> MmWriteCombined
)
178 // Normalize to default
180 CacheAttribute
= MiNotMapped
;
185 // Conver to internal caching attribute
187 CacheAttribute
= MiPlatformCacheAttributes
[FALSE
][CacheType
];
191 // Only these flags are allowed
193 if (Flags
& ~(MM_DONT_ZERO_ALLOCATION
| MM_ALLOCATE_FROM_LOCAL_NODE_ONLY
))
202 // Call the internal routine
204 return MiAllocatePagesForMdl(LowAddress
,
217 MmFreePagesFromMdl(IN PMDL Mdl
)
224 DPRINT("Freeing MDL: %p\n", Mdl
);
229 ASSERT(KeGetCurrentIrql() <= APC_LEVEL
);
230 ASSERT((Mdl
->MdlFlags
& MDL_IO_SPACE
) == 0);
231 ASSERT(((ULONG_PTR
)Mdl
->StartVa
& (PAGE_SIZE
- 1)) == 0);
234 // Get address and page information
236 Base
= (PVOID
)((ULONG_PTR
)Mdl
->StartVa
+ Mdl
->ByteOffset
);
237 NumberOfPages
= ADDRESS_AND_SIZE_TO_SPAN_PAGES(Base
, Mdl
->ByteCount
);
242 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
245 // Loop all the MDL pages
247 Pages
= (PPFN_NUMBER
)(Mdl
+ 1);
251 // Reached the last page
253 if (*Pages
== LIST_HEAD
) break;
256 // Get the page entry
258 Pfn1
= MiGetPfnEntry(*Pages
);
260 ASSERT(Pfn1
->u2
.ShareCount
== 1);
261 ASSERT(MI_IS_PFN_DELETED(Pfn1
) == TRUE
);
262 if (Pfn1
->u4
.PteFrame
!= 0x1FFEDCB)
264 /* Corrupted PFN entry or invalid free */
265 KeBugCheckEx(MEMORY_MANAGEMENT
, 0x1236, (ULONG_PTR
)Mdl
, (ULONG_PTR
)Pages
, *Pages
);
271 Pfn1
->u3
.e1
.StartOfAllocation
= 0;
272 Pfn1
->u3
.e1
.EndOfAllocation
= 0;
273 Pfn1
->u2
.ShareCount
= 0;
278 ASSERT(Pfn1
->u3
.e2
.ReferenceCount
!= 0);
279 if (Pfn1
->u3
.e2
.ReferenceCount
!= 1)
281 /* Just take off one reference */
282 InterlockedDecrement16((PSHORT
)&Pfn1
->u3
.e2
.ReferenceCount
);
286 /* We'll be nuking the whole page */
287 MiDecrementReferenceCount(Pfn1
, *Pages
);
291 // Clear this page and move on
293 *Pages
++ = LIST_HEAD
;
294 } while (--NumberOfPages
!= 0);
299 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
302 // Remove the pages locked flag
304 Mdl
->MdlFlags
&= ~MDL_PAGES_LOCKED
;
312 MmMapLockedPagesSpecifyCache(IN PMDL Mdl
,
313 IN KPROCESSOR_MODE AccessMode
,
314 IN MEMORY_CACHING_TYPE CacheType
,
315 IN PVOID BaseAddress
,
316 IN ULONG BugCheckOnFailure
,
317 IN MM_PAGE_PRIORITY Priority
)
320 PPFN_NUMBER MdlPages
, LastPage
;
323 MI_PFN_CACHE_ATTRIBUTE CacheAttribute
;
330 ASSERT(Mdl
->ByteCount
!= 0);
335 Base
= (PVOID
)((ULONG_PTR
)Mdl
->StartVa
+ Mdl
->ByteOffset
);
338 // Handle kernel case first
340 if (AccessMode
== KernelMode
)
343 // Get the list of pages and count
345 MdlPages
= (PPFN_NUMBER
)(Mdl
+ 1);
346 PageCount
= ADDRESS_AND_SIZE_TO_SPAN_PAGES(Base
, Mdl
->ByteCount
);
347 LastPage
= MdlPages
+ PageCount
;
352 ASSERT((Mdl
->MdlFlags
& (MDL_MAPPED_TO_SYSTEM_VA
|
353 MDL_SOURCE_IS_NONPAGED_POOL
|
354 MDL_PARTIAL_HAS_BEEN_MAPPED
)) == 0);
355 ASSERT((Mdl
->MdlFlags
& (MDL_PAGES_LOCKED
| MDL_PARTIAL
)) != 0);
358 // Get the correct cache type
360 IsIoMapping
= (Mdl
->MdlFlags
& MDL_IO_SPACE
) != 0;
361 CacheAttribute
= MiPlatformCacheAttributes
[IsIoMapping
][CacheType
];
366 PointerPte
= MiReserveSystemPtes(PageCount
, SystemPteSpace
);
370 // If it can fail, return NULL
372 if (Mdl
->MdlFlags
& MDL_MAPPING_CAN_FAIL
) return NULL
;
375 // Should we bugcheck?
377 if (!BugCheckOnFailure
) return NULL
;
380 // Yes, crash the system
382 KeBugCheckEx(NO_MORE_SYSTEM_PTES
, 0, PageCount
, 0, 0);
386 // Get the mapped address
388 Base
= (PVOID
)((ULONG_PTR
)MiPteToAddress(PointerPte
) + Mdl
->ByteOffset
);
393 TempPte
= ValidKernelPte
;
394 switch (CacheAttribute
)
401 MI_PAGE_DISABLE_CACHE(&TempPte
);
402 MI_PAGE_WRITE_THROUGH(&TempPte
);
405 case MiWriteCombined
:
408 // Enable write combining
410 MI_PAGE_DISABLE_CACHE(&TempPte
);
411 MI_PAGE_WRITE_COMBINED(&TempPte
);
429 if (*MdlPages
== LIST_HEAD
) break;
434 TempPte
.u
.Hard
.PageFrameNumber
= *MdlPages
;
435 MI_WRITE_VALID_PTE(PointerPte
++, TempPte
);
436 } while (++MdlPages
< LastPage
);
441 ASSERT((Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
) == 0);
442 Mdl
->MappedSystemVa
= Base
;
443 Mdl
->MdlFlags
|= MDL_MAPPED_TO_SYSTEM_VA
;
446 // Check if it was partial
448 if (Mdl
->MdlFlags
& MDL_PARTIAL
)
451 // Write the appropriate flag here too
453 Mdl
->MdlFlags
|= MDL_PARTIAL_HAS_BEEN_MAPPED
;
457 // Return the mapped address
471 MmMapLockedPages(IN PMDL Mdl
,
472 IN KPROCESSOR_MODE AccessMode
)
475 // Call the extended version
477 return MmMapLockedPagesSpecifyCache(Mdl
,
490 MmUnmapLockedPages(IN PVOID BaseAddress
,
494 PFN_COUNT PageCount
, ExtraPageCount
;
495 PPFN_NUMBER MdlPages
;
501 ASSERT(Mdl
->ByteCount
!= 0);
504 // Check if this is a kernel request
506 if (BaseAddress
> MM_HIGHEST_USER_ADDRESS
)
509 // Get base and count information
511 Base
= (PVOID
)((ULONG_PTR
)Mdl
->StartVa
+ Mdl
->ByteOffset
);
512 PageCount
= ADDRESS_AND_SIZE_TO_SPAN_PAGES(Base
, Mdl
->ByteCount
);
517 ASSERT((Mdl
->MdlFlags
& MDL_PARENT_MAPPED_SYSTEM_VA
) == 0);
518 ASSERT(PageCount
!= 0);
519 ASSERT(Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
);
524 PointerPte
= MiAddressToPte(BaseAddress
);
527 // This should be a resident system PTE
529 ASSERT(PointerPte
>= MmSystemPtesStart
[SystemPteSpace
]);
530 ASSERT(PointerPte
<= MmSystemPtesEnd
[SystemPteSpace
]);
531 ASSERT(PointerPte
->u
.Hard
.Valid
== 1);
534 // Check if the caller wants us to free advanced pages
536 if (Mdl
->MdlFlags
& MDL_FREE_EXTRA_PTES
)
539 // Get the MDL page array
541 MdlPages
= MmGetMdlPfnArray(Mdl
);
543 /* Number of extra pages stored after the PFN array */
544 ExtraPageCount
= (PFN_COUNT
)*(MdlPages
+ PageCount
);
549 PageCount
+= ExtraPageCount
;
550 PointerPte
-= ExtraPageCount
;
551 ASSERT(PointerPte
>= MmSystemPtesStart
[SystemPteSpace
]);
552 ASSERT(PointerPte
<= MmSystemPtesEnd
[SystemPteSpace
]);
555 // Get the new base address
557 BaseAddress
= (PVOID
)((ULONG_PTR
)BaseAddress
-
558 (ExtraPageCount
<< PAGE_SHIFT
));
564 Mdl
->MdlFlags
&= ~(MDL_MAPPED_TO_SYSTEM_VA
|
565 MDL_PARTIAL_HAS_BEEN_MAPPED
|
566 MDL_FREE_EXTRA_PTES
);
569 // Release the system PTEs
571 MiReleaseSystemPtes(PointerPte
, PageCount
, SystemPteSpace
);
584 MmProbeAndLockPages(IN PMDL Mdl
,
585 IN KPROCESSOR_MODE AccessMode
,
586 IN LOCK_OPERATION Operation
)
588 PPFN_NUMBER MdlPages
;
589 PVOID Base
, Address
, LastAddress
, StartAddress
;
590 ULONG LockPages
, TotalPages
;
591 NTSTATUS Status
= STATUS_SUCCESS
;
592 PEPROCESS CurrentProcess
;
593 NTSTATUS ProbeStatus
;
594 PMMPTE PointerPte
, LastPte
;
596 #if (_MI_PAGING_LEVELS >= 3)
599 #if (_MI_PAGING_LEVELS == 4)
602 PFN_NUMBER PageFrameIndex
;
606 DPRINT("Probing MDL: %p\n", Mdl
);
611 ASSERT(Mdl
->ByteCount
!= 0);
612 ASSERT(((ULONG
)Mdl
->ByteOffset
& ~(PAGE_SIZE
- 1)) == 0);
613 ASSERT(((ULONG_PTR
)Mdl
->StartVa
& (PAGE_SIZE
- 1)) == 0);
614 ASSERT((Mdl
->MdlFlags
& (MDL_PAGES_LOCKED
|
615 MDL_MAPPED_TO_SYSTEM_VA
|
616 MDL_SOURCE_IS_NONPAGED_POOL
|
618 MDL_IO_SPACE
)) == 0);
621 // Get page and base information
623 MdlPages
= (PPFN_NUMBER
)(Mdl
+ 1);
627 // Get the addresses and how many pages we span (and need to lock)
629 Address
= (PVOID
)((ULONG_PTR
)Base
+ Mdl
->ByteOffset
);
630 LastAddress
= (PVOID
)((ULONG_PTR
)Address
+ Mdl
->ByteCount
);
631 LockPages
= ADDRESS_AND_SIZE_TO_SPAN_PAGES(Address
, Mdl
->ByteCount
);
632 ASSERT(LockPages
!= 0);
634 /* Block invalid access */
635 if ((AccessMode
!= KernelMode
) &&
636 ((LastAddress
> (PVOID
)MM_USER_PROBE_ADDRESS
) || (Address
>= LastAddress
)))
638 /* Caller should be in SEH, raise the error */
639 *MdlPages
= LIST_HEAD
;
640 ExRaiseStatus(STATUS_ACCESS_VIOLATION
);
646 if (Address
<= MM_HIGHEST_USER_ADDRESS
)
651 CurrentProcess
= PsGetCurrentProcess();
658 CurrentProcess
= NULL
;
662 // Save the number of pages we'll have to lock, and the start address
664 TotalPages
= LockPages
;
665 StartAddress
= Address
;
667 /* Large pages not supported */
668 ASSERT(!MI_IS_PHYSICAL_ADDRESS(Address
));
673 ProbeStatus
= STATUS_SUCCESS
;
684 *MdlPages
= LIST_HEAD
;
689 *(volatile CHAR
*)Address
;
692 // Check if this is write access (only probe for user-mode)
694 if ((Operation
!= IoReadAccess
) &&
695 (Address
<= MM_HIGHEST_USER_ADDRESS
))
698 // Probe for write too
700 ProbeForWriteChar(Address
);
706 Address
= PAGE_ALIGN((ULONG_PTR
)Address
+ PAGE_SIZE
);
713 } while (Address
< LastAddress
);
716 // Reset back to the original page
718 ASSERT(LockPages
== 0);
719 MdlPages
= (PPFN_NUMBER
)(Mdl
+ 1);
721 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
726 ProbeStatus
= _SEH2_GetExceptionCode();
731 // So how did that go?
733 if (ProbeStatus
!= STATUS_SUCCESS
)
738 DPRINT1("MDL PROBE FAILED!\n");
740 ExRaiseStatus(ProbeStatus
);
744 // Get the PTE and PDE
746 PointerPte
= MiAddressToPte(StartAddress
);
747 PointerPde
= MiAddressToPde(StartAddress
);
748 #if (_MI_PAGING_LEVELS >= 3)
749 PointerPpe
= MiAddressToPpe(StartAddress
);
751 #if (_MI_PAGING_LEVELS == 4)
752 PointerPxe
= MiAddressToPxe(StartAddress
);
758 ASSERT(MdlPages
== (PPFN_NUMBER
)(Mdl
+ 1));
761 // Check what kind of operation this is
763 if (Operation
!= IoReadAccess
)
766 // Set the write flag
768 Mdl
->MdlFlags
|= MDL_WRITE_OPERATION
;
773 // Remove the write flag
775 Mdl
->MdlFlags
&= ~(MDL_WRITE_OPERATION
);
779 // Mark the MDL as locked *now*
781 Mdl
->MdlFlags
|= MDL_PAGES_LOCKED
;
784 // Check if this came from kernel mode
786 if (Base
> MM_HIGHEST_USER_ADDRESS
)
789 // We should not have a process
791 ASSERT(CurrentProcess
== NULL
);
795 // In kernel mode, we don't need to check for write access
797 Operation
= IoReadAccess
;
803 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
810 ASSERT(TotalPages
!= 0);
811 ASSERT(CurrentProcess
== PsGetCurrentProcess());
814 // Track locked pages
816 InterlockedExchangeAddSizeT(&CurrentProcess
->NumberOfLockedPages
,
822 Mdl
->Process
= CurrentProcess
;
824 /* Lock the process working set */
825 MiLockProcessWorkingSet(CurrentProcess
, PsGetCurrentThread());
833 LastPte
= MiAddressToPte((PVOID
)((ULONG_PTR
)LastAddress
- 1));
841 // Assume failure and check for non-mapped pages
843 *MdlPages
= LIST_HEAD
;
845 #if (_MI_PAGING_LEVELS == 4)
846 (PointerPxe
->u
.Hard
.Valid
== 0) ||
848 #if (_MI_PAGING_LEVELS >= 3)
849 (PointerPpe
->u
.Hard
.Valid
== 0) ||
851 (PointerPde
->u
.Hard
.Valid
== 0) ||
852 (PointerPte
->u
.Hard
.Valid
== 0))
855 // What kind of lock were we using?
862 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
866 /* Release process working set */
867 MiUnlockProcessWorkingSet(CurrentProcess
, PsGetCurrentThread());
873 Address
= MiPteToAddress(PointerPte
);
875 //HACK: Pass a placeholder TrapInformation so the fault handler knows we're unlocked
876 Status
= MmAccessFault(FALSE
, Address
, KernelMode
, (PVOID
)0xBADBADA3);
877 if (!NT_SUCCESS(Status
))
882 DPRINT1("Access fault failed\n");
887 // What lock should we use?
894 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
898 /* Lock the process working set */
899 MiLockProcessWorkingSet(CurrentProcess
, PsGetCurrentThread());
904 // Check if this was a write or modify
906 if (Operation
!= IoReadAccess
)
909 // Check if the PTE is not writable
911 if (MI_IS_PAGE_WRITEABLE(PointerPte
) == FALSE
)
914 // Check if it's copy on write
916 if (MI_IS_PAGE_COPY_ON_WRITE(PointerPte
))
919 // Get the base address and allow a change for user-mode
921 Address
= MiPteToAddress(PointerPte
);
922 if (Address
<= MM_HIGHEST_USER_ADDRESS
)
925 // What kind of lock were we using?
932 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
936 /* Release process working set */
937 MiUnlockProcessWorkingSet(CurrentProcess
, PsGetCurrentThread());
944 //HACK: Pass a placeholder TrapInformation so the fault handler knows we're unlocked
945 Status
= MmAccessFault(TRUE
, Address
, KernelMode
, (PVOID
)0xBADBADA3);
946 if (!NT_SUCCESS(Status
))
951 DPRINT1("Access fault failed\n");
956 // Re-acquire the lock
963 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
967 /* Lock the process working set */
968 MiLockProcessWorkingSet(CurrentProcess
, PsGetCurrentThread());
979 // Fail, since we won't allow this
981 Status
= STATUS_ACCESS_VIOLATION
;
982 goto CleanupWithLock
;
989 PageFrameIndex
= PFN_FROM_PTE(PointerPte
);
990 Pfn1
= MiGetPfnEntry(PageFrameIndex
);
993 /* Either this is for kernel-mode, or the working set is held */
994 ASSERT((CurrentProcess
== NULL
) || (UsePfnLock
== FALSE
));
996 /* No Physical VADs supported yet */
997 if (CurrentProcess
) ASSERT(CurrentProcess
->PhysicalVadRoot
== NULL
);
999 /* This address should already exist and be fully valid */
1000 MiReferenceProbedPageAndBumpLockCount(Pfn1
);
1005 // For I/O addresses, just remember this
1007 Mdl
->MdlFlags
|= MDL_IO_SPACE
;
1011 // Write the page and move on
1013 *MdlPages
++ = PageFrameIndex
;
1016 /* Check if we're on a PDE boundary */
1017 if (MiIsPteOnPdeBoundary(PointerPte
)) PointerPde
++;
1018 #if (_MI_PAGING_LEVELS >= 3)
1019 if (MiIsPteOnPpeBoundary(PointerPte
)) PointerPpe
++;
1021 #if (_MI_PAGING_LEVELS == 4)
1022 if (MiIsPteOnPxeBoundary(PointerPte
)) PointerPxe
++;
1025 } while (PointerPte
<= LastPte
);
1028 // What kind of lock were we using?
1035 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
1039 /* Release process working set */
1040 MiUnlockProcessWorkingSet(CurrentProcess
, PsGetCurrentThread());
1046 ASSERT((Mdl
->MdlFlags
& MDL_DESCRIBES_AWE
) == 0);
1051 // This is the failure path
1053 ASSERT(!NT_SUCCESS(Status
));
1056 // What kind of lock were we using?
1063 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
1067 /* Release process working set */
1068 MiUnlockProcessWorkingSet(CurrentProcess
, PsGetCurrentThread());
1072 // Pages must be locked so MmUnlock can work
1074 ASSERT(Mdl
->MdlFlags
& MDL_PAGES_LOCKED
);
1080 ExRaiseStatus(Status
);
1088 MmUnlockPages(IN PMDL Mdl
)
1090 PPFN_NUMBER MdlPages
, LastPage
;
1093 ULONG Flags
, PageCount
;
1096 DPRINT("Unlocking MDL: %p\n", Mdl
);
1101 ASSERT((Mdl
->MdlFlags
& MDL_PAGES_LOCKED
) != 0);
1102 ASSERT((Mdl
->MdlFlags
& MDL_SOURCE_IS_NONPAGED_POOL
) == 0);
1103 ASSERT((Mdl
->MdlFlags
& MDL_PARTIAL
) == 0);
1104 ASSERT(Mdl
->ByteCount
!= 0);
1107 // Get the process associated and capture the flags which are volatile
1109 Process
= Mdl
->Process
;
1110 Flags
= Mdl
->MdlFlags
;
1113 // Automagically undo any calls to MmGetSystemAddressForMdl's for this MDL
1115 if (Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
)
1118 // Unmap the pages from system space
1120 MmUnmapLockedPages(Mdl
->MappedSystemVa
, Mdl
);
1124 // Get the page count
1126 MdlPages
= (PPFN_NUMBER
)(Mdl
+ 1);
1127 Base
= (PVOID
)((ULONG_PTR
)Mdl
->StartVa
+ Mdl
->ByteOffset
);
1128 PageCount
= ADDRESS_AND_SIZE_TO_SPAN_PAGES(Base
, Mdl
->ByteCount
);
1129 ASSERT(PageCount
!= 0);
1132 // We don't support AWE
1134 if (Flags
& MDL_DESCRIBES_AWE
) ASSERT(FALSE
);
1137 // Check if the buffer is mapped I/O space
1139 if (Flags
& MDL_IO_SPACE
)
1144 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
1149 LastPage
= MdlPages
+ PageCount
;
1153 // Last page, break out
1155 if (*MdlPages
== LIST_HEAD
) break;
1158 // Check if this page is in the PFN database
1160 Pfn1
= MiGetPfnEntry(*MdlPages
);
1161 if (Pfn1
) MiDereferencePfnAndDropLockCount(Pfn1
);
1162 } while (++MdlPages
< LastPage
);
1167 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
1170 // Check if we have a process
1175 // Handle the accounting of locked pages
1177 ASSERT(Process
->NumberOfLockedPages
> 0);
1178 InterlockedExchangeAddSizeT(&Process
->NumberOfLockedPages
,
1179 -(LONG_PTR
)PageCount
);
1185 Mdl
->MdlFlags
&= ~MDL_IO_SPACE
;
1186 Mdl
->MdlFlags
&= ~MDL_PAGES_LOCKED
;
1191 // Check if we have a process
1196 // Handle the accounting of locked pages
1198 ASSERT(Process
->NumberOfLockedPages
> 0);
1199 InterlockedExchangeAddSizeT(&Process
->NumberOfLockedPages
,
1200 -(LONG_PTR
)PageCount
);
1206 LastPage
= MdlPages
+ PageCount
;
1210 // Last page reached
1212 if (*MdlPages
== LIST_HEAD
)
1215 // Were there no pages at all?
1217 if (MdlPages
== (PPFN_NUMBER
)(Mdl
+ 1))
1220 // We're already done
1222 Mdl
->MdlFlags
&= ~MDL_PAGES_LOCKED
;
1227 // Otherwise, stop here
1229 LastPage
= MdlPages
;
1233 /* Save the PFN entry instead for the secondary loop */
1234 *MdlPages
= (PFN_NUMBER
)MiGetPfnEntry(*MdlPages
);
1235 ASSERT(*MdlPages
!= 0);
1236 } while (++MdlPages
< LastPage
);
1241 MdlPages
= (PPFN_NUMBER
)(Mdl
+ 1);
1244 // Now grab the PFN lock for the actual unlock and dereference
1246 OldIrql
= KeAcquireQueuedSpinLock(LockQueuePfnLock
);
1249 /* Get the current entry and reference count */
1250 Pfn1
= (PMMPFN
)*MdlPages
;
1251 MiDereferencePfnAndDropLockCount(Pfn1
);
1252 } while (++MdlPages
< LastPage
);
1257 KeReleaseQueuedSpinLock(LockQueuePfnLock
, OldIrql
);
1262 Mdl
->MdlFlags
&= ~MDL_PAGES_LOCKED
;
1270 MmAdvanceMdl(IN PMDL Mdl
,
1271 IN ULONG NumberOfBytes
)
1274 return STATUS_NOT_IMPLEMENTED
;
1282 MmMapLockedPagesWithReservedMapping(IN PVOID MappingAddress
,
1284 IN PMDL MemoryDescriptorList
,
1285 IN MEMORY_CACHING_TYPE CacheType
)
1296 MmUnmapReservedMapping(IN PVOID BaseAddress
,
1298 IN PMDL MemoryDescriptorList
)
1308 MmPrefetchPages(IN ULONG NumberOfLists
,
1309 IN PREAD_LIST
*ReadLists
)
1312 return STATUS_NOT_IMPLEMENTED
;
1320 MmProtectMdlSystemAddress(IN PMDL MemoryDescriptorList
,
1321 IN ULONG NewProtect
)
1324 return STATUS_NOT_IMPLEMENTED
;
1332 MmProbeAndLockProcessPages(IN OUT PMDL MemoryDescriptorList
,
1333 IN PEPROCESS Process
,
1334 IN KPROCESSOR_MODE AccessMode
,
1335 IN LOCK_OPERATION Operation
)
1346 MmProbeAndLockSelectedPages(IN OUT PMDL MemoryDescriptorList
,
1347 IN LARGE_INTEGER PageList
[],
1348 IN KPROCESSOR_MODE AccessMode
,
1349 IN LOCK_OPERATION Operation
)
1359 MmMapMemoryDumpMdl(IN PMDL Mdl
)