BSD 4_4_Lite2 release
[unix-history] / usr / src / lib / libc / sys / sigaltstack.2
CommitLineData
15715acc
KB
1.\" Copyright (c) 1983, 1991, 1992, 1993
2.\" The Regents of the University of California. All rights reserved.
e909eb9b 3.\"
ad787160
C
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
e909eb9b 19.\"
ad787160
C
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
e909eb9b 31.\"
fd88f5c5 32.\" @(#)sigaltstack.2 8.2 (Berkeley) 5/1/95
ad787160 33.\"
fd88f5c5 34.Dd May 1, 1995
e909eb9b
KM
35.Dt SIGALTSTACK 2
36.Os BSD 4.2
37.Sh NAME
38.Nm sigaltstack
39.Nd set and/or get signal stack context
40.Sh SYNOPSIS
41.Fd #include <sys/types.h>
4add9a99 42.Fd #include <signal.h>
e909eb9b
KM
43.Bd -literal
44struct sigaltstack {
c8eecfad 45 caddr_t ss_base;
e909eb9b
KM
46 long ss_size;
47 int ss_flags;
48};
49.Ed
50.Ft int
51.Fn sigaltstack "const struct sigaltstack *ss" "struct sigaltstack *oss"
52.Sh DESCRIPTION
53.Fn Sigaltstack
54allows users to define an alternate stack on which signals
55are to be processed.
56If
57.Fa ss
58is non-zero,
59it specifies a pointer to and the size of a
60.Em "signal stack"
61on which to deliver signals,
62and tells the system if the process is currently executing
63on that stack.
64When a signal's action indicates its handler
65should execute on the signal stack (specified with a
66.Xr sigaction 2
67call), the system checks to see
68if the process is currently executing on that stack.
69If the process is not currently executing on the signal stack,
70the system arranges a switch to the signal stack for the
71duration of the signal handler's execution.
72.Pp
73If
74.Dv SA_DISABLE
75is set in
76.Fa ss_flags ,
c8eecfad 77.Fa ss_base
e909eb9b
KM
78and
79.Fa ss_size
80are ignored and the signal stack will be disabled.
81Trying to disable an active stack will cause
82.Nm
83to return -1 with
84.Va errno
85set to
86.Dv EINVAL .
87A disabled stack will cause all signals to be
88taken on the regular user stack.
89If the stack is later re-enabled then all signals that were specified
90to be processed on an alternate stack will resume doing so.
91.Pp
92If
93.Fa oss
94is non-zero, the current signal stack state is returned.
95The
96.Fa ss_flags
97field will contain the value
98.Dv SA_ONSTACK
99if the process is currently on a signal stack and
100.Dv SA_DISABLE
101if the signal stack is currently disabled.
102.Sh NOTES
103The value
104.Dv SIGSTKSZ
105is defined to be the number of bytes/chars that would be used to cover
106the usual case when allocating an alternate stack area.
107The following code fragment is typically used to allocate an alternate stack.
108.Bd -literal -offset indent
c8eecfad 109if ((sigstk.ss_base = malloc(SIGSTKSZ)) == NULL)
e909eb9b
KM
110 /* error return */
111sigstk.ss_size = SIGSTKSZ;
112sigstk.ss_flags = 0;
113if (sigaltstack(&sigstk,0) < 0)
114 perror("sigaltstack");
115.Ed
116An alternative approach is provided for programs with signal handlers
117that require a specific amount of stack space other than the default size.
118The value
119.Dv MINSIGSTKSZ
120is defined to be the number of bytes/chars that is required by
121the operating system to implement the alternate stack feature.
122In computing an alternate stack size,
123programs should add
124.Dv MINSIGSTKSZ
125to their stack requirements to allow for the operating system overhead.
126.Pp
127Signal stacks are automatically adjusted for the direction of stack
128growth and alignment requirements.
129Signal stacks may or may not be protected by the hardware and
130are not ``grown'' automatically as is done for the normal stack.
131If the stack overflows and this space is not protected
132unpredictable results may occur.
133.Sh RETURN VALUES
134Upon successful completion, a value of 0 is returned.
135Otherwise, a value of -1 is returned and
136.Va errno
137is set to indicate the error.
138.Sh ERRORS
139.Fn Sigstack
140will fail and the signal stack context will remain unchanged
141if one of the following occurs.
142.Bl -tag -width [ENOMEM]
143.It Bq Er EFAULT
144Either
145.Fa ss
146or
147.Fa oss
148points to memory that is not a valid part of the process
149address space.
150.It Bq Er EINVAL
151An attempt was made to disable an active stack.
152.It Bq Er ENOMEM
153Size of alternate stack area is less than or equal to
154.Dv MINSIGSTKSZ .
155.El
156.Sh SEE ALSO
157.Xr sigaction 2 ,
158.Xr setjmp 3
159.Sh HISTORY
160The predecessor to
161.Nm sigaltstack ,
162the
163.Fn sigstack
164system call, appeared in
165.Bx 4.2 .