reactos/ntoskrnl/mm
diff -u -r1.31 -r1.32
--- anonmem.c 15 Aug 2004 16:39:06 -0000 1.31
+++ anonmem.c 28 Sep 2004 19:49:20 -0000 1.32
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* $Id: anonmem.c,v 1.31 2004/08/15 16:39:06 chorns Exp $
+/* $Id: anonmem.c,v 1.32 2004/09/28 19:49:20 gvg Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/anonmem.c
@@ -636,17 +636,17 @@
return(Status);
}
MmInitialiseRegion(&MemoryArea->Data.VirtualMemoryData.RegionListHead,
- RegionSize, Type, Protect);
+ MemoryArea->Length, Type, Protect);
if ((AllocationType & MEM_COMMIT) &&
((Protect & PAGE_READWRITE) ||
(Protect & PAGE_EXECUTE_READWRITE)))
{
- MmReserveSwapPages(RegionSize);
+ MmReserveSwapPages(MemoryArea->Length);
}
*UBaseAddress = BaseAddress;
- *URegionSize = RegionSize;
+ *URegionSize = MemoryArea->Length;
DPRINT("*UBaseAddress %x *URegionSize %x\n", BaseAddress, RegionSize);
MmUnlockAddressSpace(AddressSpace);
reactos/ntoskrnl/mm
diff -u -r1.66 -r1.67
--- marea.c 21 Aug 2004 19:03:04 -0000 1.66
+++ marea.c 28 Sep 2004 19:49:21 -0000 1.67
@@ -201,8 +201,10 @@
InsertTailList(ListHead,inserted_entry);
}
+#define ROUND_DOWN_POW2(Addr, Boundary) ((ULONG_PTR) (Addr) & ~ ((Boundary) - 1))
+#define ROUND_UP_POW2(Addr, Boundary) ROUND_DOWN_POW2((ULONG_PTR) (Addr) + (Boundary) - 1, Boundary)
-PVOID MmFindGapBottomUp(PMADDRESS_SPACE AddressSpace, ULONG Length)
+static PVOID MmFindGapBottomUp(PMADDRESS_SPACE AddressSpace, ULONG Length, ULONG Granularity)
{
PLIST_ENTRY ListHead;
PLIST_ENTRY current_entry;
@@ -213,6 +215,10 @@
DPRINT("MmFindGapBottomUp(Length %x)\n",Length);
+#ifdef DBG
+ Length += PAGE_SIZE; /* For a guard page following the area */
+#endif
+
ListHead = &AddressSpace->MAreaListHead;
current_entry = ListHead->Flink;
@@ -220,35 +226,49 @@
{
current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry);
next = CONTAINING_RECORD(current_entry->Flink,MEMORY_AREA,Entry);
- Gap = (char*)next->BaseAddress - ((char*)current->BaseAddress + PAGE_ROUND_UP(current->Length));
- if (Gap >= Length)
+ Address = (PVOID) ((char*)current->BaseAddress + PAGE_ROUND_UP(current->Length));
+#ifdef DBG
+ Address = (PVOID) ((char *) Address + PAGE_SIZE); /* For a guard page preceding the area */
+#endif
+ Address = (PVOID) ROUND_UP_POW2(Address, Granularity);
+ if (Address < next->BaseAddress)
{
- return((char*)current->BaseAddress + PAGE_ROUND_UP(current->Length));
+ Gap = (char*)next->BaseAddress - ((char*)current->BaseAddress + PAGE_ROUND_UP(current->Length));
+ if (Gap >= Length)
+ {
+ return Address;
+ }
}
current_entry = current_entry->Flink;
}
if (current_entry == ListHead)
{
- Address = (PVOID)AddressSpace->LowestAddress;
+ Address = (PVOID) ROUND_UP_POW2(AddressSpace->LowestAddress, Granularity);
}
else
{
current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry);
Address = (char*)current->BaseAddress + PAGE_ROUND_UP(current->Length);
+#ifdef DBG
+ Address = (PVOID) ((char *) Address + PAGE_SIZE); /* For a guard page preceding the area */
+#endif
+ Address = (PVOID) ROUND_UP_POW2(Address, Granularity);
}
/* Check if enough space for the block */
if (AddressSpace->LowestAddress < KERNEL_BASE)
{
- if ((ULONG)Address >= KERNEL_BASE || Length > KERNEL_BASE - (ULONG)Address)
+ if ((ULONG_PTR) Address >= KERNEL_BASE || Length > KERNEL_BASE - (ULONG_PTR) Address)
{
+ DPRINT1("Failed to find gap\n");
return NULL;
}
}
else
{
- if (Length >= 0xFFFFFFFF - (ULONG)Address)
+ if (Length >= ~ ((ULONG_PTR) 0) - (ULONG_PTR) Address)
{
+ DPRINT1("Failed to find gap\n");
return NULL;
}
}
@@ -256,7 +276,7 @@
}
-PVOID MmFindGapTopDown(PMADDRESS_SPACE AddressSpace, ULONG Length)
+static PVOID MmFindGapTopDown(PMADDRESS_SPACE AddressSpace, ULONG Length, ULONG Granularity)
{
PLIST_ENTRY ListHead;
PLIST_ENTRY current_entry;
@@ -269,6 +289,10 @@
DPRINT("MmFindGapTopDown(Length %lx)\n",Length);
+#ifdef DBG
+ Length += PAGE_SIZE; /* For a guard page following the area */
+#endif
+
if (AddressSpace->LowestAddress < KERNEL_BASE) //(ULONG_PTR)MmSystemRangeStart)
{
HighestAddress = MmHighestUserAddress;
@@ -286,45 +310,49 @@
{
current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry);
BottomAddress = (char*)current->BaseAddress + PAGE_ROUND_UP(current->Length);
+#ifdef DBG
+ BottomAddress = (PVOID) ((char *) BottomAddress + PAGE_SIZE); /* For a guard page preceding the area */
+#endif
+ BottomAddress = (PVOID) ROUND_UP_POW2(BottomAddress, Granularity);
DPRINT("Base %p Length %lx\n", current->BaseAddress, PAGE_ROUND_UP(current->Length));
- if (BottomAddress < HighestAddress)
+ if (BottomAddress < TopAddress && BottomAddress < HighestAddress)
{
- Gap = (char*)TopAddress - (char*)BottomAddress + 1;
+ Gap = (char*)TopAddress - (char*) BottomAddress + 1;
DPRINT("Bottom %p Top %p Gap %lx\n", BottomAddress, TopAddress, Gap);
if (Gap >= Length)
{
- DPRINT("Found gap at %p\n", (char*)TopAddress - Length);
- return((char*)TopAddress - Length + 1);
+ DPRINT("Found gap at %p\n", (char*) TopAddress - Length);
+ return (PVOID) ROUND_DOWN_POW2((char*) TopAddress - Length + 1, Granularity);
}
- TopAddress = (char*)current->BaseAddress - 1;
}
+ TopAddress = (char*)current->BaseAddress - 1;
current_entry = current_entry->Blink;
}
if (current_entry == ListHead)
{
- Address = (char*)HighestAddress - Length + 1;
+ Address = (PVOID) ROUND_DOWN_POW2((char*) HighestAddress - Length + 1, Granularity);
}
else
{
- Address = (char*)TopAddress - Length + 1;
+ Address = (PVOID) ROUND_DOWN_POW2((char*)TopAddress - Length + 1, Granularity);
}
/* Check if enough space for the block */
if (AddressSpace->LowestAddress < KERNEL_BASE)
{
- if ((ULONG)Address >= KERNEL_BASE || Length > KERNEL_BASE - (ULONG)Address)
+ if ((ULONG_PTR) Address >= KERNEL_BASE || Length > KERNEL_BASE - (ULONG_PTR) Address)
{
- DPRINT("Failed to find gap\n");
+ DPRINT1("Failed to find gap\n");
return NULL;
}
}
else
{
- if (Length >= 0xFFFFFFFF - (ULONG)Address)
+ if (Length >= ~ ((ULONG_PTR) 0) - (ULONG_PTR) Address)
{
- DPRINT("Failed to find gap\n");
+ DPRINT1("Failed to find gap\n");
return NULL;
}
}
@@ -334,12 +362,12 @@
}
-PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, ULONG Length, BOOL TopDown)
+PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, ULONG Length, ULONG Granularity, BOOL TopDown)
{
if (TopDown)
- return MmFindGapTopDown(AddressSpace, Length);
+ return MmFindGapTopDown(AddressSpace, Length, Granularity);
- return MmFindGapBottomUp(AddressSpace, Length);
+ return MmFindGapBottomUp(AddressSpace, Length, Granularity);
}
ULONG MmFindGapAtAddress(PMADDRESS_SPACE AddressSpace, PVOID Address)
@@ -546,38 +574,30 @@
*/
{
PVOID EndAddress;
+ ULONG Granularity;
ULONG tmpLength;
DPRINT("MmCreateMemoryArea(Type %d, BaseAddress %x,"
"*BaseAddress %x, Length %x, Attributes %x, Result %x)\n",
Type,BaseAddress,*BaseAddress,Length,Attributes,Result);
+ Granularity = (MEMORY_AREA_VIRTUAL_MEMORY == Type ? MM_VIRTMEM_GRANULARITY : PAGE_SIZE);
if ((*BaseAddress) == 0 && !FixedAddress)
{
tmpLength = PAGE_ROUND_UP(Length);
*BaseAddress = MmFindGap(AddressSpace,
- PAGE_ROUND_UP(Length) +(PAGE_SIZE*2),
+ PAGE_ROUND_UP(Length),
+ Granularity,
TopDown);
if ((*BaseAddress) == 0)
{
DPRINT("No suitable gap\n");
- return(STATUS_NO_MEMORY);
- }
-#if defined(__GNUC__)
- (*BaseAddress)=(*BaseAddress)+PAGE_SIZE;
-#else
-
- {
- char* pTemp = *BaseAddress;
- pTemp += PAGE_SIZE;
- *BaseAddress = pTemp;
+ return STATUS_NO_MEMORY;
}
-#endif
-
}
else
{
- tmpLength = (ULONG)*BaseAddress + Length - PAGE_ROUND_DOWN((*BaseAddress));
- (*BaseAddress) = (PVOID)PAGE_ROUND_DOWN((*BaseAddress));
+ tmpLength = Length + ((ULONG_PTR) *BaseAddress - ROUND_DOWN_POW2(*BaseAddress, Granularity));
+ (*BaseAddress) = (PVOID) ROUND_DOWN_POW2(*BaseAddress, Granularity);
if (AddressSpace->LowestAddress == KERNEL_BASE &&
(*BaseAddress) < (PVOID)KERNEL_BASE)
@@ -602,7 +622,7 @@
tmpLength)!=NULL)
{
DPRINT("Memory area already occupied\n");
- return(STATUS_CONFLICTING_ADDRESSES);
+ return STATUS_CONFLICTING_ADDRESSES;
}
}
@@ -621,5 +641,5 @@
MmInsertMemoryArea(AddressSpace, *Result);
DPRINT("MmCreateMemoryArea() succeeded\n");
- return(STATUS_SUCCESS);
+ return STATUS_SUCCESS;
}