annotate lib/alloca.c @ 448:5cccf90bf838 3.0 tip

Fixed bug with complex external references generating invalid relocations in the object file
author lost@l-w.ca
date Fri, 05 Nov 2010 22:27:00 -0600
parents b8bf63962a99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
434
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1 /* alloca.c -- allocate automatically reclaimed memory
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
2 (Mostly) portable public-domain implementation -- D A Gwyn
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
3
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
4 This implementation of the PWB library alloca function,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
5 which is used to allocate space off the run-time stack so
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
6 that it is automatically reclaimed upon procedure exit,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
7 was inspired by discussions with J. Q. Johnson of Cornell.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
8 J.Otto Tennant <jot@cray.com> contributed the Cray support.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
9
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
10 There are some preprocessor constants that can
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
11 be defined when compiling for your specific system, for
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
12 improved efficiency; however, the defaults should be okay.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
13
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
14 The general concept of this implementation is to keep
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
15 track of all alloca-allocated blocks, and reclaim any
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
16 that are found to be deeper in the stack than the current
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
17 invocation. This heuristic does not reclaim storage as
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
18 soon as it becomes invalid, but it will do so eventually.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
19
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
20 As a special case, alloca(0) reclaims storage without
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
21 allocating any. It is a good idea to use alloca(0) in
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
22 your main control loop, etc. to force garbage collection. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
23
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
24 #include <config.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
25
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
26 #include <alloca.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
27
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
28 #include <string.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
29 #include <stdlib.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
30
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
31 #ifdef emacs
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
32 # include "lisp.h"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
33 # include "blockinput.h"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
34 # ifdef EMACS_FREE
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
35 # undef free
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
36 # define free EMACS_FREE
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
37 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
38 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
39 # define memory_full() abort ()
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
40 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
41
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
42 /* If compiling with GCC 2, this file's not needed. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
43 #if !defined (__GNUC__) || __GNUC__ < 2
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
44
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
45 /* If someone has defined alloca as a macro,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
46 there must be some other way alloca is supposed to work. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
47 # ifndef alloca
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
48
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
49 # ifdef emacs
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
50 # ifdef static
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
51 /* actually, only want this if static is defined as ""
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
52 -- this is for usg, in which emacs must undefine static
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
53 in order to make unexec workable
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
54 */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
55 # ifndef STACK_DIRECTION
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
56 you
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
57 lose
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
58 -- must know STACK_DIRECTION at compile-time
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
59 /* Using #error here is not wise since this file should work for
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
60 old and obscure compilers. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
61 # endif /* STACK_DIRECTION undefined */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
62 # endif /* static */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
63 # endif /* emacs */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
64
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
65 /* If your stack is a linked list of frames, you have to
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
66 provide an "address metric" ADDRESS_FUNCTION macro. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
67
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
68 # if defined (CRAY) && defined (CRAY_STACKSEG_END)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
69 long i00afunc ();
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
70 # define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
71 # else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
72 # define ADDRESS_FUNCTION(arg) &(arg)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
73 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
74
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
75 /* Define STACK_DIRECTION if you know the direction of stack
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
76 growth for your system; otherwise it will be automatically
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
77 deduced at run-time.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
78
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
79 STACK_DIRECTION > 0 => grows toward higher addresses
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
80 STACK_DIRECTION < 0 => grows toward lower addresses
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
81 STACK_DIRECTION = 0 => direction of growth unknown */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
82
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
83 # ifndef STACK_DIRECTION
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
84 # define STACK_DIRECTION 0 /* Direction unknown. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
85 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
86
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
87 # if STACK_DIRECTION != 0
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
88
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
89 # define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
90
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
91 # else /* STACK_DIRECTION == 0; need run-time code. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
92
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
93 static int stack_dir; /* 1 or -1 once known. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
94 # define STACK_DIR stack_dir
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
95
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
96 static void
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
97 find_stack_direction (void)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
98 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
99 static char *addr = NULL; /* Address of first `dummy', once known. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
100 auto char dummy; /* To get stack address. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
101
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
102 if (addr == NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
103 { /* Initial entry. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
104 addr = ADDRESS_FUNCTION (dummy);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
105
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
106 find_stack_direction (); /* Recurse once. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
107 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
108 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
109 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
110 /* Second entry. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
111 if (ADDRESS_FUNCTION (dummy) > addr)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
112 stack_dir = 1; /* Stack grew upward. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
113 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
114 stack_dir = -1; /* Stack grew downward. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
115 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
116 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
117
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
118 # endif /* STACK_DIRECTION == 0 */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
119
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
120 /* An "alloca header" is used to:
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
121 (a) chain together all alloca'ed blocks;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
122 (b) keep track of stack depth.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
123
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
124 It is very important that sizeof(header) agree with malloc
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
125 alignment chunk size. The following default should work okay. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
126
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
127 # ifndef ALIGN_SIZE
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
128 # define ALIGN_SIZE sizeof(double)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
129 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
130
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
131 typedef union hdr
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
132 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
133 char align[ALIGN_SIZE]; /* To force sizeof(header). */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
134 struct
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
135 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
136 union hdr *next; /* For chaining headers. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
137 char *deep; /* For stack depth measure. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
138 } h;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
139 } header;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
140
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
141 static header *last_alloca_header = NULL; /* -> last alloca header. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
142
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
143 /* Return a pointer to at least SIZE bytes of storage,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
144 which will be automatically reclaimed upon exit from
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
145 the procedure that called alloca. Originally, this space
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
146 was supposed to be taken from the current stack frame of the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
147 caller, but that method cannot be made to work for some
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
148 implementations of C, for example under Gould's UTX/32. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
149
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
150 void *
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
151 alloca (size_t size)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
152 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
153 auto char probe; /* Probes stack depth: */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
154 register char *depth = ADDRESS_FUNCTION (probe);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
155
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
156 # if STACK_DIRECTION == 0
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
157 if (STACK_DIR == 0) /* Unknown growth direction. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
158 find_stack_direction ();
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
159 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
160
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
161 /* Reclaim garbage, defined as all alloca'd storage that
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
162 was allocated from deeper in the stack than currently. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
163
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
164 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
165 register header *hp; /* Traverses linked list. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
166
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
167 # ifdef emacs
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
168 BLOCK_INPUT;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
169 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
170
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
171 for (hp = last_alloca_header; hp != NULL;)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
172 if ((STACK_DIR > 0 && hp->h.deep > depth)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
173 || (STACK_DIR < 0 && hp->h.deep < depth))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
174 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
175 register header *np = hp->h.next;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
176
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
177 free (hp); /* Collect garbage. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
178
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
179 hp = np; /* -> next header. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
180 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
181 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
182 break; /* Rest are not deeper. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
183
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
184 last_alloca_header = hp; /* -> last valid storage. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
185
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
186 # ifdef emacs
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
187 UNBLOCK_INPUT;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
188 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
189 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
190
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
191 if (size == 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
192 return NULL; /* No allocation required. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
193
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
194 /* Allocate combined header + user data storage. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
195
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
196 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
197 /* Address of header. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
198 register header *new;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
199
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
200 size_t combined_size = sizeof (header) + size;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
201 if (combined_size < sizeof (header))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
202 memory_full ();
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
203
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
204 new = malloc (combined_size);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
205
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
206 if (! new)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
207 memory_full ();
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
208
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
209 new->h.next = last_alloca_header;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
210 new->h.deep = depth;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
211
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
212 last_alloca_header = new;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
213
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
214 /* User storage begins just after header. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
215
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
216 return (void *) (new + 1);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
217 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
218 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
219
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
220 # if defined (CRAY) && defined (CRAY_STACKSEG_END)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
221
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
222 # ifdef DEBUG_I00AFUNC
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
223 # include <stdio.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
224 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
225
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
226 # ifndef CRAY_STACK
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
227 # define CRAY_STACK
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
228 # ifndef CRAY2
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
229 /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
230 struct stack_control_header
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
231 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
232 long shgrow:32; /* Number of times stack has grown. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
233 long shaseg:32; /* Size of increments to stack. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
234 long shhwm:32; /* High water mark of stack. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
235 long shsize:32; /* Current size of stack (all segments). */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
236 };
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
237
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
238 /* The stack segment linkage control information occurs at
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
239 the high-address end of a stack segment. (The stack
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
240 grows from low addresses to high addresses.) The initial
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
241 part of the stack segment linkage control information is
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
242 0200 (octal) words. This provides for register storage
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
243 for the routine which overflows the stack. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
244
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
245 struct stack_segment_linkage
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
246 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
247 long ss[0200]; /* 0200 overflow words. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
248 long sssize:32; /* Number of words in this segment. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
249 long ssbase:32; /* Offset to stack base. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
250 long:32;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
251 long sspseg:32; /* Offset to linkage control of previous
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
252 segment of stack. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
253 long:32;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
254 long sstcpt:32; /* Pointer to task common address block. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
255 long sscsnm; /* Private control structure number for
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
256 microtasking. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
257 long ssusr1; /* Reserved for user. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
258 long ssusr2; /* Reserved for user. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
259 long sstpid; /* Process ID for pid based multi-tasking. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
260 long ssgvup; /* Pointer to multitasking thread giveup. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
261 long sscray[7]; /* Reserved for Cray Research. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
262 long ssa0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
263 long ssa1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
264 long ssa2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
265 long ssa3;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
266 long ssa4;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
267 long ssa5;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
268 long ssa6;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
269 long ssa7;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
270 long sss0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
271 long sss1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
272 long sss2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
273 long sss3;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
274 long sss4;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
275 long sss5;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
276 long sss6;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
277 long sss7;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
278 };
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
279
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
280 # else /* CRAY2 */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
281 /* The following structure defines the vector of words
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
282 returned by the STKSTAT library routine. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
283 struct stk_stat
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
284 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
285 long now; /* Current total stack size. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
286 long maxc; /* Amount of contiguous space which would
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
287 be required to satisfy the maximum
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
288 stack demand to date. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
289 long high_water; /* Stack high-water mark. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
290 long overflows; /* Number of stack overflow ($STKOFEN) calls. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
291 long hits; /* Number of internal buffer hits. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
292 long extends; /* Number of block extensions. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
293 long stko_mallocs; /* Block allocations by $STKOFEN. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
294 long underflows; /* Number of stack underflow calls ($STKRETN). */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
295 long stko_free; /* Number of deallocations by $STKRETN. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
296 long stkm_free; /* Number of deallocations by $STKMRET. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
297 long segments; /* Current number of stack segments. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
298 long maxs; /* Maximum number of stack segments so far. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
299 long pad_size; /* Stack pad size. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
300 long current_address; /* Current stack segment address. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
301 long current_size; /* Current stack segment size. This
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
302 number is actually corrupted by STKSTAT to
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
303 include the fifteen word trailer area. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
304 long initial_address; /* Address of initial segment. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
305 long initial_size; /* Size of initial segment. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
306 };
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
307
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
308 /* The following structure describes the data structure which trails
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
309 any stack segment. I think that the description in 'asdef' is
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
310 out of date. I only describe the parts that I am sure about. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
311
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
312 struct stk_trailer
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
313 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
314 long this_address; /* Address of this block. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
315 long this_size; /* Size of this block (does not include
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
316 this trailer). */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
317 long unknown2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
318 long unknown3;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
319 long link; /* Address of trailer block of previous
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
320 segment. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
321 long unknown5;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
322 long unknown6;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
323 long unknown7;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
324 long unknown8;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
325 long unknown9;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
326 long unknown10;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
327 long unknown11;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
328 long unknown12;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
329 long unknown13;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
330 long unknown14;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
331 };
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
332
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
333 # endif /* CRAY2 */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
334 # endif /* not CRAY_STACK */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
335
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
336 # ifdef CRAY2
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
337 /* Determine a "stack measure" for an arbitrary ADDRESS.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
338 I doubt that "lint" will like this much. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
339
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
340 static long
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
341 i00afunc (long *address)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
342 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
343 struct stk_stat status;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
344 struct stk_trailer *trailer;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
345 long *block, size;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
346 long result = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
347
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
348 /* We want to iterate through all of the segments. The first
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
349 step is to get the stack status structure. We could do this
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
350 more quickly and more directly, perhaps, by referencing the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
351 $LM00 common block, but I know that this works. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
352
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
353 STKSTAT (&status);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
354
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
355 /* Set up the iteration. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
356
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
357 trailer = (struct stk_trailer *) (status.current_address
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
358 + status.current_size
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
359 - 15);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
360
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
361 /* There must be at least one stack segment. Therefore it is
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
362 a fatal error if "trailer" is null. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
363
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
364 if (trailer == 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
365 abort ();
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
366
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
367 /* Discard segments that do not contain our argument address. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
368
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
369 while (trailer != 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
370 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
371 block = (long *) trailer->this_address;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
372 size = trailer->this_size;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
373 if (block == 0 || size == 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
374 abort ();
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
375 trailer = (struct stk_trailer *) trailer->link;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
376 if ((block <= address) && (address < (block + size)))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
377 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
378 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
379
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
380 /* Set the result to the offset in this segment and add the sizes
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
381 of all predecessor segments. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
382
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
383 result = address - block;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
384
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
385 if (trailer == 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
386 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
387 return result;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
388 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
389
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
390 do
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
391 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
392 if (trailer->this_size <= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
393 abort ();
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
394 result += trailer->this_size;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
395 trailer = (struct stk_trailer *) trailer->link;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
396 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
397 while (trailer != 0);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
398
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
399 /* We are done. Note that if you present a bogus address (one
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
400 not in any segment), you will get a different number back, formed
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
401 from subtracting the address of the first block. This is probably
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
402 not what you want. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
403
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
404 return (result);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
405 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
406
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
407 # else /* not CRAY2 */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
408 /* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
409 Determine the number of the cell within the stack,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
410 given the address of the cell. The purpose of this
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
411 routine is to linearize, in some sense, stack addresses
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
412 for alloca. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
413
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
414 static long
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
415 i00afunc (long address)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
416 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
417 long stkl = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
418
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
419 long size, pseg, this_segment, stack;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
420 long result = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
421
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
422 struct stack_segment_linkage *ssptr;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
423
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
424 /* Register B67 contains the address of the end of the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
425 current stack segment. If you (as a subprogram) store
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
426 your registers on the stack and find that you are past
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
427 the contents of B67, you have overflowed the segment.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
428
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
429 B67 also points to the stack segment linkage control
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
430 area, which is what we are really interested in. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
431
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
432 stkl = CRAY_STACKSEG_END ();
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
433 ssptr = (struct stack_segment_linkage *) stkl;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
434
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
435 /* If one subtracts 'size' from the end of the segment,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
436 one has the address of the first word of the segment.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
437
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
438 If this is not the first segment, 'pseg' will be
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
439 nonzero. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
440
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
441 pseg = ssptr->sspseg;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
442 size = ssptr->sssize;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
443
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
444 this_segment = stkl - size;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
445
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
446 /* It is possible that calling this routine itself caused
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
447 a stack overflow. Discard stack segments which do not
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
448 contain the target address. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
449
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
450 while (!(this_segment <= address && address <= stkl))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
451 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
452 # ifdef DEBUG_I00AFUNC
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
453 fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
454 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
455 if (pseg == 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
456 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
457 stkl = stkl - pseg;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
458 ssptr = (struct stack_segment_linkage *) stkl;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
459 size = ssptr->sssize;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
460 pseg = ssptr->sspseg;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
461 this_segment = stkl - size;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
462 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
463
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
464 result = address - this_segment;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
465
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
466 /* If you subtract pseg from the current end of the stack,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
467 you get the address of the previous stack segment's end.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
468 This seems a little convoluted to me, but I'll bet you save
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
469 a cycle somewhere. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
470
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
471 while (pseg != 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
472 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
473 # ifdef DEBUG_I00AFUNC
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
474 fprintf (stderr, "%011o %011o\n", pseg, size);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
475 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
476 stkl = stkl - pseg;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
477 ssptr = (struct stack_segment_linkage *) stkl;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
478 size = ssptr->sssize;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
479 pseg = ssptr->sspseg;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
480 result += size;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
481 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
482 return (result);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
483 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
484
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
485 # endif /* not CRAY2 */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
486 # endif /* CRAY */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
487
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
488 # endif /* no alloca */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
489 #endif /* not GCC version 3 */