-/* $Id: page.c 32364 2008-02-14 20:30:31Z ros-arm-bringup $
- *
+/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/i386/page.c
#include <ntoskrnl.h>
#define NDEBUG
-#include <internal/debug.h>
+#include <debug.h>
#if defined (ALLOC_PRAGMA)
#pragma alloc_text(INIT, MmInitGlobalKernelPageDirectory)
NTAPI
MiFlushTlbIpiRoutine(ULONG_PTR Address)
{
- if (Address == (ULONG_PTR)-1)
+ if (Address == (ULONGLONG)-1)
{
KeFlushCurrentTb();
}
- else if (Address == (ULONG_PTR)-2)
+ else if (Address == (ULONGLONG)-2)
{
KeFlushCurrentTb();
}
else
{
DPRINT1("Unknown main protection type.\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (Ke386NoExecute &&
!(flProtect & PAGE_IS_EXECUTABLE))
}
BOOLEAN
-STDCALL
+NTAPI
MmCreateProcessAddressSpace(IN ULONG MinWs,
IN PEPROCESS Process,
IN PLARGE_INTEGER DirectoryTableBase)
{
NTSTATUS Status;
ULONG i, j;
- PFN_TYPE Pfn[7];
+ PFN_NUMBER Pfn[7];
ULONG Count;
DPRINT("MmCopyMmInfo(Src %x, Dest %x)\n", MinWs, Process);
}
if (Address >= MmSystemRangeStart)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
// MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] = 0;
}
if (Process != NULL && Process != CurrentProcess)
{
PEPROCESS CurrentProcess = PsGetCurrentProcess();
ULONG i;
- PFN_TYPE Pfn;
+ PFN_NUMBER Pfn;
DPRINT("ProcessId %d, Address %x\n", Process->UniqueProcessId, Address);
if (Process != NULL && Process != CurrentProcess)
{
DbgPrint("Page table entry not clear at %x/%x (is %I64x)\n",
((ULONG)Address / (4*1024*1024)), i, PageTable[i]);
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
Pfn = PAE_PTE_TO_PFN(*(PAE_ADDR_TO_PDE(Address)));
{
DbgPrint("Page table entry not clear at %x/%x (is %x)\n",
((ULONG)Address / (4*1024*1024)), i, PageTable[i]);
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
Pfn = PTE_TO_PFN(*(ADDR_TO_PDE(Address)));
if (Address >= MmSystemRangeStart)
{
// MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] = 0;
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
else
{
MmGetPageTableForProcessForPAE(PEPROCESS Process, PVOID Address, BOOLEAN Create)
{
NTSTATUS Status;
- PFN_TYPE Pfn;
+ PFN_NUMBER Pfn;
ULONGLONG Entry;
ULONGLONG ZeroEntry = 0LL;
PULONGLONG Pt;
Process, Address, Create);
if (Address >= (PVOID)PAGETABLE_MAP && Address < (PVOID)((ULONG_PTR)PAGETABLE_MAP + 0x800000))
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (Address < MmSystemRangeStart && Process && Process != PsGetCurrentProcess())
{
PageDirTable = MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(Process->Pcb.DirectoryTableBase.QuadPart));
if (PageDirTable == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
PageDir = MmCreateHyperspaceMapping(PAE_PTE_TO_PFN(PageDirTable[PAE_ADDR_TO_PDTE_OFFSET(Address)]));
MmDeleteHyperspaceMapping(PageDirTable);
if (PageDir == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
PageDir += PAE_ADDR_TO_PDE_PAGE_OFFSET(Address);
Entry = ExfInterlockedCompareExchange64UL(PageDir, &ZeroEntry, &ZeroEntry);
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status))
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER;
Entry = ExfInterlockedCompareExchange64UL(PageDir, &Entry, &ZeroEntry);
Pt = MmCreateHyperspaceMapping(Pfn);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
return Pt + PAE_ADDR_TO_PTE_OFFSET(Address);
}
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status))
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
Entry = PAE_PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE;
if (Ke386GlobalPagesEnabled)
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status))
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER;
Entry = ExfInterlockedCompareExchange64UL(PageDir, &Entry, &ZeroEntry);
{
ULONG PdeOffset = ADDR_TO_PDE_OFFSET(Address);
NTSTATUS Status;
- PFN_TYPE Pfn;
+ PFN_NUMBER Pfn;
ULONG Entry;
PULONG Pt, PageDir;
PageDir = MmCreateHyperspaceMapping(PTE_TO_PFN(Process->Pcb.DirectoryTableBase.LowPart));
if (PageDir == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (0 == InterlockedCompareExchangeUL(&PageDir[PdeOffset], 0, 0))
{
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status) || Pfn == 0)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
Entry = InterlockedCompareExchangeUL(&PageDir[PdeOffset], PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
if (Entry != 0)
Pt = MmCreateHyperspaceMapping(Pfn);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
return Pt + ADDR_TO_PTE_OFFSET(Address);
}
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status) || Pfn == 0)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE;
if (Ke386GlobalPagesEnabled)
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
if (!NT_SUCCESS(Status) || Pfn == 0)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
Entry = InterlockedCompareExchangeUL(PageDir, PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
if (Entry != 0)
return 0;
}
-PFN_TYPE
+PFN_NUMBER
NTAPI
MmGetPfnForProcess(PEPROCESS Process,
PVOID Address)
VOID
NTAPI
-MmDisableVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN* WasDirty, PPFN_TYPE Page)
+MmDisableVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN* WasDirty, PPFN_NUMBER Page)
/*
* FUNCTION: Delete a virtual mapping
*/
Pt = MmGetPageTableForProcessForPAE(Process, Address, FALSE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
/*
* Atomically disable the present bit and get the old value.
WasValid = PAE_PAGE_MASK(Pte) != 0LL ? TRUE : FALSE;
if (!WasValid)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
/*
Pt = MmGetPageTableForProcess(Process, Address, FALSE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
/*
* Atomically disable the present bit and get the old value.
WasValid = (PAGE_MASK(Pte) != 0);
if (!WasValid)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
/*
VOID
NTAPI
MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN FreePage,
- BOOLEAN* WasDirty, PPFN_TYPE Page)
+ BOOLEAN* WasDirty, PPFN_NUMBER Page)
/*
* FUNCTION: Delete a virtual mapping
*/
{
BOOLEAN WasValid = FALSE;
- PFN_TYPE Pfn;
+ PFN_NUMBER Pfn;
DPRINT("MmDeleteVirtualMapping(%x, %x, %d, %x, %x)\n",
Process, Address, FreePage, WasDirty, Page);
if (Address < MmSystemRangeStart && Process == NULL)
{
DPRINT1("MmIsAccessedAndResetAccessPage is called for user space without a process.\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (Ke386Pae)
{
Pt = MmGetPageTableForProcessForPAE(Process, Address, FALSE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
do
Pt = MmGetPageTableForProcess(Process, Address, FALSE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
do
if (Address < MmSystemRangeStart && Process == NULL)
{
DPRINT1("MmSetCleanPage is called for user space without a process.\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (Ke386Pae)
{
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
do
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
do
if (Address < MmSystemRangeStart && Process == NULL)
{
DPRINT1("MmSetDirtyPage is called for user space without a process.\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (Ke386Pae)
{
Pt = MmGetPageTableForProcessForPAE(Process, Address, FALSE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
do
Pt = MmGetPageTableForProcess(Process, Address, FALSE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
do
Pt = MmGetPageTableForProcessForPAE(Process, Address, FALSE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
do
Pt = MmGetPageTableForProcess(Process, Address, FALSE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
do
NTAPI
MmCreateVirtualMappingForKernel(PVOID Address,
ULONG flProtect,
- PPFN_TYPE Pages,
+ PPFN_NUMBER Pages,
ULONG PageCount)
{
ULONG Attributes;
if (Address < MmSystemRangeStart)
{
DPRINT1("MmCreateVirtualMappingForKernel is called for user space\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
Attributes = ProtectToPTE(flProtect);
DPRINT1("Setting physical address but not allowing access at address "
"0x%.8X with attributes %x/%x.\n",
Addr, Attributes, flProtect);
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
PdeOffset = PAE_ADDR_TO_PDE_OFFSET(Addr);
Pt = MmGetPageTableForProcessForPAE(NULL, Addr, TRUE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
else
Pte = ExfpInterlockedExchange64UL(Pt, &Pte);
if (Pte != 0LL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
}
Pt = MmGetPageTableForProcess(NULL, Addr, TRUE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
Pt--;
DPRINT1("Setting physical address but not allowing access at address "
"0x%.8X with attributes %x/%x.\n",
Addr, Attributes, flProtect);
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
PdeOffset = ADDR_TO_PDE_OFFSET(Addr);
Pt = MmGetPageTableForProcess(NULL, Addr, TRUE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
else
Pte = *Pt;
if (Pte != 0)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
(void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
}
if (Process == NULL && Address < MmSystemRangeStart)
{
DPRINT1("No process\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (Process != NULL && Address >= MmSystemRangeStart)
{
DPRINT1("Setting kernel address with process context\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (SwapEntry & (1 << 31))
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (Ke386Pae)
Pt = MmGetPageTableForProcessForPAE(Process, Address, TRUE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
tmpPte = SwapEntry << 1;
Pte = ExfpInterlockedExchange64UL(Pt, &tmpPte);
Pt = MmGetPageTableForProcess(Process, Address, TRUE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
Pte = *Pt;
if (PAGE_MASK((Pte)) != 0)
MmCreateVirtualMappingUnsafe(PEPROCESS Process,
PVOID Address,
ULONG flProtect,
- PPFN_TYPE Pages,
+ PPFN_NUMBER Pages,
ULONG PageCount)
{
ULONG Attributes;
if (Address < MmSystemRangeStart)
{
DPRINT1("No process\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (PageCount > 0x10000 ||
(ULONG_PTR) Address / PAGE_SIZE + PageCount > 0x100000)
{
DPRINT1("Page count to large\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
else
if (Address >= MmSystemRangeStart)
{
DPRINT1("Setting kernel address with process context\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (PageCount > (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE ||
(ULONG_PTR) Address / PAGE_SIZE + PageCount >
(ULONG_PTR)MmSystemRangeStart / PAGE_SIZE)
{
DPRINT1("Page Count to large\n");
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
DPRINT1("Setting physical address but not allowing access at address "
"0x%.8X with attributes %x/%x.\n",
Addr, Attributes, flProtect);
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
PdeOffset = PAE_ADDR_TO_PDE_OFFSET(Addr);
if (oldPdeOffset != PdeOffset)
Pt = MmGetPageTableForProcessForPAE(Process, Addr, TRUE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
else
Pte = ExfpInterlockedExchange64UL(Pt, &tmpPte);
if (PAE_PAGE_MASK((Pte)) != 0LL && !((Pte) & PA_PRESENT))
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (PAE_PAGE_MASK((Pte)) != 0LL)
{
DPRINT1("Setting physical address but not allowing access at address "
"0x%.8X with attributes %x/%x.\n",
Addr, Attributes, flProtect);
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
PdeOffset = ADDR_TO_PDE_OFFSET(Addr);
if (oldPdeOffset != PdeOffset)
Pt = MmGetPageTableForProcess(Process, Addr, TRUE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
else
MmMarkPageMapped(Pages[i]);
if (PAGE_MASK((Pte)) != 0 && !((Pte) & PA_PRESENT))
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (PAGE_MASK((Pte)) != 0)
{
MmCreateVirtualMapping(PEPROCESS Process,
PVOID Address,
ULONG flProtect,
- PPFN_TYPE Pages,
+ PPFN_NUMBER Pages,
ULONG PageCount)
{
ULONG i;
if (!MmIsPageInUse(Pages[i]))
{
DPRINT1("Page at address %x not in use\n", PFN_TO_PTE(Pages[i]));
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
if (Pt == NULL)
{
DPRINT1("Address %x\n", Address);
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
do
{
Pt = MmGetPageTableForProcess(Process, Address, FALSE);
if (Pt == NULL)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
InterlockedExchange((PLONG)Pt, PAGE_MASK(*Pt) | Attributes | (*Pt & (PA_ACCESSED|PA_DIRTY)));
MiFlushTlb(Pt, Address);
/*
* @implemented
*/
-PHYSICAL_ADDRESS STDCALL
+PHYSICAL_ADDRESS NTAPI
MmGetPhysicalAddress(PVOID vaddr)
/*
* FUNCTION: Returns the physical address corresponding to a virtual address
PVOID
NTAPI
-MmCreateHyperspaceMapping(PFN_TYPE Page)
+MmCreateHyperspaceMapping(PFN_NUMBER Page)
{
PVOID Address;
ULONG i;
}
if (i >= Page % 1024)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
}
}
if (i <= Page % 1024)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
}
}
if (i >= Page % 1024)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
}
}
if (i <= Page % 1024)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}
}
return Address;
}
-PFN_TYPE
+PFN_NUMBER
NTAPI
-MmChangeHyperspaceMapping(PVOID Address, PFN_TYPE NewPage)
+MmChangeHyperspaceMapping(PVOID Address, PFN_NUMBER NewPage)
{
- PFN_TYPE Pfn;
+ PFN_NUMBER Pfn;
ASSERT (IS_HYPERSPACE(Address));
if (Ke386Pae)
{
return Pfn;
}
-PFN_TYPE
+PFN_NUMBER
NTAPI
MmDeleteHyperspaceMapping(PVOID Address)
{
- PFN_TYPE Pfn;
+ PFN_NUMBER Pfn;
ASSERT (IS_HYPERSPACE(Address));
if (Ke386Pae)
{
if (Address < MmSystemRangeStart)
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
if (Ke386Pae)
{
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
BaseAddress = (PVOID)HYPERSPACE;
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
- KEBUGCHECK(0);
+ ASSERT(FALSE);
}
}