diff options
| author | Geoff Voelker | 1996-05-03 18:34:21 +0000 |
|---|---|---|
| committer | Geoff Voelker | 1996-05-03 18:34:21 +0000 |
| commit | 8dfdd41fa860572ab6dcfe76b0dec2fadea3cd6a (patch) | |
| tree | e2e1119fb6eec59d95c2aff2ecf997d2e1b439a9 /src/w32heap.c | |
| parent | b3fa71dc1be5269620f1663fb7d5da5b1ce3ff31 (diff) | |
| download | emacs-8dfdd41fa860572ab6dcfe76b0dec2fadea3cd6a.tar.gz emacs-8dfdd41fa860572ab6dcfe76b0dec2fadea3cd6a.zip | |
Include lisp.h.
(allocate_heap): Use VALBITS to determine size of heap.
(allocate_heap) [WINDOWS95]: Conditional code removed.
(sbrk): Use VALMASK instead of an unsigned integer mask.
Diffstat (limited to 'src/w32heap.c')
| -rw-r--r-- | src/w32heap.c | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/src/w32heap.c b/src/w32heap.c index 050bee14951..28d44e54b21 100644 --- a/src/w32heap.c +++ b/src/w32heap.c | |||
| @@ -27,6 +27,7 @@ Boston, MA 02111-1307, USA. | |||
| 27 | #include <stdio.h> | 27 | #include <stdio.h> |
| 28 | 28 | ||
| 29 | #include "ntheap.h" | 29 | #include "ntheap.h" |
| 30 | #include "lisp.h" /* for VALMASK */ | ||
| 30 | 31 | ||
| 31 | /* This gives us the page size and the size of the allocation unit on NT. */ | 32 | /* This gives us the page size and the size of the allocation unit on NT. */ |
| 32 | SYSTEM_INFO sysinfo_cache; | 33 | SYSTEM_INFO sysinfo_cache; |
| @@ -98,12 +99,45 @@ get_data_end (void) | |||
| 98 | return data_region_end; | 99 | return data_region_end; |
| 99 | } | 100 | } |
| 100 | 101 | ||
| 101 | #ifndef WINDOWS95 | ||
| 102 | static char * | 102 | static char * |
| 103 | allocate_heap (void) | 103 | allocate_heap (void) |
| 104 | { | 104 | { |
| 105 | unsigned long base = 0x00030000; | 105 | /* The base address for our GNU malloc heap is chosen in conjuction |
| 106 | unsigned long end = 0x00D00000; | 106 | with the link settings for temacs.exe which control the stack size, |
| 107 | the initial default process heap size and the executable image base | ||
| 108 | address. The link settings and the malloc heap base below must all | ||
| 109 | correspond; the relationship between these values depends on how NT | ||
| 110 | and Win95 arrange the virtual address space for a process (and on | ||
| 111 | the size of the code and data segments in temacs.exe). | ||
| 112 | |||
| 113 | The most important thing is to make base address for the executable | ||
| 114 | image high enough to leave enough room between it and the 4MB floor | ||
| 115 | of the process address space on Win95 for the primary thread stack, | ||
| 116 | the process default heap, and other assorted odds and ends | ||
| 117 | (eg. environment strings, private system dll memory etc) that are | ||
| 118 | allocated before temacs has a chance to grab its malloc arena. The | ||
| 119 | malloc heap base can then be set several MB higher than the | ||
| 120 | executable image base, leaving enough room for the code and data | ||
| 121 | segments. | ||
| 122 | |||
| 123 | Because some parts of Emacs can use rather a lot of stack space | ||
| 124 | (for instance, the regular expression routines can potentially | ||
| 125 | allocate several MB of stack space) we allow 8MB for the stack. | ||
| 126 | |||
| 127 | Allowing 1MB for the default process heap, and 1MB for odds and | ||
| 128 | ends, we can base the executable at 16MB and still have a generous | ||
| 129 | safety margin. At the moment, the executable has about 810KB of | ||
| 130 | code (for x86) and about 550KB of data - on RISC platforms the code | ||
| 131 | size could be roughly double, so if we allow 4MB for the executable | ||
| 132 | we will have plenty of room for expansion. | ||
| 133 | |||
| 134 | Thus we set the malloc heap base to 20MB. Since Emacs now leaves | ||
| 135 | 28 bits available for pointers, this lets us use the remainder of | ||
| 136 | the region below the 256MB line for our malloc arena - 236MB is | ||
| 137 | still a pretty decent arena to play in! */ | ||
| 138 | |||
| 139 | unsigned long base = 0x01400000; /* 20MB */ | ||
| 140 | unsigned long end = 1 << VALBITS; /* 256MB */ | ||
| 107 | 141 | ||
| 108 | reserved_heap_size = end - base; | 142 | reserved_heap_size = end - base; |
| 109 | 143 | ||
| @@ -112,39 +146,6 @@ allocate_heap (void) | |||
| 112 | MEM_RESERVE, | 146 | MEM_RESERVE, |
| 113 | PAGE_NOACCESS); | 147 | PAGE_NOACCESS); |
| 114 | } | 148 | } |
| 115 | #else | ||
| 116 | static char * | ||
| 117 | allocate_heap (void) | ||
| 118 | { | ||
| 119 | unsigned long start = 0x400000; | ||
| 120 | unsigned long stop = 0xD00000; | ||
| 121 | unsigned long increment = 0x100000; | ||
| 122 | char *ptr, *begin = NULL, *end = NULL; | ||
| 123 | int i; | ||
| 124 | |||
| 125 | for (i = start; i < stop; i += increment) | ||
| 126 | { | ||
| 127 | ptr = VirtualAlloc ((void *) i, increment, MEM_RESERVE, PAGE_NOACCESS); | ||
| 128 | if (ptr) | ||
| 129 | begin = begin ? begin : ptr; | ||
| 130 | else if (begin) | ||
| 131 | { | ||
| 132 | end = ptr; | ||
| 133 | break; | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | if (begin && !end) | ||
| 138 | end = (char *) i; | ||
| 139 | |||
| 140 | if (!begin) | ||
| 141 | /* We couldn't allocate any memory for the heap. Exit. */ | ||
| 142 | exit (-2); | ||
| 143 | |||
| 144 | reserved_heap_size = end - begin; | ||
| 145 | return begin; | ||
| 146 | } | ||
| 147 | #endif | ||
| 148 | 149 | ||
| 149 | 150 | ||
| 150 | /* Emulate Unix sbrk. */ | 151 | /* Emulate Unix sbrk. */ |
| @@ -161,9 +162,9 @@ sbrk (unsigned long increment) | |||
| 161 | if (!data_region_base) | 162 | if (!data_region_base) |
| 162 | return NULL; | 163 | return NULL; |
| 163 | 164 | ||
| 164 | /* Ensure that the addresses don't use the upper 8 bits since | 165 | /* Ensure that the addresses don't use the upper tag bits since |
| 165 | the Lisp type goes there (yucko). */ | 166 | the Lisp type goes there. */ |
| 166 | if (((unsigned long) data_region_base & 0xFF000000) != 0) | 167 | if (((unsigned long) data_region_base & ~VALMASK) != 0) |
| 167 | { | 168 | { |
| 168 | printf ("Error: The heap was allocated in upper memory.\n"); | 169 | printf ("Error: The heap was allocated in upper memory.\n"); |
| 169 | exit (1); | 170 | exit (1); |