1 .\" $NetBSD: sigaltstack.2,v 1.3 1995/02/27 10:41:52 cgd Exp $
3 .\" Copyright (c) 1983, 1991, 1992, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)sigaltstack.2 8.1 (Berkeley) 6/4/93
41 .Nd set and/or get signal stack context
43 .Fd #include <signal.h>
46 .Fa "const stack_t *restrict ss"
47 .Fa "stack_t *restrict oss"
51 allows users to define an alternate stack on which signals
56 it specifies a pointer to and the size of a
58 on which to deliver signals,
59 and tells the system if the process is currently executing
61 When a signal's action indicates its handler
62 should execute on the signal stack (specified with a
64 call), the system checks to see
65 if the process is currently executing on that stack.
66 If the process is not currently executing on the signal stack,
67 the system arranges a switch to the signal stack for the
68 duration of the signal handler's execution.
77 are ignored and the signal stack will be disabled.
78 Trying to disable an active stack will cause
84 A disabled stack will cause all signals to be
85 taken on the regular user stack.
86 If the stack is later re-enabled then all signals that were specified
87 to be processed on an alternate stack will resume doing so.
91 is non-zero, the current signal stack state is returned.
94 field will contain the value
96 if the process is currently on a signal stack and
98 if the signal stack is currently disabled.
102 is defined to be the number of bytes/chars that would be used to cover
103 the usual case when allocating an alternate stack area.
104 The following code fragment is typically used to allocate an alternate stack.
105 .Bd -literal -offset indent
106 if ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL)
108 sigstk.ss_size = SIGSTKSZ;
110 if (sigaltstack(&sigstk,0) < 0)
111 perror("sigaltstack");
113 An alternative approach is provided for programs with signal handlers
114 that require a specific amount of stack space other than the default size.
117 is defined to be the number of bytes/chars that is required by
118 the operating system to implement the alternate stack feature.
119 In computing an alternate stack size,
122 to their stack requirements to allow for the operating system overhead.
124 Signal stacks are automatically adjusted for the direction of stack
125 growth and alignment requirements.
126 Signal stacks may or may not be protected by the hardware and
127 are not ``grown'' automatically as is done for the normal stack.
128 If the stack overflows and this space is not protected
129 unpredictable results may occur.
131 Upon successful completion, a value of 0 is returned.
132 Otherwise, a value of -1 is returned and
134 is set to indicate the error.
137 will fail and the signal stack context will remain unchanged
138 if one of the following occurs.
139 .Bl -tag -width [ENOMEM]
146 points to memory that is not a valid part of the process
150 An attempt is made to disable an active stack.
155 argument is not a null pointer, and the ss_flags member
158 contains flags other than SS_DISABLE.
161 The size of the alternate stack area is less than or equal to
165 An attempt was made to modify an active stack.
168 .Fd #include <sys/types.h>
169 .Fd #include <signal.h>
186 .Fa "const struct sigaltstack *ss"
187 .Fa "struct sigaltstack *oss"
190 The variable types have changed.
193 struct is no longer used.
195 Use of the (obsolete)
197 struct will cause compiler diagnostics.
211 system call, appeared in