*/
MiCopyFromUserPage(NewPage, PAddress);
+ MmLockAddressSpace(AddressSpace);
/*
* Delete the old entry.
*/
/*
* Set the PTE to point to the new page
*/
- MmLockAddressSpace(AddressSpace);
Status = MmCreateVirtualMapping(AddressSpace->Process,
Address,
Region->Protect,
KEBUGCHECK(0);
return(Status);
}
- MmInsertRmap(NewPage, AddressSpace->Process, PAddress);
if (!NT_SUCCESS(Status))
{
DbgPrint("Unable to create virtual mapping\n");
* Unshare the old page.
*/
MmDeleteRmap(OldPage, AddressSpace->Process, PAddress);
+ MmInsertRmap(NewPage, AddressSpace->Process, PAddress);
MmLockSectionSegment(Segment);
MmUnsharePageEntrySectionSegment(Section, Segment, Offset, FALSE, FALSE);
MmUnlockSectionSegment(Segment);
PFN_TYPE Page;
PageOutContext = (MM_SECTION_PAGEOUT_CONTEXT*)Context;
+ if (Process)
+ {
+ MmLockAddressSpace(&Process->AddressSpace);
+ }
+
MmDeleteVirtualMapping(Process,
Address,
FALSE,
}
if (!PageOutContext->Private)
{
+ MmLockSectionSegment(PageOutContext->Segment);
MmUnsharePageEntrySectionSegment(PageOutContext->Section,
PageOutContext->Segment,
PageOutContext->Offset,
PageOutContext->WasDirty,
TRUE);
+ MmUnlockSectionSegment(PageOutContext->Segment);
}
- else
+ if (Process)
+ {
+ MmUnlockAddressSpace(&Process->AddressSpace);
+ }
+
+ if (PageOutContext->Private)
{
MmReleasePageMemoryConsumer(MC_USER, Page);
}
else if (!Context.WasDirty && Context.Private && SwapEntry != 0)
{
MmSetSavedSwapEntryPage(Page, 0);
+ MmLockAddressSpace(AddressSpace);
Status = MmCreatePageFileMapping(AddressSpace->Process,
Address,
SwapEntry);
+ MmUnlockAddressSpace(AddressSpace);
if (!NT_SUCCESS(Status))
{
KEBUGCHECK(0);
if (SwapEntry == 0)
{
MmShowOutOfSpaceMessagePagingFile();
-
+ MmLockAddressSpace(AddressSpace);
/*
* For private pages restore the old mappings.
*/
Entry = MAKE_SSE(Page << PAGE_SHIFT, 1);
MmSetPageEntrySectionSegment(Context.Segment, Context.Offset, Entry);
}
+ MmUnlockAddressSpace(AddressSpace);
PageOp->Status = STATUS_UNSUCCESSFUL;
MmspCompleteAndReleasePageOp(PageOp);
return(STATUS_PAGEFILE_QUOTA);
* As above: undo our actions.
* FIXME: Also free the swap page.
*/
+ MmLockAddressSpace(AddressSpace);
if (Context.Private)
{
Status = MmCreateVirtualMapping(AddressSpace->Process,
Entry = MAKE_SSE(Page << PAGE_SHIFT, 1);
MmSetPageEntrySectionSegment(Context.Segment, Context.Offset, Entry);
}
+ MmUnlockAddressSpace(AddressSpace);
PageOp->Status = STATUS_UNSUCCESSFUL;
MmspCompleteAndReleasePageOp(PageOp);
return(STATUS_UNSUCCESSFUL);
if (Context.Private)
{
+ MmLockAddressSpace(AddressSpace);
Status = MmCreatePageFileMapping(AddressSpace->Process,
Address,
SwapEntry);
+ MmUnlockAddressSpace(AddressSpace);
if (!NT_SUCCESS(Status))
{
KEBUGCHECK(0);
}
}
-NTSTATUS
+STATIC NTSTATUS
MmUnmapViewOfSegment(PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress)
{
PMEMORY_AREA MemoryArea;
PMADDRESS_SPACE AddressSpace;
PSECTION_OBJECT Section;
+ PMM_PAGEOP PageOp;
+ ULONG_PTR Offset;
DPRINT("Opening memory area Process %x BaseAddress %x\n",
Process, BaseAddress);
ASSERT(Process);
AddressSpace = &Process->AddressSpace;
+
+ MmLockAddressSpace(AddressSpace);
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
BaseAddress);
if (MemoryArea == NULL ||
MemoryArea->Type != MEMORY_AREA_SECTION_VIEW ||
MemoryArea->DeleteInProgress)
{
+ MmUnlockAddressSpace(AddressSpace);
return STATUS_NOT_MAPPED_VIEW;
}
+ MemoryArea->DeleteInProgress = TRUE;
+
+ while (MemoryArea->PageOpCount)
+ {
+ Offset = PAGE_ROUND_UP((ULONG_PTR)MemoryArea->EndingAddress - (ULONG_PTR)MemoryArea->StartingAddress);
+
+ while (Offset)
+ {
+ Offset -= PAGE_SIZE;
+ PageOp = MmCheckForPageOp(MemoryArea, NULL, NULL,
+ MemoryArea->Data.SectionData.Segment,
+ Offset + MemoryArea->Data.SectionData.ViewOffset);
+ if (PageOp)
+ {
+ MmUnlockAddressSpace(AddressSpace);
+ Status = MmspWaitForPageOpCompletionEvent(PageOp);
+ if (Status != STATUS_SUCCESS)
+ {
+ DPRINT1("Failed to wait for page op, status = %x\n", Status);
+ KEBUGCHECK(0);
+ }
+ MmLockAddressSpace(AddressSpace);
+ MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
+ BaseAddress);
+ if (MemoryArea == NULL ||
+ MemoryArea->Type != MEMORY_AREA_SECTION_VIEW)
+ {
+ MmUnlockAddressSpace(AddressSpace);
+ return STATUS_NOT_MAPPED_VIEW;
+ }
+ break;
+ }
+ }
+ }
+
Section = MemoryArea->Data.SectionData.Section;
if (Section->AllocationAttributes & SEC_IMAGE)
{
Status = MmUnmapViewOfSegment(AddressSpace, BaseAddress);
}
+ MmUnlockAddressSpace(AddressSpace);
return(STATUS_SUCCESS);
}
return(Status);
}
- MmLockAddressSpace(&Process->AddressSpace);
Status = MmUnmapViewOfSection(Process, BaseAddress);
- MmUnlockAddressSpace(&Process->AddressSpace);
ObDereferenceObject(Process);