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 #if defined(sun) 31 #pragma ident "@(#)stak.h 1.8 05/06/08 SMI" 32 #endif 33 34 /* 35 * Copyright 2008-2016 J. Schilling 36 * 37 * @(#)stak.h 1.11 16/08/28 2008-2016 J. Schilling 38 */ 39 40 /* 41 * UNIX shell 42 */ 43 44 /* 45 * To use stack as temporary workspace across 46 * possible storage allocation (eg name lookup) 47 * a) get ptr from `relstak' 48 * b) can now use `pushstak' 49 * c) then reset with `setstak' 50 * d) `absstak' gives real address if needed 51 */ 52 #define relstak() (staktop-stakbot) 53 #define relstakp(x) (((unsigned char *)(x))-stakbot) 54 #define absstak(x) (stakbot+Rcheat(x)) 55 #define setstak(x) (staktop = absstak(x)) 56 #define pushstak(c) (*staktop++ = (c)) 57 #define zerostak() (*staktop = 0) 58 59 /* 60 * Used to address an item left on the top of 61 * the stack (very temporary) 62 */ 63 #define curstak() (staktop) 64 65 /* 66 * `usestak' before `pushstak' then `fixstak' 67 * These routines are safe against heap 68 * being allocated. 69 */ 70 #define usestak() {locstak(); } 71 72 /* 73 * for local use only since it hands 74 * out a real address for the stack top 75 */ 76 extern unsigned char *locstak __PR((void)); 77 78 /* 79 * Will allocate the item being used and return its 80 * address (safe now). 81 */ 82 #define fixstak() endstak(staktop) 83 84 /* 85 * For use after `locstak' to hand back 86 * new stack top and then allocate item 87 */ 88 extern unsigned char *endstak __PR((unsigned char *)); 89 90 /* 91 * Copy a string onto the stack and 92 * allocate the space. 93 */ 94 extern unsigned char *cpystak __PR((unsigned char *)); 95 96 /* 97 * Copy a string onto the stack, checking for stack overflow 98 * as the copy is done. Same calling sequence as "movstr". 99 */ 100 extern unsigned char *movstrstak __PR((unsigned char *, 101 unsigned char *)); 102 103 /* 104 * Move bytes onto the stack, checking for stack overflow 105 * as the copy is done. Same calling sequence as the C 106 * library routine "memcpy". 107 */ 108 extern unsigned char *memcpystak __PR((unsigned char *, 109 unsigned char *, int)); 110 111 /* Allocate given ammount of stack space */ 112 extern unsigned char *getstak __PR((Intptr_t)); 113 114 /* Grow the data segment to include a given location */ 115 extern unsigned char *growstak __PR((unsigned char *)); 116 117 /* Base of the entire stack */ 118 extern unsigned char *stakbas; 119 120 /* Top of entire stack */ 121 extern unsigned char *brkend; 122 123 /* Base of current item */ 124 extern unsigned char *stakbot; 125 126 /* Top of current item */ 127 extern unsigned char *staktop; 128 129 /* Used with tdystak */ 130 extern unsigned char *savstak __PR((void)); 131