103
103
STACK_DIRECTION = 0 => direction of growth unknown */
105
105
#ifndef STACK_DIRECTION
106
#define STACK_DIRECTION 0 /* Direction unknown. */
106
#define STACK_DIRECTION 0 /* Direction unknown. */
109
109
#if STACK_DIRECTION != 0
111
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
111
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
113
113
#else /* STACK_DIRECTION == 0; need run-time code. */
115
static int stack_dir; /* 1 or -1 once known. */
116
#define STACK_DIR stack_dir
115
static int stack_dir; /* 1 or -1 once known. */
116
#define STACK_DIR stack_dir
119
119
find_stack_direction ()
121
static char *addr = NULL; /* Address of first `dummy', once known. */
122
auto char dummy; /* To get stack address. */
121
static char *addr = NULL; /* Address of first `dummy', once known. */
122
auto char dummy; /* To get stack address. */
124
124
if (addr == NULL)
125
{ /* Initial entry. */
125
{ /* Initial entry. */
126
126
addr = ADDRESS_FUNCTION (dummy);
128
find_stack_direction (); /* Recurse once. */
128
find_stack_direction (); /* Recurse once. */
132
132
/* Second entry. */
133
133
if (ADDRESS_FUNCTION (dummy) > addr)
134
stack_dir = 1; /* Stack grew upward. */
134
stack_dir = 1; /* Stack grew upward. */
136
stack_dir = -1; /* Stack grew downward. */
136
stack_dir = -1; /* Stack grew downward. */
146
146
It is very important that sizeof(header) agree with malloc
147
147
alignment chunk size. The following default should work okay. */
150
#define ALIGN_SIZE sizeof(double)
150
#define ALIGN_SIZE sizeof(double)
153
153
typedef union hdr
155
char align[ALIGN_SIZE]; /* To force sizeof(header). */
155
char align[ALIGN_SIZE]; /* To force sizeof(header). */
158
union hdr *next; /* For chaining headers. */
159
char *deep; /* For stack depth measure. */
158
union hdr *next; /* For chaining headers. */
159
char *deep; /* For stack depth measure. */
163
static header *last_alloca_header = NULL; /* -> last alloca header. */
163
static header *last_alloca_header = NULL; /* -> last alloca header. */
165
165
/* Return a pointer to at least SIZE bytes of storage,
166
166
which will be automatically reclaimed upon exit from
194
194
for (hp = last_alloca_header; hp != NULL;)
195
195
if ((STACK_DIR > 0 && hp->h.deep > depth)
196
|| (STACK_DIR < 0 && hp->h.deep < depth))
198
register header *np = hp->h.next;
200
free ((pointer) hp); /* Collect garbage. */
202
hp = np; /* -> next header. */
196
|| (STACK_DIR < 0 && hp->h.deep < depth))
198
register header *np = hp->h.next;
200
free ((pointer) hp); /* Collect garbage. */
202
hp = np; /* -> next header. */
205
break; /* Rest are not deeper. */
205
break; /* Rest are not deeper. */
207
last_alloca_header = hp; /* -> last valid storage. */
207
last_alloca_header = hp; /* -> last valid storage. */
246
246
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
247
247
struct stack_control_header
249
long shgrow:32; /* Number of times stack has grown. */
250
long shaseg:32; /* Size of increments to stack. */
251
long shhwm:32; /* High water mark of stack. */
252
long shsize:32; /* Current size of stack (all segments). */
249
long shgrow:32; /* Number of times stack has grown. */
250
long shaseg:32; /* Size of increments to stack. */
251
long shhwm:32; /* High water mark of stack. */
252
long shsize:32; /* Current size of stack (all segments). */
255
255
/* The stack segment linkage control information occurs at
262
262
struct stack_segment_linkage
264
long ss[0200]; /* 0200 overflow words. */
265
long sssize:32; /* Number of words in this segment. */
266
long ssbase:32; /* Offset to stack base. */
268
long sspseg:32; /* Offset to linkage control of previous
271
long sstcpt:32; /* Pointer to task common address block. */
272
long sscsnm; /* Private control structure number for
274
long ssusr1; /* Reserved for user. */
275
long ssusr2; /* Reserved for user. */
276
long sstpid; /* Process ID for pid based multi-tasking. */
277
long ssgvup; /* Pointer to multitasking thread giveup. */
278
long sscray[7]; /* Reserved for Cray Research. */
264
long ss[0200]; /* 0200 overflow words. */
265
long sssize:32; /* Number of words in this segment. */
266
long ssbase:32; /* Offset to stack base. */
268
long sspseg:32; /* Offset to linkage control of previous
271
long sstcpt:32; /* Pointer to task common address block. */
272
long sscsnm; /* Private control structure number for
274
long ssusr1; /* Reserved for user. */
275
long ssusr2; /* Reserved for user. */
276
long sstpid; /* Process ID for pid based multi-tasking. */
277
long ssgvup; /* Pointer to multitasking thread giveup. */
278
long sscray[7]; /* Reserved for Cray Research. */
299
299
returned by the STKSTAT library routine. */
302
long now; /* Current total stack size. */
303
long maxc; /* Amount of contiguous space which would
304
be required to satisfy the maximum
305
stack demand to date. */
306
long high_water; /* Stack high-water mark. */
307
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
308
long hits; /* Number of internal buffer hits. */
309
long extends; /* Number of block extensions. */
310
long stko_mallocs; /* Block allocations by $STKOFEN. */
311
long underflows; /* Number of stack underflow calls ($STKRETN). */
312
long stko_free; /* Number of deallocations by $STKRETN. */
313
long stkm_free; /* Number of deallocations by $STKMRET. */
314
long segments; /* Current number of stack segments. */
315
long maxs; /* Maximum number of stack segments so far. */
316
long pad_size; /* Stack pad size. */
317
long current_address; /* Current stack segment address. */
318
long current_size; /* Current stack segment size. This
319
number is actually corrupted by STKSTAT to
320
include the fifteen word trailer area. */
321
long initial_address; /* Address of initial segment. */
322
long initial_size; /* Size of initial segment. */
302
long now; /* Current total stack size. */
303
long maxc; /* Amount of contiguous space which would
304
be required to satisfy the maximum
305
stack demand to date. */
306
long high_water; /* Stack high-water mark. */
307
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
308
long hits; /* Number of internal buffer hits. */
309
long extends; /* Number of block extensions. */
310
long stko_mallocs; /* Block allocations by $STKOFEN. */
311
long underflows; /* Number of stack underflow calls ($STKRETN). */
312
long stko_free; /* Number of deallocations by $STKRETN. */
313
long stkm_free; /* Number of deallocations by $STKMRET. */
314
long segments; /* Current number of stack segments. */
315
long maxs; /* Maximum number of stack segments so far. */
316
long pad_size; /* Stack pad size. */
317
long current_address; /* Current stack segment address. */
318
long current_size; /* Current stack segment size. This
319
number is actually corrupted by STKSTAT to
320
include the fifteen word trailer area. */
321
long initial_address; /* Address of initial segment. */
322
long initial_size; /* Size of initial segment. */
325
325
/* The following structure describes the data structure which trails
329
329
struct stk_trailer
331
long this_address; /* Address of this block. */
332
long this_size; /* Size of this block (does not include
331
long this_address; /* Address of this block. */
332
long this_size; /* Size of this block (does not include
336
long link; /* Address of trailer block of previous
336
long link; /* Address of trailer block of previous
388
388
block = (long *) trailer->this_address;
389
389
size = trailer->this_size;
390
390
if (block == 0 || size == 0)
392
392
trailer = (struct stk_trailer *) trailer->link;
393
393
if ((block <= address) && (address < (block + size)))
397
397
/* Set the result to the offset in this segment and add the sizes