xref: /minix3/lib/libc/sys/sigaltstack.2 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: sigaltstack.2,v 1.24 2014/09/27 12:11:13 njoly Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 1983, 1991, 1992, 1993
42fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
72fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
82fe8fb19SBen Gras.\" are met:
92fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
102fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
112fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
122fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
132fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
142fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
152fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
162fe8fb19SBen Gras.\"    without specific prior written permission.
172fe8fb19SBen Gras.\"
182fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
192fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
222fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
232fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
242fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
252fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
262fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
272fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
282fe8fb19SBen Gras.\" SUCH DAMAGE.
292fe8fb19SBen Gras.\"
302fe8fb19SBen Gras.\"     @(#)sigaltstack.2	8.2 (Berkeley) 5/1/95
312fe8fb19SBen Gras.\"
32f14fb602SLionel Sambuc.Dd March 2, 2012
332fe8fb19SBen Gras.Dt SIGALTSTACK 2
342fe8fb19SBen Gras.Os
352fe8fb19SBen Gras.Sh NAME
362fe8fb19SBen Gras.Nm sigaltstack
372fe8fb19SBen Gras.Nd set and/or get signal stack context
382fe8fb19SBen Gras.Sh LIBRARY
392fe8fb19SBen Gras.Lb libc
402fe8fb19SBen Gras.Sh SYNOPSIS
412fe8fb19SBen Gras.In signal.h
422fe8fb19SBen Gras.Bd -literal
432fe8fb19SBen Grastypedef struct sigaltstack {
442fe8fb19SBen Gras	void   *ss_sp;
452fe8fb19SBen Gras	size_t	ss_size;
462fe8fb19SBen Gras	int     ss_flags;
472fe8fb19SBen Gras} stack_t;
482fe8fb19SBen Gras.Ed
49*0a6a1f1dSLionel Sambuc.Pp
502fe8fb19SBen Gras.Ft int
512fe8fb19SBen Gras.Fn sigaltstack "const stack_t * restrict ss" "stack_t * restrict oss"
522fe8fb19SBen Gras.Sh DESCRIPTION
532fe8fb19SBen Gras.Fn sigaltstack
542fe8fb19SBen Grasallows users to define an alternative stack on which signals
552fe8fb19SBen Grasare to be processed.
562fe8fb19SBen GrasIf
572fe8fb19SBen Gras.Fa ss
582fe8fb19SBen Grasis non-zero,
592fe8fb19SBen Grasit specifies a pointer to and the size of a
602fe8fb19SBen Gras.Em "signal stack"
612fe8fb19SBen Grason which to deliver signals,
622fe8fb19SBen Grasand tells the system if the process is currently executing
632fe8fb19SBen Grason that stack.
642fe8fb19SBen GrasWhen a signal's action indicates its handler
652fe8fb19SBen Grasshould execute on the signal stack (specified with a
662fe8fb19SBen Gras.Xr sigaction 2
672fe8fb19SBen Grascall), the system checks to see
682fe8fb19SBen Grasif the process is currently executing on that stack.
692fe8fb19SBen GrasIf the process is not currently executing on the signal stack,
702fe8fb19SBen Grasthe system arranges a switch to the signal stack for the
712fe8fb19SBen Grasduration of the signal handler's execution.
722fe8fb19SBen Gras.Pp
732fe8fb19SBen GrasIf
742fe8fb19SBen Gras.Dv SS_DISABLE
752fe8fb19SBen Grasis set in
762fe8fb19SBen Gras.Fa ss_flags ,
772fe8fb19SBen Gras.Fa ss_sp
782fe8fb19SBen Grasand
792fe8fb19SBen Gras.Fa ss_size
802fe8fb19SBen Grasare ignored and the signal stack will be disabled.
812fe8fb19SBen GrasTrying to disable an active stack will cause
822fe8fb19SBen Gras.Nm
832fe8fb19SBen Grasto return \-1 with
842fe8fb19SBen Gras.Va errno
852fe8fb19SBen Grasset to
862fe8fb19SBen Gras.Er EINVAL .
872fe8fb19SBen GrasA disabled stack will cause all signals to be
882fe8fb19SBen Grastaken on the regular user stack.
892fe8fb19SBen GrasIf the stack is later re-enabled then all signals that were specified
902fe8fb19SBen Grasto be processed on an alternative stack will resume doing so.
912fe8fb19SBen Gras.Pp
922fe8fb19SBen GrasIf
932fe8fb19SBen Gras.Fa oss
942fe8fb19SBen Grasis non-zero, the current signal stack state is returned.
952fe8fb19SBen GrasThe
962fe8fb19SBen Gras.Fa ss_flags
972fe8fb19SBen Grasfield will contain the value
982fe8fb19SBen Gras.Dv SS_ONSTACK
992fe8fb19SBen Grasif the process is currently on a signal stack and
1002fe8fb19SBen Gras.Dv SS_DISABLE
1012fe8fb19SBen Grasif the signal stack is currently disabled.
1022fe8fb19SBen Gras.Sh NOTES
1032fe8fb19SBen GrasThe value
1042fe8fb19SBen Gras.Dv SIGSTKSZ
1052fe8fb19SBen Grasis defined to be the number of bytes/chars that would be used to cover
1062fe8fb19SBen Grasthe usual case when allocating an alternative stack area.
1072fe8fb19SBen GrasThe following code fragment is typically used to allocate an alternative stack.
1082fe8fb19SBen Gras.Bd -literal -offset indent
1092fe8fb19SBen Grasif ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL)
1102fe8fb19SBen Gras	/* error return */
1112fe8fb19SBen Grassigstk.ss_size = SIGSTKSZ;
1122fe8fb19SBen Grassigstk.ss_flags = 0;
1132fe8fb19SBen Grasif (sigaltstack(\*[Am]sigstk,0) \*[Lt] 0)
1142fe8fb19SBen Gras	perror("sigaltstack");
1152fe8fb19SBen Gras.Ed
1162fe8fb19SBen Gras.Pp
1172fe8fb19SBen GrasAn alternative approach is provided for programs with signal handlers
1182fe8fb19SBen Grasthat require a specific amount of stack space other than the default size.
1192fe8fb19SBen GrasThe value
1202fe8fb19SBen Gras.Dv MINSIGSTKSZ
1212fe8fb19SBen Grasis defined to be the number of bytes/chars that is required by
1222fe8fb19SBen Grasthe operating system to implement the alternative stack feature.
1232fe8fb19SBen GrasIn computing an alternative stack size,
1242fe8fb19SBen Grasprograms should add
1252fe8fb19SBen Gras.Dv MINSIGSTKSZ
1262fe8fb19SBen Grasto their stack requirements to allow for the operating system overhead.
1272fe8fb19SBen Gras.Pp
1282fe8fb19SBen GrasSignal stacks are automatically adjusted for the direction of stack
1292fe8fb19SBen Grasgrowth and alignment requirements.
1302fe8fb19SBen GrasSignal stacks may or may not be protected by the hardware and
1312fe8fb19SBen Grasare not ``grown'' automatically as is done for the normal stack.
1322fe8fb19SBen GrasIf the stack overflows and this space is not protected
1332fe8fb19SBen Grasunpredictable results may occur.
1342fe8fb19SBen Gras.Sh RETURN VALUES
135*0a6a1f1dSLionel Sambuc.Rv -std
1362fe8fb19SBen Gras.Sh ERRORS
1372fe8fb19SBen Gras.Fn sigaltstack
1382fe8fb19SBen Graswill fail and the signal stack context will remain unchanged
1392fe8fb19SBen Grasif one of the following occurs.
1402fe8fb19SBen Gras.Bl -tag -width Er
1412fe8fb19SBen Gras.It Bq Er EFAULT
1422fe8fb19SBen GrasEither
1432fe8fb19SBen Gras.Fa ss
1442fe8fb19SBen Grasor
1452fe8fb19SBen Gras.Fa oss
1462fe8fb19SBen Graspoints to memory that is not a valid part of the process
1472fe8fb19SBen Grasaddress space.
1482fe8fb19SBen Gras.It Bq Er EINVAL
1492fe8fb19SBen GrasAn attempt was made to disable an active stack.
1502fe8fb19SBen Gras.It Bq Er ENOMEM
1512fe8fb19SBen GrasSize of alternative stack area is less than
1522fe8fb19SBen Gras.Dv MINSIGSTKSZ .
1532fe8fb19SBen Gras.El
1542fe8fb19SBen Gras.Sh SEE ALSO
1552fe8fb19SBen Gras.Xr sigaction 2 ,
1562fe8fb19SBen Gras.Xr setjmp 3 ,
1572fe8fb19SBen Gras.Xr signal 7
1582fe8fb19SBen Gras.Sh STANDARDS
1592fe8fb19SBen GrasThe
1602fe8fb19SBen Gras.Fn sigaltstack
1612fe8fb19SBen Grasfunction conforms to
1622fe8fb19SBen Gras.St -xpg4.2 .
1632fe8fb19SBen Gras.Sh HISTORY
1642fe8fb19SBen GrasThe predecessor to
1652fe8fb19SBen Gras.Nm sigaltstack ,
1662fe8fb19SBen Grasthe
1672fe8fb19SBen Gras.Fn sigstack
1682fe8fb19SBen Grassystem call, appeared in
1692fe8fb19SBen Gras.Bx 4.2 .
170