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