Commit in reactos/ntoskrnl on MAIN
ex/sysinfo.c+2-21.46 -> 1.47
include/internal/mm.h+4-11.88 -> 1.89
mm/anonmem.c+4-41.31 -> 1.32
  /marea.c+59-391.66 -> 1.67
ps/process.c+15-21.142 -> 1.143
+84-48
5 modified files
NtAllocateVirtualMemory() should return 64k aligned areas

reactos/ntoskrnl/ex
sysinfo.c 1.46 -> 1.47
diff -u -r1.46 -r1.47
--- sysinfo.c	28 Sep 2004 15:02:28 -0000	1.46
+++ sysinfo.c	28 Sep 2004 19:49:20 -0000	1.47
@@ -1,4 +1,4 @@
-/* $Id: sysinfo.c,v 1.46 2004/09/28 15:02:28 weiden Exp $
+/* $Id: sysinfo.c,v 1.47 2004/09/28 19:49:20 gvg Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -338,7 +338,7 @@
 	Sbi->NumberOfPhysicalPages = MmStats.NrTotalPages;
 	Sbi->LowestPhysicalPage = 0; /* FIXME */ 
 	Sbi->HighestPhysicalPage = MmStats.NrTotalPages; /* FIXME */
-	Sbi->AllocationGranularity = 65536; /* hard coded on Intel? */
+	Sbi->AllocationGranularity = MM_VIRTMEM_GRANULARITY; /* hard coded on Intel? */
 	Sbi->LowestUserAddress = 0x10000; /* Top of 64k */
 	Sbi->HighestUserAddress = (ULONG_PTR)MmHighestUserAddress;
 	Sbi->ActiveProcessors = 0x00000001; /* FIXME */

reactos/ntoskrnl/include/internal
mm.h 1.88 -> 1.89
diff -u -r1.88 -r1.89
--- mm.h	9 Sep 2004 20:42:33 -0000	1.88
+++ mm.h	28 Sep 2004 19:49:20 -0000	1.89
@@ -50,6 +50,9 @@
 #define MM_LOWEST_USER_ADDRESS (4096)
 #endif
 
+#define MM_VIRTMEM_GRANULARITY (64 * 1024) /* Although Microsoft says this isn't hardcoded anymore,
+                                              they won't be able to change it. Stuff depends on it */
+
 #define STATUS_MM_RESTART_OPERATION       ((NTSTATUS)0xD0000001)
 
 /*
@@ -354,7 +357,7 @@
 				      PVOID Address,
 				      ULONG Length);
 
-PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, ULONG Length, BOOL TopDown);
+PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, ULONG Length, ULONG Granularity, BOOL TopDown);
 
 /* npool.c *******************************************************************/
 

reactos/ntoskrnl/mm
anonmem.c 1.31 -> 1.32
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
marea.c 1.66 -> 1.67
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;
 }

reactos/ntoskrnl/ps
process.c 1.142 -> 1.143
diff -u -r1.142 -r1.143
--- process.c	28 Sep 2004 15:02:29 -0000	1.142
+++ process.c	28 Sep 2004 19:49:21 -0000	1.143
@@ -1,4 +1,4 @@
-/* $Id: process.c,v 1.142 2004/09/28 15:02:29 weiden Exp $
+/* $Id: process.c,v 1.143 2004/09/28 19:49:21 gvg Exp $
  *
  * COPYRIGHT:         See COPYING in the top level directory
  * PROJECT:           ReactOS kernel
@@ -431,7 +431,20 @@
 				   (PVOID*)&Peb,
 				   0,
 				   &PebSize,
-				   MEM_RESERVE | MEM_COMMIT,
+				   MEM_RESERVE,
+				   PAGE_READWRITE);
+  if (!NT_SUCCESS(Status))
+    {
+      DPRINT1("NtAllocateVirtualMemory() failed (Status %lx)\n", Status);
+      return(Status);
+    }
+  Peb = (PPEB)PEB_BASE;
+  PebSize = PAGE_SIZE;
+  Status = NtAllocateVirtualMemory(ProcessHandle,
+				   (PVOID*)&Peb,
+				   0,
+				   &PebSize,
+				   MEM_COMMIT,
 				   PAGE_READWRITE);
   if (!NT_SUCCESS(Status))
     {
CVSspam 0.2.8