xref: /illumos-gate/usr/src/cmd/sh/stak.h (revision 2a8bcb4e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  *	UNIX shell
32  */
33 
34 /* To use stack as temporary workspace across
35  * possible storage allocation (eg name lookup)
36  * a) get ptr from `relstak'
37  * b) can now use `pushstak'
38  * c) then reset with `setstak'
39  * d) `absstak' gives real address if needed
40  */
41 #define		relstak()	(staktop-stakbot)
42 #define		absstak(x)	(stakbot+Rcheat(x))
43 #define		setstak(x)	(staktop=absstak(x))
44 #define		pushstak(c)	(*staktop++=(c))
45 #define		zerostak()	(*staktop=0)
46 
47 /* Used to address an item left on the top of
48  * the stack (very temporary)
49  */
50 #define		curstak()	(staktop)
51 
52 /* `usestak' before `pushstak' then `fixstak'
53  * These routines are safe against heap
54  * being allocated.
55  */
56 #define		usestak()	{locstak();}
57 
58 /* for local use only since it hands
59  * out a real address for the stack top
60  */
61 extern unsigned char		*locstak();
62 
63 /* Will allocate the item being used and return its
64  * address (safe now).
65  */
66 #define		fixstak()	endstak(staktop)
67 
68 /* For use after `locstak' to hand back
69  * new stack top and then allocate item
70  */
71 extern unsigned char		*endstak();
72 
73 /* Copy a string onto the stack and
74  * allocate the space.
75  */
76 extern unsigned char		*cpystak();
77 
78 /* Copy a string onto the stack, checking for stack overflow
79  * as the copy is done.  Same calling sequence as "movstr".
80  */
81 extern unsigned char		*movstrstak();
82 
83 /* Move bytes onto the stack, checking for stack overflow
84  * as the copy is done.  Same calling sequence as the C
85  * library routine "memcpy".
86  */
87 extern unsigned char		*memcpystak();
88 
89 /* Allocate given ammount of stack space */
90 extern unsigned char		*getstak();
91 
92 /* Grow the data segment to include a given location */
93 extern void		growstak();
94 
95 /* A chain of ptrs of stack blocks that
96  * have become covered by heap allocation.
97  * `tdystak' will return them to the heap.
98  */
99 extern struct blk	*stakbsy;
100 
101 /* Base of the entire stack */
102 extern unsigned char		*stakbas;
103 
104 /* Top of entire stack */
105 extern unsigned char		*brkend;
106 
107 /* Base of current item */
108 extern unsigned char		*stakbot;
109 
110 /* Top of current item */
111 extern unsigned char		*staktop;
112 
113 /* Used with tdystak */
114 extern unsigned char		*savstak();
115