Author: fireball
Date: Fri Feb 8 13:55:40 2008
New Revision: 32214
URL:
http://svn.reactos.org/svn/reactos?rev=32214&view=rev
Log:
- Implement MiCountFreePagesInLoaderBlock() to correctly count free pages (instead of
using a variable introduced somewhere below r2000 (MemHigher), and later converted to
MmFreeLdrMemHigher).
- Get rid of MmFreeLdrMemHigher and MmFreeLdrMemLower (they were not actually used for
anything except getting number of free pages).
Modified:
trunk/reactos/include/reactos/rosldr.h
trunk/reactos/ntoskrnl/ke/freeldr.c
trunk/reactos/ntoskrnl/mm/mminit.c
Modified: trunk/reactos/include/reactos/rosldr.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/rosldr.h?r…
==============================================================================
--- trunk/reactos/include/reactos/rosldr.h (original)
+++ trunk/reactos/include/reactos/rosldr.h Fri Feb 8 13:55:40 2008
@@ -45,7 +45,6 @@
ULONG ArchExtra;
} ROS_LOADER_PARAMETER_BLOCK, *PROS_LOADER_PARAMETER_BLOCK;
-extern ULONG MmFreeLdrMemHigher, MmFreeLdrMemLower;
extern BOOLEAN AcpiTableDetected;
extern ULONG MmFreeLdrPageDirectoryStart, MmFreeLdrPageDirectoryEnd;
Modified: trunk/reactos/ntoskrnl/ke/freeldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/freeldr.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/freeldr.c (original)
+++ trunk/reactos/ntoskrnl/ke/freeldr.c Fri Feb 8 13:55:40 2008
@@ -32,7 +32,6 @@
/* FreeLDR Memory Data */
ULONG_PTR MmFreeLdrFirstKrnlPhysAddr, MmFreeLdrLastKrnlPhysAddr;
ULONG_PTR MmFreeLdrLastKernelAddress;
-ULONG MmFreeLdrMemHigher;
ULONG MmFreeLdrPageDirectoryEnd;
/* FreeLDR Loader Data */
@@ -926,7 +925,6 @@
/* First get some kernel-loader globals */
AcpiTableDetected = (RosLoaderBlock->Flags & MB_FLAGS_ACPI_TABLE) ? TRUE :
FALSE;
- MmFreeLdrMemHigher = RosLoaderBlock->MemHigher;
MmFreeLdrPageDirectoryEnd = RosLoaderBlock->PageDirectoryEnd;
if (!MmFreeLdrPageDirectoryEnd) MmFreeLdrPageDirectoryEnd = 0x40000;
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 8 13:55:40 2008
@@ -203,6 +203,35 @@
*
*/
MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
+}
+
+ULONG
+NTAPI
+MiCountFreePagesInLoaderBlock(PLOADER_PARAMETER_BLOCK LoaderBlock)
+{
+ PLIST_ENTRY NextEntry;
+ PMEMORY_ALLOCATION_DESCRIPTOR Md;
+ ULONG TotalPages = 0;
+
+ for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
+ NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
+ NextEntry = NextEntry->Flink)
+ {
+ Md = CONTAINING_RECORD(NextEntry, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
+
+ if (Md->MemoryType == LoaderBad ||
+ Md->MemoryType == LoaderFirmwarePermanent ||
+ Md->MemoryType == LoaderSpecialMemory ||
+ Md->MemoryType == LoaderBBTMemory)
+ {
+ /* Don't count these blocks */
+ continue;
+ }
+
+ TotalPages += Md->PageCount;
+ }
+
+ return TotalPages;
}
PCHAR
@@ -247,7 +276,6 @@
* FUNCTION: Initalize memory managment
*/
{
- ULONG i;
ULONG kernel_len;
ULONG_PTR MappingAddress;
PLDR_DATA_TABLE_ENTRY LdrEntry;
@@ -280,26 +308,7 @@
DPRINT("CurrentProcess: %x\n", PsGetCurrentProcess());
PsGetCurrentProcess()->Pcb.DirectoryTableBase.LowPart =
(ULONG)MmGetPageDirectory();
- if ((BIOSMemoryMap != NULL) && (AddressRangeCount > 0))
- {
- // If we have a bios memory map, recalulate the memory size
- ULONG last = 0;
- for (i = 0; i < AddressRangeCount; i++)
- {
- if (BIOSMemoryMap[i].Type == 1
- && (BIOSMemoryMap[i].BaseAddrLow + BIOSMemoryMap[i].LengthLow +
PAGE_SIZE -1) / PAGE_SIZE > last)
- {
- last = (BIOSMemoryMap[i].BaseAddrLow + BIOSMemoryMap[i].LengthLow + PAGE_SIZE
-1) / PAGE_SIZE;
- }
- }
- if ((last - 256) * 4 > MmFreeLdrMemHigher)
- {
- MmFreeLdrMemHigher = (last - 256) * 4;
- }
- }
-
/* NTLDR Hacks */
- if (!MmFreeLdrMemHigher) MmFreeLdrMemHigher = 65536;
if (!MmFreeLdrPageDirectoryEnd) MmFreeLdrPageDirectoryEnd = 0x40000;
if (!FirstKrnlPhysAddr)
{
@@ -312,11 +321,6 @@
FirstKrnlPhysAddr = (ULONG_PTR)LdrEntry->DllBase - KSEG0_BASE;
/* FIXME: How do we get the last address? */
- }
-
- if (MmFreeLdrMemHigher >= (MaxMem - 1) * 1024)
- {
- MmFreeLdrMemHigher = (MaxMem - 1) * 1024;
}
/* Set memory limits */
@@ -346,13 +350,13 @@
* (we assume the kernel occupies a continuous range of physical
* memory)
*/
- DPRINT("first krnl %x\nlast krnl %x\n",FirstKrnlPhysAddr,
+ DPRINT("first krnl %x, last krnl %x\n",FirstKrnlPhysAddr,
LastKrnlPhysAddr);
/*
* Free physical memory not used by the kernel
*/
- MmStats.NrTotalPages = MmFreeLdrMemHigher/4;
+ MmStats.NrTotalPages = MiCountFreePagesInLoaderBlock(KeLoaderBlock);
MmNumberOfPhysicalPages = MmStats.NrTotalPages;
if (!MmStats.NrTotalPages)
{
@@ -361,12 +365,9 @@
}
else
{
- /* add 1MB for standard memory (not extended) */
+ /* HACK: add 1MB for standard memory (not extended). Why? */
MmStats.NrTotalPages += 256;
}
-#ifdef BIOS_MEM_FIX
- MmStats.NrTotalPages += 16;
-#endif
/*
* Initialize the kernel address space