# HG changeset patch # User Geoff Voelker # Date 804546846 0 # Node ID bd304be0b49124f889062f21c75efa9af945f7d1 # Parent 4439dcb1496aaea7426d96e530df8e6fb8c91b6e 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. diff -r 4439dcb1496a -r bd304be0b491 src/w32heap.c --- 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 #include @@ -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;