Geoff Voelker (voelker@cs.washington.edu) 7-29-94
*/
+#include "config.h"
+
#include <stdlib.h>
#include <stdio.h>
/* 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;
/* 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. */
/* 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;
return data_region_end;
}
-
-#ifdef WINDOWS95
+#ifndef WINDOWS95
static char *
allocate_heap (void)
{
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;
}
data_region_end = data_region_base;
+ real_data_region_end = data_region_end;
data_region_size = get_reserved_heap_size ();
}
/* 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;
}
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;