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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* Copyright (c) 1988 AT&T */ 22 /* All Rights Reserved */ 23 24 25 /* 26 * Copyright 2014 Garrett D'Amore <garrett@damore.org> 27 * Copyright 2023 Oxide Computer Company 28 * 29 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 30 * Use is subject to license terms. 31 */ 32 33 #ifndef _UCONTEXT_H 34 #define _UCONTEXT_H 35 36 /* 37 * The header <ucontext.h> and the functions: getcontext(), setcontext(), 38 * makecontext(), swapcontext(), were introduced by X/Open XPG4 Version 2 39 * (XPG4v2/SUSv1). They were not defined in POSIX.1-1990 - POSIX.1-1995. 40 * They were carried into POSIX.1-2001 (SUSv3) but marked obsolescent, 41 * and where removed entirely from POSIX.1-2008 (SUSv4) and later. 42 * In summary, no version of POSIX predating XPG4v2 states any 43 * requirements about <ucontext.h> or its content. 44 * 45 * Note in particular that the standard does not require that we "hide" 46 * anything here for those older POSIX standards. Programs written to 47 * those old standards shoud not include <ucontext.h>, and if they did, 48 * the result would be "implementation defined" behvior. 49 * 50 * The historical practice for this system is to expose the same content 51 * from this header for XPG4v2 and all earlier environments. 52 */ 53 54 #include <sys/ucontext.h> 55 /* 56 * The file sys/regset.h defines indices in the gregset_t array, 57 * such as EIP on i386. Those defines were historically exposed 58 * via sys/ucontext.h, sys/signal.h, etc. which caused surprises 59 * due to those defines unexpectedly polluting the namespace. 60 * On the other hand, several existing applications assume that 61 * the regset names are defined after an include <ucontext.h>. 62 * To solve both problems at once: <ucontext.h> (this file) 63 * DOES include sys/regset.h for you but <sys/ucontext.h> 64 * does NOT include sys/regset.h anymore. 65 */ 66 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 67 #include <sys/regset.h> 68 #include <sys/siginfo.h> 69 #include <inttypes.h> 70 #endif 71 72 #ifdef __cplusplus 73 extern "C" { 74 #endif 75 76 #ifdef __sparc 77 #ifdef __PRAGMA_REDEFINE_EXTNAME 78 #pragma redefine_extname makecontext __makecontext_v2 79 #else 80 #define makecontext __makecontext_v2 81 #endif 82 #endif 83 84 extern int getcontext(ucontext_t *) __RETURNS_TWICE; 85 extern int setcontext(const ucontext_t *); 86 extern int swapcontext(ucontext_t *_RESTRICT_KYWD, 87 const ucontext_t *_RESTRICT_KYWD); 88 extern void makecontext(ucontext_t *, void(*)(), int, ...); 89 90 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 91 extern ucontext_t *ucontext_alloc(uint32_t); 92 extern void ucontext_free(ucontext_t *); 93 extern int getcontext_extd(ucontext_t *, uint32_t) __RETURNS_TWICE; 94 extern int swapcontext_extd(ucontext_t *_RESTRICT_KYWD, uint32_t, 95 const ucontext_t *_RESTRICT_KYWD); 96 extern int walkcontext(const ucontext_t *, int (*)(uintptr_t, int, void *), 97 void *); 98 extern int printstack(int); 99 extern int addrtosymstr(void *, char *, int); 100 extern int getustack(stack_t **); 101 extern int setustack(stack_t *); 102 103 extern int stack_getbounds(stack_t *); 104 extern int stack_setbounds(const stack_t *); 105 extern int stack_inbounds(void *); 106 107 /* 108 * Can only declare this if siginfo_t is declared. 109 * See <sys/signal.h> above and the conditions under which 110 * that includes <sys/siginfo.h> to give us siginfo_t. 111 */ 112 #if defined(__EXTENSIONS__) || \ 113 !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2) 114 extern int stack_violation(int, const siginfo_t *, const ucontext_t *); 115 #endif 116 117 extern void *_stack_grow(void *); 118 #endif /* !_XPG4_2 || __EXTENSIONS__ */ 119 120 #ifdef __cplusplus 121 } 122 #endif 123 124 #endif /* _UCONTEXT_H */ 125