xref: /minix/lib/libc/sys/sigaltstack.2 (revision 0a6a1f1d)
1.\"	$NetBSD: sigaltstack.2,v 1.24 2014/09/27 12:11:13 njoly 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. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)sigaltstack.2	8.2 (Berkeley) 5/1/95
31.\"
32.Dd March 2, 2012
33.Dt SIGALTSTACK 2
34.Os
35.Sh NAME
36.Nm sigaltstack
37.Nd set and/or get signal stack context
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In signal.h
42.Bd -literal
43typedef struct sigaltstack {
44	void   *ss_sp;
45	size_t	ss_size;
46	int     ss_flags;
47} stack_t;
48.Ed
49.Pp
50.Ft int
51.Fn sigaltstack "const stack_t * restrict ss" "stack_t * restrict oss"
52.Sh DESCRIPTION
53.Fn sigaltstack
54allows users to define an alternative 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 SS_DISABLE
75is set in
76.Fa ss_flags ,
77.Fa ss_sp
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.Er 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 alternative 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 SS_ONSTACK
99if the process is currently on a signal stack and
100.Dv SS_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 alternative stack area.
107The following code fragment is typically used to allocate an alternative stack.
108.Bd -literal -offset indent
109if ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL)
110	/* error return */
111sigstk.ss_size = SIGSTKSZ;
112sigstk.ss_flags = 0;
113if (sigaltstack(\*[Am]sigstk,0) \*[Lt] 0)
114	perror("sigaltstack");
115.Ed
116.Pp
117An alternative approach is provided for programs with signal handlers
118that require a specific amount of stack space other than the default size.
119The value
120.Dv MINSIGSTKSZ
121is defined to be the number of bytes/chars that is required by
122the operating system to implement the alternative stack feature.
123In computing an alternative stack size,
124programs should add
125.Dv MINSIGSTKSZ
126to their stack requirements to allow for the operating system overhead.
127.Pp
128Signal stacks are automatically adjusted for the direction of stack
129growth and alignment requirements.
130Signal stacks may or may not be protected by the hardware and
131are not ``grown'' automatically as is done for the normal stack.
132If the stack overflows and this space is not protected
133unpredictable results may occur.
134.Sh RETURN VALUES
135.Rv -std
136.Sh ERRORS
137.Fn sigaltstack
138will fail and the signal stack context will remain unchanged
139if one of the following occurs.
140.Bl -tag -width Er
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.It Bq Er EINVAL
149An attempt was made to disable an active stack.
150.It Bq Er ENOMEM
151Size of alternative stack area is less than
152.Dv MINSIGSTKSZ .
153.El
154.Sh SEE ALSO
155.Xr sigaction 2 ,
156.Xr setjmp 3 ,
157.Xr signal 7
158.Sh STANDARDS
159The
160.Fn sigaltstack
161function conforms to
162.St -xpg4.2 .
163.Sh HISTORY
164The predecessor to
165.Nm sigaltstack ,
166the
167.Fn sigstack
168system call, appeared in
169.Bx 4.2 .
170