open - implement O_DIRECTORY
[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. 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.
19 .\"
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.
31 .\"
32 .\"     @(#)sigaltstack.2       8.2 (Berkeley) 5/1/95
33 .\" $FreeBSD: src/lib/libc/sys/sigaltstack.2,v 1.11.2.7 2002/09/15 00:32:41 archie Exp $
34 .\" $DragonFly: src/lib/libc/sys/sigaltstack.2,v 1.2 2003/06/17 04:26:47 dillon Exp $
35 .\"
36 .Dd May 1, 1995
37 .Dt SIGALTSTACK 2
38 .Os
39 .Sh NAME
40 .Nm sigaltstack
41 .Nd set and/or get signal stack context
42 .Sh LIBRARY
43 .Lb libc
44 .Sh SYNOPSIS
45 .In signal.h
46 .Bd -literal
47 typedef struct sigaltstack {
48         char    *ss_sp;
49         size_t  ss_size;
50         int     ss_flags;
51 } stack_t;
52 .Ed
53 .Ft int
54 .Fn sigaltstack "const stack_t *ss" "stack_t *oss"
55 .Sh DESCRIPTION
56 .Fn Sigaltstack
57 allows users to define an alternate stack on which signals
58 are to be processed.
59 If
60 .Fa ss
61 is non-zero,
62 it specifies a pointer to and the size of a
63 .Em "signal stack"
64 on which to deliver signals,
65 and tells the system if the process is currently executing
66 on that stack.
67 When a signal's action indicates its handler
68 should execute on the signal stack (specified with a
69 .Xr sigaction 2
70 call), the system checks to see
71 if the process is currently executing on that stack.
72 If the process is not currently executing on the signal stack,
73 the system arranges a switch to the signal stack for the
74 duration of the signal handler's execution.
75 .Pp
76 If
77 .Dv SS_DISABLE
78 is set in
79 .Fa ss_flags ,
80 .Fa ss_sp
81 and
82 .Fa ss_size
83 are ignored and the signal stack will be disabled.
84 Trying to disable an active stack will cause
85 .Fn sigaltstack
86 to return -1 with
87 .Va errno
88 set to
89 .Er EINVAL .
90 A disabled stack will cause all signals to be
91 taken on the regular user stack.
92 If the stack is later re-enabled then all signals that were specified
93 to be processed on an alternate stack will resume doing so.
94 .Pp
95 If
96 .Fa oss
97 is non-zero, the current signal stack state is returned.
98 The
99 .Fa ss_flags
100 field will contain the value
101 .Dv SS_ONSTACK
102 if the process is currently on a signal stack and
103 .Dv SS_DISABLE
104 if the signal stack is currently disabled.
105 .Sh NOTES
106 The value
107 .Dv SIGSTKSZ
108 is defined to be the number of bytes/chars that would be used to cover
109 the usual case when allocating an alternate stack area.
110 The following code fragment is typically used to allocate an alternate stack.
111 .Bd -literal -offset indent
112 if ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL)
113         /* error return */
114 sigstk.ss_size = SIGSTKSZ;
115 sigstk.ss_flags = 0;
116 if (sigaltstack(&sigstk,0) < 0)
117         perror("sigaltstack");
118 .Ed
119 An alternative approach is provided for programs with signal handlers
120 that require a specific amount of stack space other than the default size.
121 The value
122 .Dv MINSIGSTKSZ
123 is defined to be the number of bytes/chars that is required by
124 the operating system to implement the alternate stack feature.
125 In computing an alternate stack size,
126 programs should add
127 .Dv MINSIGSTKSZ
128 to their stack requirements to allow for the operating system overhead.
129 .Pp
130 Signal stacks are automatically adjusted for the direction of stack
131 growth and alignment requirements.
132 Signal stacks may or may not be protected by the hardware and
133 are not ``grown'' automatically as is done for the normal stack.
134 If the stack overflows and this space is not protected
135 unpredictable results may occur.
136 .Sh RETURN VALUES
137 .Rv -std sigaltstack
138 .Sh ERRORS
139 .Fn Sigaltstack
140 will fail and the signal stack context will remain unchanged
141 if one of the following occurs.
142 .Bl -tag -width Er
143 .It Bq Er EFAULT
144 Either
145 .Fa ss
146 or
147 .Fa oss
148 points to memory that is not a valid part of the process
149 address space.
150 .It Bq Er EINVAL
151 An attempt was made to disable an active stack.
152 .It Bq Er ENOMEM
153 Size 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
160 The predecessor to
161 .Fn sigaltstack ,
162 the
163 .Fn sigstack
164 system call, appeared in
165 .Bx 4.2 .