- Reference/Dereference the process object only for adresses within user space.

svn path=/trunk/; revision=4701
This commit is contained in:
Hartmut Birr 2003-05-17 13:46:05 +00:00
parent f5048a6a3b
commit 9ad263f04e

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: rmap.c,v 1.15 2003/01/11 15:28:18 hbirr Exp $ /* $Id: rmap.c,v 1.16 2003/05/17 13:46:05 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top directory * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -72,6 +72,7 @@ MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
{ {
PMM_RMAP_ENTRY entry; PMM_RMAP_ENTRY entry;
PMEMORY_AREA MemoryArea; PMEMORY_AREA MemoryArea;
PMADDRESS_SPACE AddressSpace;
ULONG Type; ULONG Type;
PVOID Address; PVOID Address;
PEPROCESS Process; PEPROCESS Process;
@ -96,24 +97,35 @@ MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
{ {
KeBugCheck(0); KeBugCheck(0);
} }
Status = ObReferenceObjectByPointer(Process, PROCESS_ALL_ACCESS, NULL, KernelMode); if (Address < (PVOID)KERNEL_BASE)
ExReleaseFastMutex(&RmapListLock); {
if (!NT_SUCCESS(Status)) Status = ObReferenceObjectByPointer(Process, PROCESS_ALL_ACCESS, NULL, KernelMode);
{ ExReleaseFastMutex(&RmapListLock);
return Status; if (!NT_SUCCESS(Status))
} {
return Status;
}
AddressSpace = &Process->AddressSpace;
}
else
{
AddressSpace = MmGetKernelAddressSpace();
}
/* /*
* Lock the address space; then check that the address we are using * Lock the address space; then check that the address we are using
* still corresponds to a valid memory area (the page might have been * still corresponds to a valid memory area (the page might have been
* freed or paged out after we read the rmap entry.) * freed or paged out after we read the rmap entry.)
*/ */
MmLockAddressSpace(&Process->AddressSpace); MmLockAddressSpace(AddressSpace);
MemoryArea = MmOpenMemoryAreaByAddress(&Process->AddressSpace, Address); MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace, Address);
if (MemoryArea == NULL) if (MemoryArea == NULL)
{ {
MmUnlockAddressSpace(&Process->AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); if (Address < (PVOID)KERNEL_BASE)
{
ObDereferenceObject(Process);
}
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
@ -139,52 +151,60 @@ MmWritePagePhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
if (PageOp->Thread != PsGetCurrentThread()) if (PageOp->Thread != PsGetCurrentThread())
{ {
MmReleasePageOp(PageOp); MmReleasePageOp(PageOp);
MmUnlockAddressSpace(&Process->AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); if (Address < (PVOID)KERNEL_BASE)
{
ObDereferenceObject(Process);
}
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
/* /*
* Release locks now we have a page op. * Release locks now we have a page op.
*/ */
MmUnlockAddressSpace(&Process->AddressSpace); MmUnlockAddressSpace(AddressSpace);
/* /*
* Do the actual page out work. * Do the actual page out work.
*/ */
Status = MmWritePageSectionView(&Process->AddressSpace, MemoryArea, Status = MmWritePageSectionView(AddressSpace, MemoryArea,
Address, PageOp); Address, PageOp);
} }
else if (Type == MEMORY_AREA_VIRTUAL_MEMORY) else if (Type == MEMORY_AREA_VIRTUAL_MEMORY)
{ {
PageOp = MmGetPageOp(MemoryArea, Process->UniqueProcessId, PageOp = MmGetPageOp(MemoryArea, Address < (PVOID)KERNEL_BASE ? Process->UniqueProcessId : 0,
Address, NULL, 0, MM_PAGEOP_PAGEOUT); Address, NULL, 0, MM_PAGEOP_PAGEOUT);
if (PageOp->Thread != PsGetCurrentThread()) if (PageOp->Thread != PsGetCurrentThread())
{ {
MmReleasePageOp(PageOp); MmReleasePageOp(PageOp);
MmUnlockAddressSpace(&Process->AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); if (Address < (PVOID)KERNEL_BASE)
{
ObDereferenceObject(Process);
}
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
/* /*
* Release locks now we have a page op. * Release locks now we have a page op.
*/ */
MmUnlockAddressSpace(&Process->AddressSpace); MmUnlockAddressSpace(AddressSpace);
/* /*
* Do the actual page out work. * Do the actual page out work.
*/ */
Status = MmWritePageVirtualMemory(&Process->AddressSpace, MemoryArea, Status = MmWritePageVirtualMemory(AddressSpace, MemoryArea,
Address, PageOp); Address, PageOp);
} }
else else
{ {
KeBugCheck(0); KeBugCheck(0);
} }
ObDereferenceObject(Process); if (Address < (PVOID)KERNEL_BASE)
{
ObDereferenceObject(Process);
}
return(Status); return(Status);
} }
@ -193,6 +213,7 @@ MmPageOutPhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
{ {
PMM_RMAP_ENTRY entry; PMM_RMAP_ENTRY entry;
PMEMORY_AREA MemoryArea; PMEMORY_AREA MemoryArea;
PMADDRESS_SPACE AddressSpace;
ULONG Type; ULONG Type;
PVOID Address; PVOID Address;
PEPROCESS Process; PEPROCESS Process;
@ -214,14 +235,23 @@ MmPageOutPhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
KeBugCheck(0); KeBugCheck(0);
} }
Status = ObReferenceObjectByPointer(Process, PROCESS_ALL_ACCESS, NULL, KernelMode); if (Address < (PVOID)KERNEL_BASE)
ExReleaseFastMutex(&RmapListLock); {
if (!NT_SUCCESS(Status)) Status = ObReferenceObjectByPointer(Process, PROCESS_ALL_ACCESS, NULL, KernelMode);
{ ExReleaseFastMutex(&RmapListLock);
return Status; if (!NT_SUCCESS(Status))
} {
MmLockAddressSpace(&Process->AddressSpace); return Status;
MemoryArea = MmOpenMemoryAreaByAddress(&Process->AddressSpace, Address); }
AddressSpace = &Process->AddressSpace;
}
else
{
AddressSpace = MmGetKernelAddressSpace();
}
MmLockAddressSpace(AddressSpace);
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace, Address);
Type = MemoryArea->Type; Type = MemoryArea->Type;
if (Type == MEMORY_AREA_SECTION_VIEW) if (Type == MEMORY_AREA_SECTION_VIEW)
{ {
@ -243,50 +273,59 @@ MmPageOutPhysicalAddress(PHYSICAL_ADDRESS PhysicalAddress)
if (PageOp->Thread != PsGetCurrentThread()) if (PageOp->Thread != PsGetCurrentThread())
{ {
MmReleasePageOp(PageOp); MmReleasePageOp(PageOp);
MmUnlockAddressSpace(&Process->AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); if (Address < (PVOID)KERNEL_BASE)
{
ObDereferenceObject(Process);
}
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
/* /*
* Release locks now we have a page op. * Release locks now we have a page op.
*/ */
MmUnlockAddressSpace(&Process->AddressSpace); MmUnlockAddressSpace(AddressSpace);
/* /*
* Do the actual page out work. * Do the actual page out work.
*/ */
Status = MmPageOutSectionView(&Process->AddressSpace, MemoryArea, Status = MmPageOutSectionView(AddressSpace, MemoryArea,
Address, PageOp); Address, PageOp);
} }
else if (Type == MEMORY_AREA_VIRTUAL_MEMORY) else if (Type == MEMORY_AREA_VIRTUAL_MEMORY)
{ {
PageOp = MmGetPageOp(MemoryArea, Process->UniqueProcessId, PageOp = MmGetPageOp(MemoryArea, Address < (PVOID)KERNEL_BASE ? Process->UniqueProcessId : 0,
Address, NULL, 0, MM_PAGEOP_PAGEOUT); Address, NULL, 0, MM_PAGEOP_PAGEOUT);
if (PageOp->Thread != PsGetCurrentThread()) if (PageOp->Thread != PsGetCurrentThread())
{ {
MmReleasePageOp(PageOp); MmReleasePageOp(PageOp);
MmUnlockAddressSpace(&Process->AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); if (Address < (PVOID)KERNEL_BASE)
{
ObDereferenceObject(Process);
}
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
/* /*
* Release locks now we have a page op. * Release locks now we have a page op.
*/ */
MmUnlockAddressSpace(&Process->AddressSpace); MmUnlockAddressSpace(AddressSpace);
/* /*
* Do the actual page out work. * Do the actual page out work.
*/ */
Status = MmPageOutVirtualMemory(&Process->AddressSpace, MemoryArea, Status = MmPageOutVirtualMemory(AddressSpace, MemoryArea,
Address, PageOp); Address, PageOp);
} }
else else
{ {
KeBugCheck(0); KeBugCheck(0);
} }
ObDereferenceObject(Process); if (Address < (PVOID)KERNEL_BASE)
{
ObDereferenceObject(Process);
}
return(Status); return(Status);
} }