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