annotate src/alloca.c @ 63127:20c2d120fc79

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