-/* $Id: virtual.c,v 1.56 2002/05/07 22:36:46 hbirr Exp $
+/* $Id: virtual.c,v 1.57 2002/05/13 18:10:41 chorns Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
/* FUNCTIONS *****************************************************************/
-PMM_SEGMENT
+PMM_SEGMENT
MmGetSegmentForAddress(PMEMORY_AREA MArea,
PVOID Address,
PVOID* PCurrentAddress)
/*
* FUNCTION: Get the segment corresponding to a particular memory area and
- * address.
+ * address.
* ARGUMENTS:
* MArea (IN) = The memory area
* Address (IN) = The address to get the segment for
}
-NTSTATUS
+NTSTATUS
MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID Address,
PMM_PAGEOP PageOp)
{
- PVOID PhysicalAddress;
- BOOL WasDirty;
+ ULONG_PTR PhysicalAddress;
+ BOOLEAN WasDirty;
SWAPENTRY SwapEntry;
NTSTATUS Status;
PMDL Mdl;
*/
if ((MemoryArea->Attributes & PAGE_READONLY) ||
(MemoryArea->Attributes & PAGE_EXECUTE_READ))
- {
+ {
MmDeleteVirtualMapping(MemoryArea->Process, Address, FALSE,
NULL, (PULONG)&PhysicalAddress);
MmDeleteAllRmaps(PhysicalAddress, NULL, NULL);
KeBugCheck(0);
}
MmReleasePageMemoryConsumer(MC_USER, PhysicalAddress);
-
+
PageOp->Status = STATUS_SUCCESS;
KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE);
MmReleasePageOp(PageOp);
* Otherwise this is read-write data
*/
MmDisableVirtualMapping(MemoryArea->Process, Address,
- &WasDirty, (PULONG)&PhysicalAddress);
+ &WasDirty, (PULONG_PTR)&PhysicalAddress);
if (PhysicalAddress == 0)
{
KeBugCheck(0);
/*
* If necessary, allocate an entry in the paging file for this page
*/
- SwapEntry = MmGetSavedSwapEntryPage((PVOID)PhysicalAddress);
+ SwapEntry = MmGetSavedSwapEntryPage(PhysicalAddress);
if (SwapEntry == 0)
{
SwapEntry = MmAllocSwapPage();
return(STATUS_UNSUCCESSFUL);
}
}
-
+
/*
* Write the page to the pagefile
*/
Status = MmWriteToSwapPage(SwapEntry, Mdl);
if (!NT_SUCCESS(Status))
{
- DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n",
+ DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n",
Status);
MmEnableVirtualMapping(MemoryArea->Process, Address);
PageOp->Status = STATUS_UNSUCCESSFUL;
NTSTATUS
MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
- MEMORY_AREA* MemoryArea,
+ MEMORY_AREA* MemoryArea,
PVOID Address,
BOOLEAN Locked)
/*
* NOTES: This function is called with the address space lock held.
*/
{
- PVOID Page;
+ ULONG_PTR Page;
NTSTATUS Status;
PMM_SEGMENT Segment;
PVOID CurrentAddress;
PMM_PAGEOP PageOp;
-
+
/*
* There is a window between taking the page fault and locking the
* address space when another thread could load the page so we check
{
if (Locked)
{
- MmLockPage((PVOID)MmGetPhysicalAddressForProcess(NULL, Address));
- }
+ MmLockPage(MmGetPhysicalAddressForProcess(NULL, Address));
+ }
return(STATUS_SUCCESS);
}
MmLockAddressSpace(AddressSpace);
if (Locked)
{
- MmLockPage((PVOID)MmGetPhysicalAddressForProcess(NULL, Address));
+ MmLockPage(MmGetPhysicalAddressForProcess(NULL, Address));
}
MmReleasePageOp(PageOp);
return(STATUS_SUCCESS);
(ULONG)Page,
TRUE);
MmLockAddressSpace(AddressSpace);
- }
+ }
if (!NT_SUCCESS(Status))
{
DPRINT1("MmCreateVirtualMapping failed, not out of memory\n");
*/
if (Locked)
{
- MmLockPage((PVOID)MmGetPhysicalAddressForProcess(NULL, Address));
+ MmLockPage(MmGetPhysicalAddressForProcess(NULL, Address));
}
PageOp->Status = STATUS_SUCCESS;
KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE);
BaseAddress + (i * PAGESIZE)))
{
SWAPENTRY SwapEntry;
-
+
MmDeletePageFileMapping(AddressSpace->Process,
BaseAddress + (i * PAGESIZE),
&SwapEntry);
FALSE, NULL, NULL);
if (PhysicalAddr.u.LowPart != 0)
{
- MmDeleteRmap((PVOID)PhysicalAddr.u.LowPart, AddressSpace->Process,
+ MmDeleteRmap((ULONG_PTR)PhysicalAddr.u.LowPart, AddressSpace->Process,
BaseAddress + (i * PAGESIZE));
- MmDereferencePage((PVOID)(ULONG)(PhysicalAddr.u.LowPart));
+ MmDereferencePage((ULONG_PTR)(PhysicalAddr.u.LowPart));
}
}
}
ULONG OldType;
ULONG OldProtect;
ULONG OldLength;
-
+
DPRINT("MmSplitSegment()\n");
/*
* Save the type and protection and length of the current segment
FirstSegment->Protect,
Type,
Protect);
-
+
CurrentAddress = FirstAddress + FirstSegment->Length +
RegionSegment->Length;
}
OldLength,
OldType,
OldProtect,
- Type,
+ Type,
Protect);
CurrentSegment = CONTAINING_RECORD(CurrentEntry,
{
KeBugCheck(0);
}
-
+
if (BaseAddress >= CurrentAddress &&
(BaseAddress + RegionSize) <= (CurrentAddress + CurrentSegment->Length))
{
* PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_GUARD,
* PAGE_NOACCESS
* REMARKS:
- * This function maps to the win32 VirtualAllocEx. Virtual memory is
+ * This function maps to the win32 VirtualAllocEx. Virtual memory is
* process based so the protocol starts with a ProcessHandle. I
* splitted the functionality of obtaining the actual address and
* specifying the start address in two parameters ( BaseAddress and
ObDereferenceObject(Process);
return(STATUS_UNSUCCESSFUL);
}
-
+
Status = MmCreateMemoryArea(Process,
&Process->AddressSpace,
MEMORY_AREA_VIRTUAL_MEMORY,
{
MmReserveSwapPages(RegionSize);
}
-
+
*UBaseAddress = BaseAddress;
*URegionSize = RegionSize;
DPRINT("*UBaseAddress %x *URegionSize %x\n", BaseAddress, RegionSize);
-
+
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
return(STATUS_SUCCESS);
}
-NTSTATUS STDCALL
+NTSTATUS STDCALL
NtFlushVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
IN ULONG NumberOfBytesToFlush,
/*
* FUNCTION: Flushes virtual memory to file
* ARGUMENTS:
- * ProcessHandle = Points to the process that allocated the virtual
+ * ProcessHandle = Points to the process that allocated the virtual
* memory
* BaseAddress = Points to the memory address
* NumberOfBytesToFlush = Limits the range to flush,
* NumberOfBytesFlushed = Actual number of bytes flushed
- * RETURNS: Status
+ * RETURNS: Status
*/
{
UNIMPLEMENTED;
}
-
-VOID STATIC
-MmFreeVirtualMemoryPage(PVOID Context,
- MEMORY_AREA* MemoryArea,
- PVOID Address,
- ULONG PhysicalAddr,
- SWAPENTRY SwapEntry,
- BOOLEAN Dirty)
+VOID
+MmFreeVirtualMemoryPage (IN BOOLEAN Before,
+ IN PVOID Context,
+ IN PMEMORY_AREA MemoryArea,
+ IN PVOID Address,
+ IN ULONG_PTR PhysicalAddress,
+ IN SWAPENTRY SwapEntry,
+ IN BOOLEAN Dirty)
{
PEPROCESS Process = (PEPROCESS)Context;
-
- if (PhysicalAddr != 0)
+
+ if (Before)
+ return;
+
+ if (PhysicalAddress != 0)
{
- MmDeleteRmap((PVOID)PhysicalAddr, Process, Address);
- MmDereferencePage((PVOID)PhysicalAddr);
+ MmDeleteRmap(PhysicalAddress, Process, Address);
+ MmDereferencePage(PhysicalAddress);
}
else if (SwapEntry != 0)
{