Author: tkreuzer
Date: Mon Nov 30 01:24:55 2009
New Revision: 44327
URL:
http://svn.reactos.org/svn/reactos?rev=44327&view=rev
Log:
[MM]
Rewrite the broken MmFindGap* functions. They were first searching for a gap between the
already allocated memory areas and only after that trying to find a gap below or above
these areas. This bug helped with 2 things. 1. Not overwriting the kernel mapping, because
no memory area was defined for it and 2. allow csrss to map video memory at virtual adress
0x000a0000. The former is fixed by adding the appropriate memory area, the latter is
hacked away, by making the addressing range start at 0x00100000. Also use
MmHighestUserAddress instead of MmSystemRangestart - 1. Simplyfy overcomplicated code. Fix
a DPRINT
Modified:
branches/ros-amd64-bringup/reactos/ntoskrnl/mm/marea.c
branches/ros-amd64-bringup/reactos/ntoskrnl/mm/mminit.c
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/mm/marea.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/mm/marea.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/mm/marea.c [iso-8859-1] Mon Nov 30
01:24:55 2009
@@ -469,13 +469,12 @@
ULONG_PTR Length,
ULONG_PTR Granularity)
{
- PVOID LowestAddress = MmGetAddressSpaceOwner(AddressSpace) ? MM_LOWEST_USER_ADDRESS :
MmSystemRangeStart;
+ // HACK: csrss really wants to map video memory at 0x000a0000 - 0x00100000, so keep
that free
+ PVOID LowestAddress = MmGetAddressSpaceOwner(AddressSpace) ? (PVOID)0x00100000 :
MmSystemRangeStart;
PVOID HighestAddress = MmGetAddressSpaceOwner(AddressSpace) ?
- (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) :
(PVOID)MAXULONG_PTR;
+ MmHighestUserAddress : (PVOID)MAXULONG_PTR;
PVOID AlignedAddress;
- PMEMORY_AREA Node;
- PMEMORY_AREA FirstNode;
- PMEMORY_AREA PreviousNode;
+ PMEMORY_AREA Root, Node;
MmVerifyMemoryAreas(AddressSpace);
@@ -484,53 +483,30 @@
AlignedAddress = MM_ROUND_UP(LowestAddress, Granularity);
- /* Special case for empty tree. */
- if (AddressSpace->WorkingSetExpansionLinks.Flink == NULL)
- {
- if ((ULONG_PTR)HighestAddress - (ULONG_PTR)AlignedAddress >= Length)
+ Root = (PMEMORY_AREA)AddressSpace->WorkingSetExpansionLinks.Flink;
+
+ /* Go to the node with lowest address in the tree. */
+ if (Root)
+ Node = MmIterateFirstNode(Root);
+ else
+ Node = NULL;
+
+ while (Node)
+ {
+ if (Node->StartingAddress > AlignedAddress &&
+ (ULONG_PTR)Node->StartingAddress >= (ULONG_PTR)AlignedAddress + Length)
{
DPRINT("MmFindGapBottomUp: %p\n", AlignedAddress);
return AlignedAddress;
}
- DPRINT("MmFindGapBottomUp: 0\n");
- return 0;
- }
-
- /* Go to the node with lowest address in the tree. */
- FirstNode = Node =
MmIterateFirstNode((PMEMORY_AREA)AddressSpace->WorkingSetExpansionLinks.Flink);
-
- /* Traverse the tree from left to right. */
- PreviousNode = Node;
- for (;;)
- {
+
+ AlignedAddress = MM_ROUND_UP(Node->EndingAddress, Granularity);
Node = MmIterateNextNode(Node);
- if (Node == NULL)
- break;
-
- AlignedAddress = MM_ROUND_UP(PreviousNode->EndingAddress, Granularity);
- if (Node->StartingAddress > AlignedAddress &&
- (ULONG_PTR)Node->StartingAddress - (ULONG_PTR)AlignedAddress >= Length)
- {
- DPRINT("MmFindGapBottomUp: %p\n", AlignedAddress);
- return AlignedAddress;
- }
-
- PreviousNode = Node;
}
/* Check if there is enough space after the last memory area. */
- AlignedAddress = MM_ROUND_UP(PreviousNode->EndingAddress, Granularity);
if ((ULONG_PTR)HighestAddress > (ULONG_PTR)AlignedAddress &&
(ULONG_PTR)HighestAddress - (ULONG_PTR)AlignedAddress >= Length)
- {
- DPRINT("MmFindGapBottomUp: %p\n", AlignedAddress);
- return AlignedAddress;
- }
-
- /* Check if there is enough space before the first memory area. */
- AlignedAddress = MM_ROUND_UP(LowestAddress, Granularity);
- if (FirstNode->StartingAddress > AlignedAddress &&
- (ULONG_PTR)FirstNode->StartingAddress - (ULONG_PTR)AlignedAddress >=
Length)
{
DPRINT("MmFindGapBottomUp: %p\n", AlignedAddress);
return AlignedAddress;
@@ -549,72 +525,46 @@
{
PVOID LowestAddress = MmGetAddressSpaceOwner(AddressSpace) ? MM_LOWEST_USER_ADDRESS :
MmSystemRangeStart;
PVOID HighestAddress = MmGetAddressSpaceOwner(AddressSpace) ?
- (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) :
(PVOID)MAXULONG_PTR;
+ MmHighestUserAddress : (PVOID)MAXULONG_PTR;
PVOID AlignedAddress;
- PMEMORY_AREA Node;
- PMEMORY_AREA PreviousNode;
+ PMEMORY_AREA Root, Node;
MmVerifyMemoryAreas(AddressSpace);
DPRINT("LowestAddress: %p HighestAddress: %p\n",
LowestAddress, HighestAddress);
- AlignedAddress = MM_ROUND_DOWN((ULONG_PTR)HighestAddress - Length + 1, Granularity);
+ AlignedAddress = MM_ROUND_DOWN((ULONG_PTR)HighestAddress - Length, Granularity);
/* Check for overflow. */
if (AlignedAddress > HighestAddress)
return NULL;
- /* Special case for empty tree. */
- if (AddressSpace->WorkingSetExpansionLinks.Flink == NULL)
- {
- if (AlignedAddress >= LowestAddress)
+ Root = (PMEMORY_AREA)AddressSpace->WorkingSetExpansionLinks.Flink;
+
+ /* Go to the node with highest address in the tree. */
+ if (Root)
+ Node = MmIterateLastNode(Root);
+ else
+ Node = NULL;
+
+ /* Traverse the tree from left to right. */
+ while (Node)
+ {
+ if (Node->EndingAddress <= AlignedAddress)
{
DPRINT("MmFindGapTopDown: %p\n", AlignedAddress);
return AlignedAddress;
}
- DPRINT("MmFindGapTopDown: 0\n");
- return 0;
- }
-
- /* Go to the node with highest address in the tree. */
- Node =
MmIterateLastNode((PMEMORY_AREA)AddressSpace->WorkingSetExpansionLinks.Flink);
-
- /* Check if there is enough space after the last memory area. */
- if (Node->EndingAddress <= AlignedAddress)
- {
- DPRINT("MmFindGapTopDown: %p\n", AlignedAddress);
- return AlignedAddress;
- }
-
- /* Traverse the tree from left to right. */
- PreviousNode = Node;
- for (;;)
- {
+
+ AlignedAddress = MM_ROUND_DOWN((ULONG_PTR)Node->StartingAddress - Length,
Granularity);
+
+ /* Check for overflow. */
+ if (AlignedAddress > Node->StartingAddress)
+ return NULL;
+
Node = MmIteratePrevNode(Node);
- if (Node == NULL)
- break;
-
- AlignedAddress = MM_ROUND_DOWN((ULONG_PTR)PreviousNode->StartingAddress - Length
+ 1, Granularity);
-
- /* Check for overflow. */
- if (AlignedAddress > PreviousNode->StartingAddress)
- return NULL;
-
- if (Node->EndingAddress <= AlignedAddress)
- {
- DPRINT("MmFindGapTopDown: %p\n", AlignedAddress);
- return AlignedAddress;
- }
-
- PreviousNode = Node;
- }
-
- AlignedAddress = MM_ROUND_DOWN((ULONG_PTR)PreviousNode->StartingAddress - Length +
1, Granularity);
-
- /* Check for overflow. */
- if (AlignedAddress > PreviousNode->StartingAddress)
- return NULL;
+ }
if (AlignedAddress >= LowestAddress)
{
@@ -944,6 +894,7 @@
if ((*BaseAddress) == 0 && !FixedAddress)
{
tmpLength = PAGE_ROUND_UP(Length);
+ __debugbreak();
*BaseAddress = MmFindGap(AddressSpace,
tmpLength,
Granularity,
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/mm/mminit.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] Mon Nov 30
01:24:55 2009
@@ -1,4 +1,4 @@
-/*
+/*
* PROJECT: ReactOS Kernel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: ntoskrnl/mm/mminit.c
@@ -78,6 +78,21 @@
BoundaryAddressMultiple.QuadPart = 0;
//
+ // Create the memory area to define the loader mappings
+ //
+ BaseAddress = (PVOID)KSEG0_BASE;
+ Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
+ MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
+ &BaseAddress,
+ MmBootImageSize,
+ PAGE_EXECUTE_READWRITE,
+ &MArea,
+ TRUE,
+ 0,
+ BoundaryAddressMultiple);
+ ASSERT(Status == STATUS_SUCCESS);
+
+ //
// Create the memory area to define the PTE base
//
BaseAddress = (PVOID)PTE_BASE;
@@ -284,8 +299,8 @@
// Print the memory layout
//
DPRINT1(" 0x%p - 0x%p\t%s\n",
- MmSystemRangeStart,
- (ULONG_PTR)MmSystemRangeStart + MmBootImageSize,
+ KSEG0_BASE,
+ (ULONG_PTR)KSEG0_BASE + MmBootImageSize,
"Boot Loaded Image");
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmPagedPoolBase,