aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGeoff Voelker1995-06-30 21:14:06 +0000
committerGeoff Voelker1995-06-30 21:14:06 +0000
commit3bbabc43d815e100b1c99d62ce7571e601c86ccb (patch)
tree9c7804da58266419880e52aa71ca287efe1bf6eb /src
parent051fe60dc47c956ea47f9640a7ed6855fb676ddc (diff)
downloademacs-3bbabc43d815e100b1c99d62ce7571e601c86ccb.tar.gz
emacs-3bbabc43d815e100b1c99d62ce7571e601c86ccb.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/w32heap.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/w32heap.c b/src/w32heap.c
index 7c717fbdfd0..a8f0ab1d46b 100644
--- a/src/w32heap.c
+++ b/src/w32heap.c
@@ -20,6 +20,8 @@
20 Geoff Voelker (voelker@cs.washington.edu) 7-29-94 20 Geoff Voelker (voelker@cs.washington.edu) 7-29-94
21*/ 21*/
22 22
23#include "config.h"
24
23#include <stdlib.h> 25#include <stdlib.h>
24#include <stdio.h> 26#include <stdio.h>
25 27
@@ -27,6 +29,7 @@
27 29
28/* This gives us the page size and the size of the allocation unit on NT. */ 30/* This gives us the page size and the size of the allocation unit on NT. */
29SYSTEM_INFO sysinfo_cache; 31SYSTEM_INFO sysinfo_cache;
32unsigned long syspage_mask = 0;
30 33
31/* These are defined to get Emacs to compile, but are not used. */ 34/* These are defined to get Emacs to compile, but are not used. */
32int edata; 35int edata;
@@ -58,6 +61,7 @@ cache_system_info (void)
58 61
59 /* Cache page size, allocation unit, processor type, etc. */ 62 /* Cache page size, allocation unit, processor type, etc. */
60 GetSystemInfo (&sysinfo_cache); 63 GetSystemInfo (&sysinfo_cache);
64 syspage_mask = sysinfo_cache.dwPageSize - 1;
61} 65}
62 66
63/* Round ADDRESS up to be aligned with ALIGN. */ 67/* Round ADDRESS up to be aligned with ALIGN. */
@@ -75,6 +79,7 @@ round_to_next (unsigned char *address, unsigned long align)
75/* Info for keeping track of our heap. */ 79/* Info for keeping track of our heap. */
76unsigned char *data_region_base = NULL; 80unsigned char *data_region_base = NULL;
77unsigned char *data_region_end = NULL; 81unsigned char *data_region_end = NULL;
82unsigned char *real_data_region_end = NULL;
78unsigned long data_region_size = 0; 83unsigned long data_region_size = 0;
79unsigned long reserved_heap_size = 0; 84unsigned long reserved_heap_size = 0;
80 85
@@ -92,8 +97,7 @@ get_data_end (void)
92 return data_region_end; 97 return data_region_end;
93} 98}
94 99
95 100#ifndef WINDOWS95
96#ifdef WINDOWS95
97static char * 101static char *
98allocate_heap (void) 102allocate_heap (void)
99{ 103{
@@ -112,7 +116,7 @@ static char *
112allocate_heap (void) 116allocate_heap (void)
113{ 117{
114 unsigned long start = 0x400000; 118 unsigned long start = 0x400000;
115 unsigned long stop = 0xF00000; 119 unsigned long stop = 0xD00000;
116 unsigned long increment = 0x100000; 120 unsigned long increment = 0x100000;
117 char *ptr, *begin = NULL, *end = NULL; 121 char *ptr, *begin = NULL, *end = NULL;
118 int i; 122 int i;
@@ -165,6 +169,7 @@ sbrk (unsigned long increment)
165 } 169 }
166 170
167 data_region_end = data_region_base; 171 data_region_end = data_region_base;
172 real_data_region_end = data_region_end;
168 data_region_size = get_reserved_heap_size (); 173 data_region_size = get_reserved_heap_size ();
169 } 174 }
170 175
@@ -173,15 +178,28 @@ sbrk (unsigned long increment)
173 /* If size is negative, shrink the heap by decommitting pages. */ 178 /* If size is negative, shrink the heap by decommitting pages. */
174 if (size < 0) 179 if (size < 0)
175 { 180 {
181 int new_size;
182 unsigned char *new_data_region_end;
183
176 size = -size; 184 size = -size;
177 185
178 /* Sanity checks. */ 186 /* Sanity checks. */
179 if ((data_region_end - size) < data_region_base) 187 if ((data_region_end - size) < data_region_base)
180 return NULL; 188 return NULL;
181 189
182 /* Decommit size bytes from the end of the heap. */ 190 /* We can only decommit full pages, so allow for
183 if (!VirtualFree (data_region_end - size, size, MEM_DECOMMIT)) 191 partial deallocation [cga]. */
184 return NULL; 192 new_data_region_end = (data_region_end - size);
193 new_data_region_end = (unsigned char *)
194 ((long) (new_data_region_end + syspage_mask) & ~syspage_mask);
195 new_size = real_data_region_end - new_data_region_end;
196 real_data_region_end = new_data_region_end;
197 if (new_size > 0)
198 {
199 /* Decommit size bytes from the end of the heap. */
200 if (!VirtualFree (real_data_region_end, new_size, MEM_DECOMMIT))
201 return NULL;
202 }
185 203
186 data_region_end -= size; 204 data_region_end -= size;
187 } 205 }
@@ -198,6 +216,11 @@ sbrk (unsigned long increment)
198 PAGE_READWRITE) == NULL) 216 PAGE_READWRITE) == NULL)
199 return NULL; 217 return NULL;
200 data_region_end += size; 218 data_region_end += size;
219
220 /* We really only commit full pages, so record where
221 the real end of committed memory is [cga]. */
222 real_data_region_end = (unsigned char *)
223 ((long) (data_region_end + syspage_mask) & ~syspage_mask);
201 } 224 }
202 225
203 return result; 226 return result;