Mercurial > emacs
comparison src/w32heap.c @ 11943:ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
(sbrk): Use allocate_heap.
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Fri, 26 May 1995 05:27:52 +0000 |
parents | 5eb009221225 |
children | bd304be0b491 |
comparison
equal
deleted
inserted
replaced
11942:04cc0b15ef74 | 11943:ea533622fb8b |
---|---|
74 | 74 |
75 /* Info for keeping track of our heap. */ | 75 /* Info for keeping track of our heap. */ |
76 unsigned char *data_region_base = NULL; | 76 unsigned char *data_region_base = NULL; |
77 unsigned char *data_region_end = NULL; | 77 unsigned char *data_region_end = NULL; |
78 unsigned long data_region_size = 0; | 78 unsigned long data_region_size = 0; |
79 unsigned long reserved_heap_size = 0; | |
79 | 80 |
80 /* The start of the data segment. */ | 81 /* The start of the data segment. */ |
81 unsigned char * | 82 unsigned char * |
82 get_data_start (void) | 83 get_data_start (void) |
83 { | 84 { |
89 get_data_end (void) | 90 get_data_end (void) |
90 { | 91 { |
91 return data_region_end; | 92 return data_region_end; |
92 } | 93 } |
93 | 94 |
95 | |
96 #ifdef WINDOWS95 | |
97 static char * | |
98 allocate_heap (void) | |
99 { | |
100 unsigned long base = 0x00030000; | |
101 unsigned long end = 0x00D00000; | |
102 | |
103 reserved_heap_size = end - base; | |
104 | |
105 return VirtualAlloc ((void *) base, | |
106 get_reserved_heap_size (), | |
107 MEM_RESERVE, | |
108 PAGE_NOACCESS); | |
109 } | |
110 #else | |
111 static char * | |
112 allocate_heap (void) | |
113 { | |
114 unsigned long start = 0x400000; | |
115 unsigned long stop = 0xF00000; | |
116 unsigned long increment = 0x100000; | |
117 char *ptr, *begin = NULL, *end = NULL; | |
118 int i; | |
119 | |
120 for (i = start; i < stop; i += increment) | |
121 { | |
122 ptr = VirtualAlloc ((void *) i, increment, MEM_RESERVE, PAGE_NOACCESS); | |
123 if (ptr) | |
124 begin = begin ? begin : ptr; | |
125 else if (begin) | |
126 { | |
127 end = ptr; | |
128 break; | |
129 } | |
130 } | |
131 | |
132 if (begin && !end) | |
133 end = (char *) i; | |
134 | |
135 if (!begin) | |
136 /* We couldn't allocate any memory for the heap. Exit. */ | |
137 exit (-2); | |
138 | |
139 reserved_heap_size = end - begin; | |
140 return begin; | |
141 } | |
142 #endif | |
143 | |
144 | |
94 /* Emulate Unix sbrk. */ | 145 /* Emulate Unix sbrk. */ |
95 void * | 146 void * |
96 sbrk (unsigned long increment) | 147 sbrk (unsigned long increment) |
97 { | 148 { |
98 void *result; | 149 void *result; |
99 long size = (long) increment; | 150 long size = (long) increment; |
100 | 151 |
101 /* Allocate our heap if we haven't done so already. */ | 152 /* Allocate our heap if we haven't done so already. */ |
102 if (!data_region_base) | 153 if (!data_region_base) |
103 { | 154 { |
104 data_region_base = VirtualAlloc ((void *) get_data_region_base (), | 155 data_region_base = allocate_heap (); |
105 get_reserved_heap_size (), | |
106 MEM_RESERVE, | |
107 PAGE_NOACCESS); | |
108 if (!data_region_base) | 156 if (!data_region_base) |
109 return NULL; | 157 return NULL; |
110 | 158 |
111 /* Ensure that the addresses don't use the upper 8 bits since | 159 /* Ensure that the addresses don't use the upper 8 bits since |
112 the Lisp type goes there (yucko). */ | 160 the Lisp type goes there (yucko). */ |