mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 21:42:57 +00:00
[NTOS:MM] Use MI_MAKE_HARDWARE_PTE & friends in legacy Mm
This commit is contained in:
parent
43378411fb
commit
b10d92a16c
1 changed files with 29 additions and 64 deletions
|
@ -15,9 +15,6 @@
|
||||||
|
|
||||||
#include <mm/ARM3/miarm.h>
|
#include <mm/ARM3/miarm.h>
|
||||||
|
|
||||||
#define ADDR_TO_PDE_OFFSET MiAddressToPdeOffset
|
|
||||||
#define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (1024 * PAGE_SIZE))
|
|
||||||
|
|
||||||
/* GLOBALS *****************************************************************/
|
/* GLOBALS *****************************************************************/
|
||||||
|
|
||||||
#define PA_BIT_PRESENT (0)
|
#define PA_BIT_PRESENT (0)
|
||||||
|
@ -134,47 +131,6 @@ ULONG MmProtectToValue[32] =
|
||||||
|
|
||||||
/* FUNCTIONS ***************************************************************/
|
/* FUNCTIONS ***************************************************************/
|
||||||
|
|
||||||
static ULONG
|
|
||||||
ProtectToPTE(ULONG flProtect)
|
|
||||||
{
|
|
||||||
ULONG Attributes = 0;
|
|
||||||
|
|
||||||
if (flProtect & (PAGE_NOACCESS|PAGE_GUARD))
|
|
||||||
{
|
|
||||||
Attributes = 0;
|
|
||||||
}
|
|
||||||
else if (flProtect & PAGE_IS_WRITABLE)
|
|
||||||
{
|
|
||||||
Attributes = PA_PRESENT | PA_READWRITE;
|
|
||||||
}
|
|
||||||
else if (flProtect & (PAGE_IS_READABLE | PAGE_IS_EXECUTABLE))
|
|
||||||
{
|
|
||||||
Attributes = PA_PRESENT;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT1("Unknown main protection type.\n");
|
|
||||||
KeBugCheck(MEMORY_MANAGEMENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flProtect & PAGE_SYSTEM)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Attributes = Attributes | PA_USER;
|
|
||||||
}
|
|
||||||
if (flProtect & PAGE_NOCACHE)
|
|
||||||
{
|
|
||||||
Attributes = Attributes | PA_CD;
|
|
||||||
}
|
|
||||||
if (flProtect & PAGE_WRITETHROUGH)
|
|
||||||
{
|
|
||||||
Attributes = Attributes | PA_WT;
|
|
||||||
}
|
|
||||||
return(Attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
MiFillSystemPageDirectory(IN PVOID Base,
|
MiFillSystemPageDirectory(IN PVOID Base,
|
||||||
|
@ -591,15 +547,22 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
|
||||||
ULONG flProtect,
|
ULONG flProtect,
|
||||||
PFN_NUMBER Page)
|
PFN_NUMBER Page)
|
||||||
{
|
{
|
||||||
ULONG Attributes;
|
ULONG ProtectionMask;
|
||||||
PMMPTE PointerPte;
|
PMMPTE PointerPte;
|
||||||
ULONG Pte;
|
MMPTE TempPte;
|
||||||
|
ULONG_PTR Pte;
|
||||||
|
|
||||||
DPRINT("MmCreateVirtualMappingUnsafe(%p, %p, %lu, %x)\n",
|
DPRINT("MmCreateVirtualMappingUnsafe(%p, %p, %lu, %x)\n",
|
||||||
Process, Address, flProtect, Page);
|
Process, Address, flProtect, Page);
|
||||||
|
|
||||||
ASSERT(((ULONG_PTR)Address % PAGE_SIZE) == 0);
|
ASSERT(((ULONG_PTR)Address % PAGE_SIZE) == 0);
|
||||||
|
|
||||||
|
ProtectionMask = MiMakeProtectionMask(flProtect);
|
||||||
|
/* Caller must have checked ! */
|
||||||
|
ASSERT(ProtectionMask != MM_INVALID_PROTECTION);
|
||||||
|
ASSERT(ProtectionMask != MM_NOACCESS);
|
||||||
|
ASSERT(ProtectionMask != MM_ZERO_ACCESS);
|
||||||
|
|
||||||
/* Make sure our PDE is valid, and that everything is going fine */
|
/* Make sure our PDE is valid, and that everything is going fine */
|
||||||
if (Process == NULL)
|
if (Process == NULL)
|
||||||
{
|
{
|
||||||
|
@ -626,22 +589,18 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
|
||||||
MiMakePdeExistAndMakeValid(MiAddressToPde(Address), Process, MM_NOIRQL);
|
MiMakePdeExistAndMakeValid(MiAddressToPde(Address), Process, MM_NOIRQL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Attributes = ProtectToPTE(flProtect);
|
PointerPte = MiAddressToPte(Address);
|
||||||
Attributes &= 0xfff;
|
|
||||||
if (Address >= MmSystemRangeStart)
|
if (Address >= MmSystemRangeStart)
|
||||||
{
|
{
|
||||||
Attributes &= ~PA_USER;
|
MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte, PointerPte, ProtectionMask, Page);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Attributes |= PA_USER;
|
MI_MAKE_HARDWARE_PTE_USER(&TempPte, PointerPte, ProtectionMask, Page);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This must be for a valid address */
|
Pte = InterlockedExchangePte(PointerPte, TempPte.u.Long);
|
||||||
ASSERT(FlagOn(Attributes, PA_PRESENT));
|
|
||||||
|
|
||||||
PointerPte = MiAddressToPte(Address);
|
|
||||||
Pte = InterlockedExchangePte(PointerPte, PFN_TO_PTE(Page) | Attributes);
|
|
||||||
/* There should not have been anything valid here */
|
/* There should not have been anything valid here */
|
||||||
if (Pte != 0)
|
if (Pte != 0)
|
||||||
{
|
{
|
||||||
|
@ -752,9 +711,10 @@ VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
|
MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
|
||||||
{
|
{
|
||||||
ULONG Attributes = 0;
|
ULONG ProtectionMask;
|
||||||
PMMPTE PointerPte;
|
PMMPTE PointerPte;
|
||||||
ULONG Pte;
|
MMPTE TempPte;
|
||||||
|
ULONG_PTR Pte;
|
||||||
|
|
||||||
DPRINT("MmSetPageProtect(Process %p Address %p flProtect %x)\n",
|
DPRINT("MmSetPageProtect(Process %p Address %p flProtect %x)\n",
|
||||||
Process, Address, flProtect);
|
Process, Address, flProtect);
|
||||||
|
@ -764,17 +724,22 @@ MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
|
||||||
|
|
||||||
ASSERT(Process == PsGetCurrentProcess());
|
ASSERT(Process == PsGetCurrentProcess());
|
||||||
|
|
||||||
|
ProtectionMask = MiMakeProtectionMask(flProtect);
|
||||||
|
/* Caller must have checked ! */
|
||||||
|
ASSERT(ProtectionMask != MM_INVALID_PROTECTION);
|
||||||
|
|
||||||
MiLockProcessWorkingSetUnsafe(Process, PsGetCurrentThread());
|
MiLockProcessWorkingSetUnsafe(Process, PsGetCurrentThread());
|
||||||
|
|
||||||
MiMakePdeExistAndMakeValid(MiAddressToPde(Address), Process, MM_NOIRQL);
|
MiMakePdeExistAndMakeValid(MiAddressToPde(Address), Process, MM_NOIRQL);
|
||||||
|
|
||||||
Attributes = ProtectToPTE(flProtect);
|
|
||||||
|
|
||||||
Attributes &= 0xfff;
|
|
||||||
Attributes |= PA_USER;
|
|
||||||
|
|
||||||
PointerPte = MiAddressToPte(Address);
|
PointerPte = MiAddressToPte(Address);
|
||||||
Pte = InterlockedExchangePte(PointerPte, PAGE_MASK(PointerPte->u.Long) | Attributes | (PointerPte->u.Long & (PA_ACCESSED|PA_DIRTY)));
|
|
||||||
|
MI_MAKE_HARDWARE_PTE_USER(&TempPte, PointerPte, ProtectionMask, PFN_FROM_PTE(PointerPte));
|
||||||
|
/* Keep dirty & accessed bits */
|
||||||
|
TempPte.u.Hard.Accessed = PointerPte->u.Hard.Accessed;
|
||||||
|
TempPte.u.Hard.Dirty = PointerPte->u.Hard.Dirty;
|
||||||
|
|
||||||
|
Pte = InterlockedExchangePte(PointerPte, TempPte.u.Long);
|
||||||
|
|
||||||
// We should be able to bring a page back from PAGE_NOACCESS
|
// We should be able to bring a page back from PAGE_NOACCESS
|
||||||
if ((Pte & 0x800) || !(Pte >> PAGE_SHIFT))
|
if ((Pte & 0x800) || !(Pte >> PAGE_SHIFT))
|
||||||
|
@ -783,7 +748,7 @@ MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
|
||||||
KeBugCheck(MEMORY_MANAGEMENT);
|
KeBugCheck(MEMORY_MANAGEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Pte & 0xFFF) != Attributes)
|
if (Pte != TempPte.u.Long)
|
||||||
KeInvalidateTlbEntry(Address);
|
KeInvalidateTlbEntry(Address);
|
||||||
|
|
||||||
MiUnlockProcessWorkingSetUnsafe(Process, PsGetCurrentThread());
|
MiUnlockProcessWorkingSetUnsafe(Process, PsGetCurrentThread());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue