Author: ros-arm-bringup
Date: Fri Feb 15 09:53:49 2008
New Revision: 32374
URL: http://svn.reactos.org/svn/reactos?rev=32374&view=rev
Log:
Remove Ke386Pae conditionals from page code -- PAE is never turned on ReactOS (and probably wouldn't work), so there's no point in wasting CPU cycles and making the code even more unredable by having the PAE code there.
The PAE implementation has been moved to pagepae.c, in case someone will ever want to revive.
Even in that case, it's recommended to build two kernels like everyone else does, instead of doing runtime conditionals for every single page operation.
Added:
trunk/reactos/ntoskrnl/mm/i386/pagepae.c (with props)
Modified:
trunk/reactos/ntoskrnl/mm/i386/page.c
[This mail would be too long, it was shortened to contain the URLs only.]
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/page.c?re…
Added: trunk/reactos/ntoskrnl/mm/i386/pagepae.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/pagepae.c…
Author: ros-arm-bringup
Date: Fri Feb 15 09:49:59 2008
New Revision: 32373
URL: http://svn.reactos.org/svn/reactos?rev=32373&view=rev
Log:
Christ! Don't zero out the shared memory page during Virtual Memory initialization! The page is already well in-use by the time we were zeroing it out, and this is also the reason why all the attempts to move MmInit1 into MmInitSystem had previously failed -- the NtSystemRoot path would get written during initialization (But before MmInitSystem), and MmInit1 would then zero out the entire structure.
Not only does this allow us to do MmInit1 in MmInitSystem, where it should be, but it also fixes the fact that several KUSER_SHARED_DATA flags were being zeroed out.
As an added benefit, ARM/PPC ports now need to worry about Mm much later then before (well after the HAL has initialized and interrupts are enabled).
Modified:
trunk/reactos/ntoskrnl/ex/init.c
trunk/reactos/ntoskrnl/ke/i386/kiinit.c
trunk/reactos/ntoskrnl/mm/mminit.c
Modified: trunk/reactos/ntoskrnl/ex/init.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=323…
==============================================================================
(empty)
Modified: trunk/reactos/ntoskrnl/ke/i386/kiinit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/kiinit.c?…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/kiinit.c (original)
+++ trunk/reactos/ntoskrnl/ke/i386/kiinit.c Fri Feb 15 09:49:59 2008
@@ -536,9 +536,6 @@
/* HACK for MmUpdatePageDir */
((PETHREAD)InitThread)->ThreadsProcess = (PEPROCESS)InitProcess;
- /* Initialize Kernel Memory Address Space */
- MmInit1();
-
/* Set basic CPU Features that user mode can read */
SharedUserData->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] =
(KeFeatureBits & KF_MMX) ? TRUE: FALSE;
Modified: trunk/reactos/ntoskrnl/mm/mminit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=3…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mminit.c (original)
+++ trunk/reactos/ntoskrnl/mm/mminit.c Fri Feb 15 09:49:59 2008
@@ -182,7 +182,6 @@
0,
BoundaryAddressMultiple);
MmSharedDataPagePhysicalAddress.QuadPart = 2 << PAGE_SHIFT;
- RtlZeroMemory(BaseAddress, Length);
/*
*
@@ -420,6 +419,9 @@
ULONG Flags = 0;
if (Phase == 0)
{
+ /* Initialize Mm bootstrap */
+ MmInit1();
+
/* Initialize the Loader Lock */
KeInitializeMutant(&MmSystemLoadLock, FALSE);
Author: ros-arm-bringup
Date: Fri Feb 15 03:31:18 2008
New Revision: 32369
URL: http://svn.reactos.org/svn/reactos?rev=32369&view=rev
Log:
Fixed some bugs we introduced by incorrectly double-accounting the PFN database. The database is *virtually* continous and follows the kernel address region, but not physically -- physically, it is at the very far end of memory.
Unfortunately, fixing this bug now caused any unused memory in the FreeLDR-mapped region of 6MB to appear...well...unused. This would normally be a good thing, except ReactOS started crashing.
We fixed it by applying the Glorious Hack. See freelist.c:359.
Modified:
trunk/reactos/ntoskrnl/mm/freelist.c
trunk/reactos/ntoskrnl/mm/mminit.c
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 (original)
+++ trunk/reactos/ntoskrnl/mm/freelist.c Fri Feb 15 03:31:18 2008
@@ -356,6 +356,22 @@
KernelPageStart = KernelStart / PAGE_SIZE;
KernelPageEnd = KernelEnd / PAGE_SIZE;
+ // Glorious Hack:
+ // The kernel seems to crash if the region of memory that FreeLDR maps
+ // (those evil 6MB) is not *entirely* marked "in use", even though only
+ // 3 or 4MB of it may actually be in use.
+ // This wasn't noticed before, because the PFN database pages which are
+ // *VIRTUALLY* continous after the kernel end were also marked as
+ // *PHYSICALLY* continous (even though they were allocated at the very far
+ // end of physical memory).
+ //
+ // So we'll simply gobble up whatever is left of what FreeLDR mapped.
+ //
+ // PS. This is really sinister
+ //
+ KernelEnd += (KernelStart + 0x600000) - KernelEnd;
+ KernelPageEnd = KernelEnd / PAGE_SIZE;
+
/* Loop every page on the system */
for (i = 0; i <= MmPageArraySize; i++)
{
@@ -437,6 +453,7 @@
KeInitializeEvent(&ZeroPageThreadEvent, NotificationEvent, TRUE);
+ DPRINT("Pages: %x %x\n", MmStats.NrFreePages, MmStats.NrSystemPages);
MmStats.NrTotalPages = MmStats.NrFreePages + MmStats.NrSystemPages + MmStats.NrUserPages;
MmInitializeBalancer(MmStats.NrFreePages, MmStats.NrSystemPages);
}
Modified: trunk/reactos/ntoskrnl/mm/mminit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=3…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mminit.c (original)
+++ trunk/reactos/ntoskrnl/mm/mminit.c Fri Feb 15 03:31:18 2008
@@ -53,6 +53,7 @@
ULONG MmNumberOfPhysicalPages, MmHighestPhysicalPage, MmLowestPhysicalPage;
ULONG_PTR MiKSeg0Start, MiKSeg0End;
PVOID MmPfnDatabase;
+ULONG_PTR MmPfnDatabaseEnd;
PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
extern KMUTANT MmSystemLoadLock;
BOOLEAN MiDbgEnableMdDump =
@@ -257,14 +258,14 @@
KSEG0_BASE, MiKSeg0Start,
"Undefined region");
DPRINT1("0x%p - 0x%p\t%s\n",
- MiKSeg0Start, MmPfnDatabase,
+ MiKSeg0Start, MiKSeg0End,
"FreeLDR Kernel mapping region");
DPRINT1("0x%p - 0x%p\t%s\n",
- MmPfnDatabase, MiKSeg0End,
+ MmPfnDatabase, MmPfnDatabaseEnd,
"PFN Database region");
- if (MiKSeg0End != (ULONG_PTR)MiNonPagedPoolStart)
+ if (MmPfnDatabaseEnd != (ULONG_PTR)MiNonPagedPoolStart)
DPRINT1("0x%p - 0x%p\t%s\n",
- MiKSeg0End, MiNonPagedPoolStart,
+ MmPfnDatabaseEnd, MiNonPagedPoolStart,
"Remaining FreeLDR mapping");
DPRINT1("0x%p - 0x%p\t%s\n",
MiNonPagedPoolStart, (ULONG_PTR)MiNonPagedPoolStart + MiNonPagedPoolLength,
@@ -347,7 +348,7 @@
PLDR_DATA_TABLE_ENTRY LdrEntry;
/* Dump memory descriptors */
- if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
+ if (TRUE) MiDbgDumpMemoryDescriptors();
if (MiDbgEnableMdDump) MiDbgDumpBiosMap(BIOSMemoryMap, AddressRangeCount);
/* Set the page directory */
@@ -386,8 +387,8 @@
/* We'll put the PFN array right after the loaded modules */
MmPfnDatabase = (PVOID)MiKSeg0End;
- MiKSeg0End += MmHighestPhysicalPage * sizeof(PHYSICAL_PAGE);
- MiKSeg0End = PAGE_ROUND_UP(MiKSeg0End);
+ MmPfnDatabaseEnd = (ULONG_PTR)MmPfnDatabase + (MmHighestPhysicalPage * sizeof(PHYSICAL_PAGE));
+ MmPfnDatabaseEnd = PAGE_ROUND_UP(MmPfnDatabaseEnd);
/*
* FreeLDR maps 6MB starting at the kernel base address, followed by the
@@ -395,15 +396,15 @@
* then choose the end of the FreeLDR block. If it does go past the FreeLDR
* allocation, then choose the next PAGE_SIZE boundary.
*/
- if (MiKSeg0End < (MiKSeg0Start + 0x600000))
+ if ((ULONG_PTR)MmPfnDatabaseEnd < (MiKSeg0Start + 0x600000))
{
/* Use the first memory following FreeLDR's 6MB mapping */
- MiNonPagedPoolStart = (PVOID)PAGE_ROUND_UP(MiKSeg0Start + 0x600000);
+ MiNonPagedPoolStart = (PVOID)((ULONG_PTR)MiKSeg0Start + 0x600000);
}
else
{
/* Use the next free available page */
- MiNonPagedPoolStart = (PVOID)MiKSeg0End;
+ MiNonPagedPoolStart = (PVOID)MmPfnDatabaseEnd;
}
/* Length of non-paged pool */