]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/man/man2/sigaltstack.2
xnu-2050.48.11.tar.gz
[apple/xnu.git] / bsd / man / man2 / sigaltstack.2
... / ...
CommitLineData
1.\" $NetBSD: sigaltstack.2,v 1.3 1995/02/27 10:41:52 cgd Exp $
2.\"
3.\" Copyright (c) 1983, 1991, 1992, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
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.
21.\"
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
32.\" SUCH DAMAGE.
33.\"
34.\" @(#)sigaltstack.2 8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt SIGALTSTACK 2
38.Os BSD 4.2
39.Sh NAME
40.Nm sigaltstack
41.Nd set and/or get signal stack context
42.Sh SYNOPSIS
43.Fd #include <signal.h>
44.Ft int
45.Fo sigaltstack
46.Fa "const stack_t *restrict ss"
47.Fa "stack_t *restrict oss"
48.Fc
49.Sh DESCRIPTION
50.Fn Sigaltstack
51allows users to define an alternate stack on which signals
52are to be processed.
53If
54.Fa ss
55is non-zero,
56it specifies a pointer to and the size of a
57.Em "signal stack"
58on which to deliver signals,
59and tells the system if the process is currently executing
60on that stack.
61When a signal's action indicates its handler
62should execute on the signal stack (specified with a
63.Xr sigaction 2
64call), the system checks to see
65if the process is currently executing on that stack.
66If the process is not currently executing on the signal stack,
67the system arranges a switch to the signal stack for the
68duration of the signal handler's execution.
69.Pp
70If
71.Dv SA_DISABLE
72is set in
73.Fa ss_flags ,
74.Fa ss_sp
75and
76.Fa ss_size
77are ignored and the signal stack will be disabled.
78Trying to disable an active stack will cause
79.Nm
80to return -1 with
81.Va errno
82set to
83.Dv EINVAL .
84A disabled stack will cause all signals to be
85taken on the regular user stack.
86If the stack is later re-enabled then all signals that were specified
87to be processed on an alternate stack will resume doing so.
88.Pp
89If
90.Fa oss
91is non-zero, the current signal stack state is returned.
92The
93.Fa ss_flags
94field will contain the value
95.Dv SA_ONSTACK
96if the process is currently on a signal stack and
97.Dv SA_DISABLE
98if the signal stack is currently disabled.
99.Sh NOTES
100The value
101.Dv SIGSTKSZ
102is defined to be the number of bytes/chars that would be used to cover
103the usual case when allocating an alternate stack area.
104The following code fragment is typically used to allocate an alternate stack.
105.Bd -literal -offset indent
106if ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL)
107 /* error return */
108sigstk.ss_size = SIGSTKSZ;
109sigstk.ss_flags = 0;
110if (sigaltstack(&sigstk,0) < 0)
111 perror("sigaltstack");
112.Ed
113An alternative approach is provided for programs with signal handlers
114that require a specific amount of stack space other than the default size.
115The value
116.Dv MINSIGSTKSZ
117is defined to be the number of bytes/chars that is required by
118the operating system to implement the alternate stack feature.
119In computing an alternate stack size,
120programs should add
121.Dv MINSIGSTKSZ
122to their stack requirements to allow for the operating system overhead.
123.Pp
124Signal stacks are automatically adjusted for the direction of stack
125growth and alignment requirements.
126Signal stacks may or may not be protected by the hardware and
127are not ``grown'' automatically as is done for the normal stack.
128If the stack overflows and this space is not protected
129unpredictable results may occur.
130.Sh RETURN VALUES
131Upon successful completion, a value of 0 is returned.
132Otherwise, a value of -1 is returned and
133.Va errno
134is set to indicate the error.
135.Sh ERRORS
136.Fn Sigaltstack
137will fail and the signal stack context will remain unchanged
138if one of the following occurs.
139.Bl -tag -width [ENOMEM]
140.\" ===========
141.It Bq Er EFAULT
142Either
143.Fa ss
144or
145.Fa oss
146points to memory that is not a valid part of the process
147address space.
148.\" ===========
149.It Bq Er EINVAL
150An attempt is made to disable an active stack.
151.\" ===========
152.It Bq Er EINVAL
153The
154.Fa ss
155argument is not a null pointer, and the ss_flags member
156pointed to by
157.Fa ss
158contains flags other than SS_DISABLE.
159.\" ===========
160.It Bq Er ENOMEM
161The size of the alternate stack area is less than or equal to
162.Dv MINSIGSTKSZ .
163.\" ===========
164.It Bq Er EPERM
165An attempt was made to modify an active stack.
166.El
167.Sh LEGACY SYNOPSIS
168.Fd #include <sys/types.h>
169.Fd #include <signal.h>
170.Pp
171The include file
172.In sys/types.h
173is necessary.
174.Pp
175.Bd -literal
176struct sigaltstack {
177 char *ss_sp;
178 int ss_size;
179 int ss_flags;
180};
181.Ed
182.Pp
183.Ft int
184.br
185.Fo sigaltstack
186.Fa "const struct sigaltstack *ss"
187.Fa "struct sigaltstack *oss"
188.Fc ;
189.Pp
190The variable types have changed.
191Specifically, the
192.Vt sigaltstack
193struct is no longer used.
194.Sh COMPATIBILITY
195Use of the (obsolete)
196.Vt sigaltstack
197struct will cause compiler diagnostics.
198Use
199.Vt stack_t ,
200defined in
201.In signal.h .
202.Sh SEE ALSO
203.Xr sigaction 2 ,
204.Xr setjmp 3 ,
205.Xr compat 5
206.Sh HISTORY
207The predecessor to
208.Nm sigaltstack ,
209the
210.Fn sigstack
211system call, appeared in
212.Bx 4.2 .