diff src/w32heap.c @ 12452:bd304be0b491

Include config.h. (syspage_mask, real_data_region_end): Defined. (allocate_heap) [WINDOWS95]: Reverse conditional, end search at 0xD00000. (sbrk): Commit and uncommit memory in machine dependent page size chunks.
author Geoff Voelker <voelker@cs.washington.edu>
date Fri, 30 Jun 1995 21:14:06 +0000
parents ea533622fb8b
children ee40177f6c68
line wrap: on
line diff
--- a/src/w32heap.c	Fri Jun 30 21:12:37 1995 +0000
+++ b/src/w32heap.c	Fri Jun 30 21:14:06 1995 +0000
@@ -20,6 +20,8 @@
    Geoff Voelker (voelker@cs.washington.edu)			     7-29-94
 */
 
+#include "config.h"
+
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -27,6 +29,7 @@
 
 /* This gives us the page size and the size of the allocation unit on NT.  */
 SYSTEM_INFO sysinfo_cache;
+unsigned long syspage_mask = 0;
 
 /* These are defined to get Emacs to compile, but are not used.  */
 int edata;
@@ -58,6 +61,7 @@
 
   /* Cache page size, allocation unit, processor type, etc.  */
   GetSystemInfo (&sysinfo_cache);
+  syspage_mask = sysinfo_cache.dwPageSize - 1;
 }
 
 /* Round ADDRESS up to be aligned with ALIGN.  */
@@ -75,6 +79,7 @@
 /* Info for keeping track of our heap.  */
 unsigned char *data_region_base = NULL;
 unsigned char *data_region_end = NULL;
+unsigned char *real_data_region_end = NULL;
 unsigned long  data_region_size = 0;
 unsigned long  reserved_heap_size = 0;
 
@@ -92,8 +97,7 @@
   return data_region_end;
 }
 
-
-#ifdef WINDOWS95
+#ifndef WINDOWS95
 static char *
 allocate_heap (void)
 {
@@ -112,7 +116,7 @@
 allocate_heap (void)
 {
   unsigned long start     = 0x400000;
-  unsigned long stop      = 0xF00000;
+  unsigned long stop      = 0xD00000;
   unsigned long increment = 0x100000;
   char *ptr, *begin = NULL, *end = NULL;
   int i;
@@ -165,6 +169,7 @@
 	}
 
       data_region_end = data_region_base;
+      real_data_region_end = data_region_end;
       data_region_size = get_reserved_heap_size ();
     }
   
@@ -173,15 +178,28 @@
   /* If size is negative, shrink the heap by decommitting pages.  */
   if (size < 0) 
     {
+      int new_size;
+      unsigned char *new_data_region_end;
+
       size = -size;
 
       /* Sanity checks.  */
       if ((data_region_end - size) < data_region_base)
 	return NULL;
 
-      /* Decommit size bytes from the end of the heap.  */
-      if (!VirtualFree (data_region_end - size, size, MEM_DECOMMIT))
-	return NULL;
+      /* We can only decommit full pages, so allow for 
+	 partial deallocation [cga].  */
+      new_data_region_end = (data_region_end - size);
+      new_data_region_end = (unsigned char *)
+	((long) (new_data_region_end + syspage_mask) & ~syspage_mask);
+      new_size = real_data_region_end - new_data_region_end;
+      real_data_region_end = new_data_region_end;
+      if (new_size > 0) 
+	{
+	  /* Decommit size bytes from the end of the heap.  */
+	  if (!VirtualFree (real_data_region_end, new_size, MEM_DECOMMIT))
+	    return NULL;
+ 	}
 
       data_region_end -= size;
     } 
@@ -198,6 +216,11 @@
 			PAGE_READWRITE) == NULL)
 	return NULL;
       data_region_end += size;
+
+      /* We really only commit full pages, so record where
+	 the real end of committed memory is [cga].  */
+      real_data_region_end = (unsigned char *)
+	  ((long) (data_region_end + syspage_mask) & ~syspage_mask);
     }
   
   return result;