Author: ros-arm-bringup
Date: Sun Jun 21 09:46:50 2009
New Revision: 41509
URL: http://svn.reactos.org/svn/reactos?rev=41509&view=rev
Log:
- Introduce a new MEMORY_AREA flag, MEMORY_AREA_STATIC:
- MEMORY_AREA structures are typically allocated from nonpaged pool, under the assumption it exists.
- However, nonpaged pool itself is described by a MEMORY_AREA. Right now, this MEMORY_AREA is created after nonpaged pool has been initialized (it is a miracle this works).
- This new flag allows MEMORY_AREA structures to be allocated statically, allowing the description of certain system address space components, themselves prerequisites to nonpaged pool creation, as well as the nonpaged pool component itself, before nonpaged pool has been initialized.
- This is not yet used.
Modified:
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/mm/marea.c
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Sun Jun 21 09:46:50 2009
@@ -28,6 +28,8 @@
struct _MM_PAGEOP;
typedef ULONG SWAPENTRY;
typedef ULONG PFN_TYPE, *PPFN_TYPE;
+
+#define MI_STATIC_MEMORY_AREAS (1)
#define MEMORY_AREA_INVALID (0)
#define MEMORY_AREA_SECTION_VIEW (1)
@@ -43,6 +45,7 @@
#define MEMORY_AREA_PAGED_POOL (12)
#define MEMORY_AREA_NO_ACCESS (13)
#define MEMORY_AREA_PEB_OR_TEB (14)
+#define MEMORY_AREA_STATIC (0x80000000)
#define MM_PHYSICAL_PAGE_MPW_PENDING (0x8)
Modified: trunk/reactos/ntoskrnl/mm/marea.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/marea.c?rev=41…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] Sun Jun 21 09:46:50 2009
@@ -49,6 +49,9 @@
#pragma alloc_text(INIT, MmInitMemoryAreas)
#endif
+MEMORY_AREA MiStaticMemoryAreas[MI_STATIC_MEMORY_AREAS];
+ULONG MiStaticMemoryAreaCount;
+
/* #define VALIDATE_MEMORY_AREAS */
/* FUNCTIONS *****************************************************************/
@@ -986,9 +989,28 @@
return STATUS_CONFLICTING_ADDRESSES;
}
}
-
- MemoryArea = ExAllocatePoolWithTag(NonPagedPool, sizeof(MEMORY_AREA),
- TAG_MAREA);
+
+ //
+ // Is this a static memory area?
+ //
+ if (Type & MEMORY_AREA_STATIC)
+ {
+ //
+ // Use the static array instead of the pool
+ //
+ ASSERT(MiStaticMemoryAreaCount < MI_STATIC_MEMORY_AREAS);
+ MemoryArea = &MiStaticMemoryAreas[MiStaticMemoryAreaCount++];
+ }
+ else
+ {
+ //
+ // Allocate the memory area from nonpaged pool
+ //
+ MemoryArea = ExAllocatePoolWithTag(NonPagedPool,
+ sizeof(MEMORY_AREA),
+ TAG_MAREA);
+ }
+
RtlZeroMemory(MemoryArea, sizeof(MEMORY_AREA));
MemoryArea->Type = Type;
MemoryArea->StartingAddress = *BaseAddress;
Author: ros-arm-bringup
Date: Sun Jun 21 09:33:48 2009
New Revision: 41508
URL: http://svn.reactos.org/svn/reactos?rev=41508&view=rev
Log:
- Define a new consumer: MC_SYSTEM:
- Right now, it is only used for allocating new page tables for kernel-mode mappings.
- This consumer's pages are never zeroed automatically (this is a more endemic ReactOS problem -- kernel pages are zeroed when they shouldn't be).
- New page tables, however, should indeed be zeroed, so now they are zeroed manually with RtlZeroMemory.
- The page zero function is not called anymore, and a useless zero-space hyperspace mapping is thus saved each time this happens.
- Because of this, zero-space hyperspace mappings are required much later in the Memory Manager's initialization steps than before.
Modified:
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/mm/freelist.c
trunk/reactos/ntoskrnl/mm/i386/page.c
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Sun Jun 21 09:33:48 2009
@@ -102,7 +102,8 @@
#define MC_USER (1)
#define MC_PPOOL (2)
#define MC_NPPOOL (3)
-#define MC_MAXIMUM (4)
+#define MC_SYSTEM (4)
+#define MC_MAXIMUM (5)
#define PAGED_POOL_MASK 1
#define MUST_SUCCEED_POOL_MASK 2
Modified: trunk/reactos/ntoskrnl/mm/freelist.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/freelist.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/freelist.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/freelist.c [iso-8859-1] Sun Jun 21 09:33:48 2009
@@ -777,7 +777,7 @@
KeReleaseQueuedSpinLock(LockQueuePfnLock, oldIrql);
PfnOffset = PageDescriptor - MmPfnDatabase;
- if (NeedClear)
+ if ((NeedClear) && (Consumer != MC_SYSTEM))
{
MiZeroPage(PfnOffset);
}
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/page.c?re…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] Sun Jun 21 09:33:48 2009
@@ -310,7 +310,7 @@
{
return NULL;
}
- Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
+ Status = MmRequestPageMemoryConsumer(MC_SYSTEM, FALSE, &Pfn);
if (!NT_SUCCESS(Status) || Pfn == 0)
{
KeBugCheck(MEMORY_MANAGEMENT);
@@ -322,8 +322,11 @@
}
if(0 != InterlockedCompareExchangePte(&MmGlobalKernelPageDirectory[PdeOffset], Entry, 0))
{
- MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
+ MmReleasePageMemoryConsumer(MC_SYSTEM, Pfn);
}
+ InterlockedExchangePte(PageDir, MmGlobalKernelPageDirectory[PdeOffset]);
+ RtlZeroMemory(MiPteToAddress(PageDir), PAGE_SIZE);
+ return (PULONG)MiAddressToPte(Address);
}
InterlockedExchangePte(PageDir, MmGlobalKernelPageDirectory[PdeOffset]);
}
Author: ros-arm-bringup
Date: Sun Jun 21 08:28:31 2009
New Revision: 41507
URL: http://svn.reactos.org/svn/reactos?rev=41507&view=rev
Log:
- Add another helper: MiGetPfnEntryIndex. This returns the page frame number (PFN) for a given MMPFN entry.
- Also add MiPteToAddress to complement MiAddressToPte. This returns the VA for a given PTE. Bonus points if you can figure out the bit magic.
Modified:
trunk/reactos/ntoskrnl/include/internal/i386/mm.h
trunk/reactos/ntoskrnl/include/internal/mm.h
Modified: trunk/reactos/ntoskrnl/include/internal/i386/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/i386/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/i386/mm.h [iso-8859-1] Sun Jun 21 08:28:31 2009
@@ -23,6 +23,11 @@
#define MiAddressToPteOffset(x) \
((((ULONG)(x)) << 10) >> 22)
+//
+// Convert a PTE into a corresponding address
+//
+#define MiPteToAddress(PTE) ((PVOID)((ULONG)(PTE) << 10))
+
#define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (1024 * PAGE_SIZE))
#define ADDR_TO_PDE_OFFSET(v) ((((ULONG)(v)) / (1024 * PAGE_SIZE)))
#define ADDR_TO_PTE_OFFSET(v) ((((ULONG)(v)) % (1024 * PAGE_SIZE)) / PAGE_SIZE)
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Sun Jun 21 08:28:31 2009
@@ -1050,6 +1050,16 @@
return Page;
};
+FORCEINLINE
+PFN_NUMBER
+MiGetPfnEntryIndex(IN PMMPFN Pfn1)
+{
+ //
+ // This will return the Page Frame Number (PFN) from the MMPFN
+ //
+ return Pfn1 - MmPfnDatabase;
+}
+
PFN_TYPE
NTAPI
MmGetLRUNextUserPage(PFN_TYPE PreviousPage);
Author: ros-arm-bringup
Date: Sun Jun 21 08:09:25 2009
New Revision: 41505
URL: http://svn.reactos.org/svn/reactos?rev=41505&view=rev
Log:
- It is very possible for MiGetPfnEntry to be called for a page above the page array size, since not all pages are represented in the array. In this scenario, MiGetPfnEntry should return NULL (and the caller should be prepared for this scenario).
- Also move out the extern definitions outside of the inline, so that other functions may access them and consequently removing a needless UNREFERENCED_PARAMETER.
Modified:
trunk/reactos/ntoskrnl/include/internal/mm.h
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Sun Jun 21 08:09:25 2009
@@ -352,6 +352,9 @@
} u4;
} MMPFN, *PMMPFN;
+extern PMMPFN MmPageArray;
+extern ULONG MmPageArraySize;
+
extern MM_STATS MmStats;
typedef struct _MM_PAGEOP
@@ -1036,14 +1039,9 @@
MiGetPfnEntry(IN PFN_TYPE Pfn)
{
PMMPFN Page;
- extern PMMPFN MmPageArray;
- extern ULONG MmPageArraySize;
-
- /* Mark MmPageArraySize as unreferenced, otherwise it will appear as an unused variable on a Release build */
- UNREFERENCED_PARAMETER(MmPageArraySize);
/* Make sure the PFN number is valid */
- ASSERT(Pfn <= MmPageArraySize);
+ if (Pfn > MmPageArraySize) return NULL;
/* Get the entry */
Page = &MmPageArray[Pfn];