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