}
VOID
-MmReferencePage(PFN_TYPE Pfn)
+MmReferencePageUnsafe(PFN_TYPE Pfn)
{
KIRQL oldIrql;
- DPRINT("MmReferencePage(PysicalAddress %x)\n", Pfn << PAGE_SHIFT);
+ DPRINT("MmReferencePageUnsafe(PysicalAddress %x)\n", Pfn << PAGE_SHIFT);
if (Pfn == 0 || Pfn >= MmPageArraySize)
{
- KEBUGCHECK(0);
+ return;
}
KeAcquireSpinLock(&PageListLock, &oldIrql);
KeReleaseSpinLock(&PageListLock, oldIrql);
}
+VOID
+MmReferencePage(PFN_TYPE Pfn)
+{
+ DPRINT("MmReferencePage(PysicalAddress %x)\n", Pfn << PAGE_SHIFT);
+
+ if (Pfn == 0 || Pfn >= MmPageArraySize)
+ {
+ KEBUGCHECK(0);
+ }
+
+ MmReferencePageUnsafe(Pfn);
+}
+
ULONG
MmGetReferenceCountPage(PFN_TYPE Pfn)
{
}
VOID
-MmLockPage(PFN_TYPE Pfn)
+MmLockPageUnsafe(PFN_TYPE Pfn)
{
KIRQL oldIrql;
- DPRINT("MmLockPage(PhysicalAddress %x)\n", Pfn << PAGE_SHIFT);
+ DPRINT("MmLockPageUnsafe(PhysicalAddress %x)\n", Pfn << PAGE_SHIFT);
if (Pfn == 0 || Pfn >= MmPageArraySize)
{
- KEBUGCHECK(0);
+ return;
}
KeAcquireSpinLock(&PageListLock, &oldIrql);
KeReleaseSpinLock(&PageListLock, oldIrql);
}
+VOID
+MmLockPage(PFN_TYPE Pfn)
+{
+ DPRINT("MmLockPage(PhysicalAddress %x)\n", Pfn << PAGE_SHIFT);
+
+ if (Pfn == 0 || Pfn >= MmPageArraySize)
+ {
+ KEBUGCHECK(0);
+ }
+
+ MmLockPageUnsafe(Pfn);
+}
+
VOID
MmUnlockPage(PFN_TYPE Pfn)
{
/*
MDL Flags desc.
-MDL_PAGES_LOCKED MmProbelAndLockPages has been called for this mdl
+MDL_PAGES_LOCKED MmProbeAndLockPages has been called for this mdl
MDL_SOURCE_IS_NONPAGED_POOL mdl has been build by MmBuildMdlForNonPagedPool
MDL_PARTIAL mdl has been built by IoBuildPartialMdl
MDL_MAPPING_CAN_FAIL in case of an error, MmMapLockedPages will return NULL instead of to bugcheck
/* Unmap all the pages. */
for (i = 0; i < PageCount; i++)
{
- MmDeleteVirtualMapping(NULL,
+ MmDeleteVirtualMapping(Mdl->Process,
(char*)BaseAddress + (i * PAGE_SIZE),
FALSE,
NULL,
{
memcpy(Mdl + 1, Pages, sizeof(PFN_TYPE) * (PAGE_ROUND_UP(Mdl->ByteOffset+Mdl->ByteCount)/PAGE_SIZE));
- //FIXME: this flag should be set by the caller perhaps?
+ /* FIXME: this flag should be set by the caller perhaps? */
Mdl->MdlFlags |= MDL_IO_PAGE_READ;
}
ASSERT(NrPages <= (Mdl->Size - sizeof(MDL))/sizeof(PFN_TYPE));
- if (Mdl->StartVa >= (PVOID)KERNEL_BASE &&
- MmGetPfnForProcess(NULL, Mdl->StartVa) > MmPageArraySize)
+ if (Mdl->StartVa >= (PVOID)KERNEL_BASE &&
+ MmGetPfnForProcess(NULL, Mdl->StartVa) >= MmPageArraySize)
{
/* phys addr is not phys memory so this must be io memory */
if (Mdl->StartVa >= (PVOID)KERNEL_BASE)
{
- //FIXME: why isn't AccessMode used?
+ /* FIXME: why isn't AccessMode used? */
Mode = KernelMode;
Mdl->Process = NULL;
AddressSpace = MmGetKernelAddressSpace();
}
else
{
- //FIXME: why isn't AccessMode used?
+ /* FIXME: why isn't AccessMode used? */
Mode = UserMode;
Mdl->Process = CurrentProcess;
AddressSpace = &CurrentProcess->AddressSpace;
for (j = 0; j < i; j++)
{
Page = MdlPages[j];
- MmUnlockPage(Page);
- MmDereferencePage(Page);
+ if (Page < MmPageArraySize)
+ {
+ MmUnlockPage(Page);
+ MmDereferencePage(Page);
+ }
}
MmUnlockAddressSpace(AddressSpace);
ExRaiseStatus(Status);
for (j = 0; j < i; j++)
{
Page = MdlPages[j];
- MmUnlockPage(Page);
- MmDereferencePage(Page);
+ if (Page < MmPageArraySize)
+ {
+ MmUnlockPage(Page);
+ MmDereferencePage(Page);
+ }
}
MmUnlockAddressSpace(AddressSpace);
ExRaiseStatus(Status);
}
Page = MmGetPfnForProcess(NULL, Address);
MdlPages[i] = Page;
- MmReferencePage(Page);
+ if (Page >= MmPageArraySize)
+ Mdl->MdlFlags |= MDL_IO_SPACE;
+ else
+ MmReferencePage(Page);
}
MmUnlockAddressSpace(AddressSpace);
}
KeReleaseSpinLock(&MiMdlMappingRegionLock, oldIrql);
+
+ Mdl->Process = NULL;
}
/* Set the virtual mappings for the MDL pages. */
Protect |= PAGE_NOCACHE;
else if (CacheType == MmWriteCombined)
DPRINT("CacheType MmWriteCombined not supported!\n");
- Status = MmCreateVirtualMapping(CurrentProcess,
- Base,
- Protect,
- MdlPages,
- PageCount);
+ if (Mdl->MdlFlags & MDL_IO_SPACE)
+ Status = MmCreateVirtualMappingUnsafe(CurrentProcess,
+ Base,
+ Protect,
+ MdlPages,
+ PageCount);
+ else
+ Status = MmCreateVirtualMapping(CurrentProcess,
+ Base,
+ Protect,
+ MdlPages,
+ PageCount);
if (!NT_SUCCESS(Status))
{
DbgPrint("Unable to create virtual mapping\n");
MmSharePageEntrySectionSegment(Segment, Offset);
+ /* FIXME: Should we call MmCreateVirtualMappingUnsafe if
+ * (Section->AllocationAttributes & SEC_PHYSICALMEMORY) is true?
+ */
Status = MmCreateVirtualMapping(MemoryArea->Process,
Address,
Attributes,
* Just map the desired physical page
*/
Page = (Offset + MemoryArea->Data.SectionData.ViewOffset) >> PAGE_SHIFT;
- Status = MmCreateVirtualMapping(AddressSpace->Process,
- Address,
- Region->Protect,
- &Page,
- 1);
+ Status = MmCreateVirtualMappingUnsafe(AddressSpace->Process,
+ Address,
+ Region->Protect,
+ &Page,
+ 1);
if (!NT_SUCCESS(Status))
{
- DPRINT("MmCreateVirtualMapping failed, not out of memory\n");
+ DPRINT("MmCreateVirtualMappingUnsafe failed, not out of memory\n");
KEBUGCHECK(0);
return(Status);
}
*/
if (Locked)
{
- MmLockPage(Page);
+ MmLockPageUnsafe(Page);
}
/*