PFN_TYPE Page;
PEPROCESS CurrentProcess = PsGetCurrentProcess();
PMADDRESS_SPACE AddressSpace;
+ BOOLEAN PagedPool;
DPRINT("MmProbeAndLockPages(Mdl %x)\n", Mdl);
Mode = KernelMode;
Mdl->Process = NULL;
AddressSpace = MmGetKernelAddressSpace();
+ PagedPool = Mdl->StartVa >= MmPagedPoolBase && Mdl->StartVa < MmPagedPoolBase + MmPagedPoolSize ? TRUE : FALSE;
}
else
{
Mode = UserMode;
Mdl->Process = CurrentProcess;
AddressSpace = &CurrentProcess->AddressSpace;
+ PagedPool = FALSE;
}
+ if (PagedPool)
+ {
+ MmLockPagedPool();
+ }
+ else
+ {
+ MmLockAddressSpace(AddressSpace);
+ }
/*
* Lock the pages
*/
- MmLockAddressSpace(AddressSpace);
-
for (i = 0; i < NrPages; i++)
{
PVOID Address;
MmDereferencePage(Page);
}
}
- MmUnlockAddressSpace(AddressSpace);
+ if (PagedPool)
+ {
+ MmUnlockPagedPool();
+ }
+ else
+ {
+ MmUnlockAddressSpace(AddressSpace);
+ }
ExRaiseStatus(STATUS_ACCESS_VIOLATION);
}
}
MmDereferencePage(Page);
}
}
- MmUnlockAddressSpace(AddressSpace);
+ if (PagedPool)
+ {
+ MmUnlockPagedPool();
+ }
+ else
+ {
+ MmUnlockAddressSpace(AddressSpace);
+ }
ExRaiseStatus(STATUS_ACCESS_VIOLATION);
}
}
MmReferencePage(Page);
}
- MmUnlockAddressSpace(AddressSpace);
+ if (PagedPool)
+ {
+ MmUnlockPagedPool();
+ }
+ else
+ {
+ MmUnlockAddressSpace(AddressSpace);
+ }
Mdl->MdlFlags |= MDL_PAGES_LOCKED;
}
DbgPrint("%s:%d\n",__FILE__,__LINE__);
return(STATUS_UNSUCCESSFUL);
}
+ if (Address >= (ULONG_PTR)MmPagedPoolBase && Address < (ULONG_PTR)MmPagedPoolBase + MmPagedPoolSize)
+ {
+ return STATUS_SUCCESS;
+ }
AddressSpace = MmGetKernelAddressSpace();
}
else
Status = MmRequestPageMemoryConsumer(MC_PPOOL, FALSE, &AllocatedPage);
if (!NT_SUCCESS(Status))
{
- MmUnlockAddressSpace(MmGetKernelAddressSpace());
- Status = MmRequestPageMemoryConsumer(MC_PPOOL, TRUE, &AllocatedPage);
- MmLockAddressSpace(MmGetKernelAddressSpace());
+ return Status;
}
Status =
MmCreateVirtualMapping(NULL,
NTSTATUS Status;
BOOLEAN Locked = FromMdl;
PFN_TYPE Pfn;
+ BOOLEAN PagedPool;
DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
CPRINT("Address: %x\n", Address);
return(STATUS_UNSUCCESSFUL);
}
+ PagedPool = Address >= (ULONG_PTR)MmPagedPoolBase && Address < (ULONG_PTR)MmPagedPoolBase + MmPagedPoolSize ? TRUE : FALSE;
AddressSpace = MmGetKernelAddressSpace();
}
else
{
+ PagedPool = FALSE;
AddressSpace = &PsGetCurrentProcess()->AddressSpace;
}
if (!FromMdl)
{
- MmLockAddressSpace(AddressSpace);
+ if (PagedPool)
+ {
+ MmLockPagedPool();
+ }
+ else
+ {
+ MmLockAddressSpace(AddressSpace);
+ }
}
/*
*/
do
{
- MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)Address);
- if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
+ if (PagedPool)
{
- if (!FromMdl)
- {
- MmUnlockAddressSpace(AddressSpace);
- }
- return (STATUS_UNSUCCESSFUL);
+ Status = MmCommitPagedPoolAddress((PVOID)Address, Locked);
}
-
- switch (MemoryArea->Type)
+ else
{
- case MEMORY_AREA_PAGED_POOL:
+ MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)Address);
+ if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
+ {
+ if (!FromMdl)
{
- Status = MmCommitPagedPoolAddress((PVOID)Address, Locked);
- break;
+ MmUnlockAddressSpace(AddressSpace);
}
+ return (STATUS_UNSUCCESSFUL);
+ }
- case MEMORY_AREA_SYSTEM:
- Status = STATUS_UNSUCCESSFUL;
- break;
+ switch (MemoryArea->Type)
+ {
+ case MEMORY_AREA_SYSTEM:
+ Status = STATUS_UNSUCCESSFUL;
+ break;
- case MEMORY_AREA_SECTION_VIEW:
- Status = MmNotPresentFaultSectionView(AddressSpace,
- MemoryArea,
- (PVOID)Address,
- Locked);
- break;
+ case MEMORY_AREA_SECTION_VIEW:
+ Status = MmNotPresentFaultSectionView(AddressSpace,
+ MemoryArea,
+ (PVOID)Address,
+ Locked);
+ break;
- case MEMORY_AREA_VIRTUAL_MEMORY:
- case MEMORY_AREA_PEB_OR_TEB:
- Status = MmNotPresentFaultVirtualMemory(AddressSpace,
- MemoryArea,
- (PVOID)Address,
- Locked);
- break;
+ case MEMORY_AREA_VIRTUAL_MEMORY:
+ case MEMORY_AREA_PEB_OR_TEB:
+ Status = MmNotPresentFaultVirtualMemory(AddressSpace,
+ MemoryArea,
+ (PVOID)Address,
+ Locked);
+ break;
- case MEMORY_AREA_SHARED_DATA:
- Pfn = MmSharedDataPagePhysicalAddress.QuadPart >> PAGE_SHIFT;
- Status =
- MmCreateVirtualMapping(PsGetCurrentProcess(),
- (PVOID)PAGE_ROUND_DOWN(Address),
- PAGE_READONLY,
- &Pfn,
- 1);
- break;
+ case MEMORY_AREA_SHARED_DATA:
+ Pfn = MmSharedDataPagePhysicalAddress.QuadPart >> PAGE_SHIFT;
+ Status = MmCreateVirtualMapping(PsGetCurrentProcess(),
+ (PVOID)PAGE_ROUND_DOWN(Address),
+ PAGE_READONLY,
+ &Pfn,
+ 1);
+ break;
- default:
- Status = STATUS_UNSUCCESSFUL;
- break;
+ default:
+ Status = STATUS_UNSUCCESSFUL;
+ break;
+ }
}
}
while (Status == STATUS_MM_RESTART_OPERATION);
DPRINT("Completed page fault handling\n");
if (!FromMdl)
{
- MmUnlockAddressSpace(AddressSpace);
+ if (PagedPool)
+ {
+ MmUnlockPagedPool();
+ }
+ else
+ {
+ MmUnlockAddressSpace(AddressSpace);
+ }
}
return(Status);
}
ULONG MmPagedPoolSize;
ULONG MmTotalPagedPoolQuota = 0; // TODO FIXME commented out until we use it
static PR_POOL MmPagedPool = NULL;
+static FAST_MUTEX MmPagedPoolLock;
/* FUNCTIONS *****************************************************************/
VOID INIT_FUNCTION
-MmInitializePagedPool()
+MmInitializePagedPool(VOID)
{
/*
* We are still at a high IRQL level at this point so explicitly commit
PAGE_SIZE );
ExInitializeFastMutex(&MmPagedPool->Mutex);
+ ExInitializeFastMutex(&MmPagedPoolLock);
+}
+
+VOID MmLockPagedPool(VOID)
+{
+ ExAcquireFastMutex(&MmPagedPoolLock);
+}
+
+VOID MmUnlockPagedPool(VOID)
+{
+ ExReleaseFastMutex(&MmPagedPoolLock);
}
/**********************************************************************