summaryrefslogtreecommitdiffstats
path: root/gl/alloca.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/alloca.c')
-rw-r--r--gl/alloca.c154
1 files changed, 77 insertions, 77 deletions
diff --git a/gl/alloca.c b/gl/alloca.c
index ff1cb7e9..75afdb96 100644
--- a/gl/alloca.c
+++ b/gl/alloca.c
@@ -81,37 +81,37 @@ long i00afunc ();
81 STACK_DIRECTION = 0 => direction of growth unknown */ 81 STACK_DIRECTION = 0 => direction of growth unknown */
82 82
83# ifndef STACK_DIRECTION 83# ifndef STACK_DIRECTION
84# define STACK_DIRECTION 0 /* Direction unknown. */ 84# define STACK_DIRECTION 0 /* Direction unknown. */
85# endif 85# endif
86 86
87# if STACK_DIRECTION != 0 87# if STACK_DIRECTION != 0
88 88
89# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ 89# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
90 90
91# else /* STACK_DIRECTION == 0; need run-time code. */ 91# else /* STACK_DIRECTION == 0; need run-time code. */
92 92
93static int stack_dir; /* 1 or -1 once known. */ 93static int stack_dir; /* 1 or -1 once known. */
94# define STACK_DIR stack_dir 94# define STACK_DIR stack_dir
95 95
96static void 96static void
97find_stack_direction (void) 97find_stack_direction (void)
98{ 98{
99 static char *addr = NULL; /* Address of first `dummy', once known. */ 99 static char *addr = NULL; /* Address of first `dummy', once known. */
100 auto char dummy; /* To get stack address. */ 100 auto char dummy; /* To get stack address. */
101 101
102 if (addr == NULL) 102 if (addr == NULL)
103 { /* Initial entry. */ 103 { /* Initial entry. */
104 addr = ADDRESS_FUNCTION (dummy); 104 addr = ADDRESS_FUNCTION (dummy);
105 105
106 find_stack_direction (); /* Recurse once. */ 106 find_stack_direction (); /* Recurse once. */
107 } 107 }
108 else 108 else
109 { 109 {
110 /* Second entry. */ 110 /* Second entry. */
111 if (ADDRESS_FUNCTION (dummy) > addr) 111 if (ADDRESS_FUNCTION (dummy) > addr)
112 stack_dir = 1; /* Stack grew upward. */ 112 stack_dir = 1; /* Stack grew upward. */
113 else 113 else
114 stack_dir = -1; /* Stack grew downward. */ 114 stack_dir = -1; /* Stack grew downward. */
115 } 115 }
116} 116}
117 117
@@ -124,21 +124,21 @@ find_stack_direction (void)
124 It is very important that sizeof(header) agree with malloc 124 It is very important that sizeof(header) agree with malloc
125 alignment chunk size. The following default should work okay. */ 125 alignment chunk size. The following default should work okay. */
126 126
127# ifndef ALIGN_SIZE 127# ifndef ALIGN_SIZE
128# define ALIGN_SIZE sizeof(double) 128# define ALIGN_SIZE sizeof(double)
129# endif 129# endif
130 130
131typedef union hdr 131typedef union hdr
132{ 132{
133 char align[ALIGN_SIZE]; /* To force sizeof(header). */ 133 char align[ALIGN_SIZE]; /* To force sizeof(header). */
134 struct 134 struct
135 { 135 {
136 union hdr *next; /* For chaining headers. */ 136 union hdr *next; /* For chaining headers. */
137 char *deep; /* For stack depth measure. */ 137 char *deep; /* For stack depth measure. */
138 } h; 138 } h;
139} header; 139} header;
140 140
141static header *last_alloca_header = NULL; /* -> last alloca header. */ 141static header *last_alloca_header = NULL; /* -> last alloca header. */
142 142
143/* Return a pointer to at least SIZE bytes of storage, 143/* Return a pointer to at least SIZE bytes of storage,
144 which will be automatically reclaimed upon exit from 144 which will be automatically reclaimed upon exit from
@@ -150,11 +150,11 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
150void * 150void *
151alloca (size_t size) 151alloca (size_t size)
152{ 152{
153 auto char probe; /* Probes stack depth: */ 153 auto char probe; /* Probes stack depth: */
154 register char *depth = ADDRESS_FUNCTION (probe); 154 register char *depth = ADDRESS_FUNCTION (probe);
155 155
156# if STACK_DIRECTION == 0 156# if STACK_DIRECTION == 0
157 if (STACK_DIR == 0) /* Unknown growth direction. */ 157 if (STACK_DIR == 0) /* Unknown growth direction. */
158 find_stack_direction (); 158 find_stack_direction ();
159# endif 159# endif
160 160
@@ -162,7 +162,7 @@ alloca (size_t size)
162 was allocated from deeper in the stack than currently. */ 162 was allocated from deeper in the stack than currently. */
163 163
164 { 164 {
165 register header *hp; /* Traverses linked list. */ 165 register header *hp; /* Traverses linked list. */
166 166
167# ifdef emacs 167# ifdef emacs
168 BLOCK_INPUT; 168 BLOCK_INPUT;
@@ -170,18 +170,18 @@ alloca (size_t size)
170 170
171 for (hp = last_alloca_header; hp != NULL;) 171 for (hp = last_alloca_header; hp != NULL;)
172 if ((STACK_DIR > 0 && hp->h.deep > depth) 172 if ((STACK_DIR > 0 && hp->h.deep > depth)
173 || (STACK_DIR < 0 && hp->h.deep < depth)) 173 || (STACK_DIR < 0 && hp->h.deep < depth))
174 { 174 {
175 register header *np = hp->h.next; 175 register header *np = hp->h.next;
176 176
177 free (hp); /* Collect garbage. */ 177 free (hp); /* Collect garbage. */
178 178
179 hp = np; /* -> next header. */ 179 hp = np; /* -> next header. */
180 } 180 }
181 else 181 else
182 break; /* Rest are not deeper. */ 182 break; /* Rest are not deeper. */
183 183
184 last_alloca_header = hp; /* -> last valid storage. */ 184 last_alloca_header = hp; /* -> last valid storage. */
185 185
186# ifdef emacs 186# ifdef emacs
187 UNBLOCK_INPUT; 187 UNBLOCK_INPUT;
@@ -189,7 +189,7 @@ alloca (size_t size)
189 } 189 }
190 190
191 if (size == 0) 191 if (size == 0)
192 return NULL; /* No allocation required. */ 192 return NULL; /* No allocation required. */
193 193
194 /* Allocate combined header + user data storage. */ 194 /* Allocate combined header + user data storage. */
195 195
@@ -229,10 +229,10 @@ alloca (size_t size)
229/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ 229/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
230struct stack_control_header 230struct stack_control_header
231 { 231 {
232 long shgrow:32; /* Number of times stack has grown. */ 232 long shgrow:32; /* Number of times stack has grown. */
233 long shaseg:32; /* Size of increments to stack. */ 233 long shaseg:32; /* Size of increments to stack. */
234 long shhwm:32; /* High water mark of stack. */ 234 long shhwm:32; /* High water mark of stack. */
235 long shsize:32; /* Current size of stack (all segments). */ 235 long shsize:32; /* Current size of stack (all segments). */
236 }; 236 };
237 237
238/* The stack segment linkage control information occurs at 238/* The stack segment linkage control information occurs at
@@ -244,21 +244,21 @@ struct stack_control_header
244 244
245struct stack_segment_linkage 245struct stack_segment_linkage
246 { 246 {
247 long ss[0200]; /* 0200 overflow words. */ 247 long ss[0200]; /* 0200 overflow words. */
248 long sssize:32; /* Number of words in this segment. */ 248 long sssize:32; /* Number of words in this segment. */
249 long ssbase:32; /* Offset to stack base. */ 249 long ssbase:32; /* Offset to stack base. */
250 long:32; 250 long:32;
251 long sspseg:32; /* Offset to linkage control of previous 251 long sspseg:32; /* Offset to linkage control of previous
252 segment of stack. */ 252 segment of stack. */
253 long:32; 253 long:32;
254 long sstcpt:32; /* Pointer to task common address block. */ 254 long sstcpt:32; /* Pointer to task common address block. */
255 long sscsnm; /* Private control structure number for 255 long sscsnm; /* Private control structure number for
256 microtasking. */ 256 microtasking. */
257 long ssusr1; /* Reserved for user. */ 257 long ssusr1; /* Reserved for user. */
258 long ssusr2; /* Reserved for user. */ 258 long ssusr2; /* Reserved for user. */
259 long sstpid; /* Process ID for pid based multi-tasking. */ 259 long sstpid; /* Process ID for pid based multi-tasking. */
260 long ssgvup; /* Pointer to multitasking thread giveup. */ 260 long ssgvup; /* Pointer to multitasking thread giveup. */
261 long sscray[7]; /* Reserved for Cray Research. */ 261 long sscray[7]; /* Reserved for Cray Research. */
262 long ssa0; 262 long ssa0;
263 long ssa1; 263 long ssa1;
264 long ssa2; 264 long ssa2;
@@ -282,27 +282,27 @@ struct stack_segment_linkage
282 returned by the STKSTAT library routine. */ 282 returned by the STKSTAT library routine. */
283struct stk_stat 283struct stk_stat
284 { 284 {
285 long now; /* Current total stack size. */ 285 long now; /* Current total stack size. */
286 long maxc; /* Amount of contiguous space which would 286 long maxc; /* Amount of contiguous space which would
287 be required to satisfy the maximum 287 be required to satisfy the maximum
288 stack demand to date. */ 288 stack demand to date. */
289 long high_water; /* Stack high-water mark. */ 289 long high_water; /* Stack high-water mark. */
290 long overflows; /* Number of stack overflow ($STKOFEN) calls. */ 290 long overflows; /* Number of stack overflow ($STKOFEN) calls. */
291 long hits; /* Number of internal buffer hits. */ 291 long hits; /* Number of internal buffer hits. */
292 long extends; /* Number of block extensions. */ 292 long extends; /* Number of block extensions. */
293 long stko_mallocs; /* Block allocations by $STKOFEN. */ 293 long stko_mallocs; /* Block allocations by $STKOFEN. */
294 long underflows; /* Number of stack underflow calls ($STKRETN). */ 294 long underflows; /* Number of stack underflow calls ($STKRETN). */
295 long stko_free; /* Number of deallocations by $STKRETN. */ 295 long stko_free; /* Number of deallocations by $STKRETN. */
296 long stkm_free; /* Number of deallocations by $STKMRET. */ 296 long stkm_free; /* Number of deallocations by $STKMRET. */
297 long segments; /* Current number of stack segments. */ 297 long segments; /* Current number of stack segments. */
298 long maxs; /* Maximum number of stack segments so far. */ 298 long maxs; /* Maximum number of stack segments so far. */
299 long pad_size; /* Stack pad size. */ 299 long pad_size; /* Stack pad size. */
300 long current_address; /* Current stack segment address. */ 300 long current_address; /* Current stack segment address. */
301 long current_size; /* Current stack segment size. This 301 long current_size; /* Current stack segment size. This
302 number is actually corrupted by STKSTAT to 302 number is actually corrupted by STKSTAT to
303 include the fifteen word trailer area. */ 303 include the fifteen word trailer area. */
304 long initial_address; /* Address of initial segment. */ 304 long initial_address; /* Address of initial segment. */
305 long initial_size; /* Size of initial segment. */ 305 long initial_size; /* Size of initial segment. */
306 }; 306 };
307 307
308/* The following structure describes the data structure which trails 308/* The following structure describes the data structure which trails
@@ -311,13 +311,13 @@ struct stk_stat
311 311
312struct stk_trailer 312struct stk_trailer
313 { 313 {
314 long this_address; /* Address of this block. */ 314 long this_address; /* Address of this block. */
315 long this_size; /* Size of this block (does not include 315 long this_size; /* Size of this block (does not include
316 this trailer). */ 316 this trailer). */
317 long unknown2; 317 long unknown2;
318 long unknown3; 318 long unknown3;
319 long link; /* Address of trailer block of previous 319 long link; /* Address of trailer block of previous
320 segment. */ 320 segment. */
321 long unknown5; 321 long unknown5;
322 long unknown6; 322 long unknown6;
323 long unknown7; 323 long unknown7;
@@ -355,8 +355,8 @@ i00afunc (long *address)
355 /* Set up the iteration. */ 355 /* Set up the iteration. */
356 356
357 trailer = (struct stk_trailer *) (status.current_address 357 trailer = (struct stk_trailer *) (status.current_address
358 + status.current_size 358 + status.current_size
359 - 15); 359 - 15);
360 360
361 /* There must be at least one stack segment. Therefore it is 361 /* There must be at least one stack segment. Therefore it is
362 a fatal error if "trailer" is null. */ 362 a fatal error if "trailer" is null. */
@@ -371,10 +371,10 @@ i00afunc (long *address)
371 block = (long *) trailer->this_address; 371 block = (long *) trailer->this_address;
372 size = trailer->this_size; 372 size = trailer->this_size;
373 if (block == 0 || size == 0) 373 if (block == 0 || size == 0)
374 abort (); 374 abort ();
375 trailer = (struct stk_trailer *) trailer->link; 375 trailer = (struct stk_trailer *) trailer->link;
376 if ((block <= address) && (address < (block + size))) 376 if ((block <= address) && (address < (block + size)))
377 break; 377 break;
378 } 378 }
379 379
380 /* Set the result to the offset in this segment and add the sizes 380 /* Set the result to the offset in this segment and add the sizes
@@ -390,7 +390,7 @@ i00afunc (long *address)
390 do 390 do
391 { 391 {
392 if (trailer->this_size <= 0) 392 if (trailer->this_size <= 0)
393 abort (); 393 abort ();
394 result += trailer->this_size; 394 result += trailer->this_size;
395 trailer = (struct stk_trailer *) trailer->link; 395 trailer = (struct stk_trailer *) trailer->link;
396 } 396 }
@@ -453,7 +453,7 @@ i00afunc (long address)
453 fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); 453 fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
454# endif 454# endif
455 if (pseg == 0) 455 if (pseg == 0)
456 break; 456 break;
457 stkl = stkl - pseg; 457 stkl = stkl - pseg;
458 ssptr = (struct stack_segment_linkage *) stkl; 458 ssptr = (struct stack_segment_linkage *) stkl;
459 size = ssptr->sssize; 459 size = ssptr->sssize;