xref: /csrg-svn/lib/libc/sys/sigaltstack.2 (revision 69141)
161185Sbostic.\" Copyright (c) 1983, 1991, 1992, 1993
261185Sbostic.\"	The Regents of the University of California.  All rights reserved.
353255Smckusick.\"
453255Smckusick.\" %sccs.include.redist.man%
553255Smckusick.\"
6*69141Smckusick.\"     @(#)sigaltstack.2	8.2 (Berkeley) 05/01/95
753255Smckusick.\"
853255Smckusick.Dd
953255Smckusick.Dt SIGALTSTACK 2
1053255Smckusick.Os BSD 4.2
1153255Smckusick.Sh NAME
1253255Smckusick.Nm sigaltstack
1353255Smckusick.Nd set and/or get signal stack context
1453255Smckusick.Sh SYNOPSIS
1553255Smckusick.Fd #include <sys/types.h>
1655757Sbostic.Fd #include <signal.h>
1753255Smckusick.Bd -literal
1853255Smckusickstruct sigaltstack {
19*69141Smckusick	caddr_t ss_base;
2053255Smckusick	long	ss_size;
2153255Smckusick	int     ss_flags;
2253255Smckusick};
2353255Smckusick.Ed
2453255Smckusick.Ft int
2553255Smckusick.Fn sigaltstack "const struct sigaltstack *ss" "struct sigaltstack *oss"
2653255Smckusick.Sh DESCRIPTION
2753255Smckusick.Fn Sigaltstack
2853255Smckusickallows users to define an alternate stack on which signals
2953255Smckusickare to be processed.
3053255SmckusickIf
3153255Smckusick.Fa ss
3253255Smckusickis non-zero,
3353255Smckusickit specifies a pointer to and the size of a
3453255Smckusick.Em "signal stack"
3553255Smckusickon which to deliver signals,
3653255Smckusickand tells the system if the process is currently executing
3753255Smckusickon that stack.
3853255SmckusickWhen a signal's action indicates its handler
3953255Smckusickshould execute on the signal stack (specified with a
4053255Smckusick.Xr sigaction 2
4153255Smckusickcall), the system checks to see
4253255Smckusickif the process is currently executing on that stack.
4353255SmckusickIf the process is not currently executing on the signal stack,
4453255Smckusickthe system arranges a switch to the signal stack for the
4553255Smckusickduration of the signal handler's execution.
4653255Smckusick.Pp
4753255SmckusickIf
4853255Smckusick.Dv SA_DISABLE
4953255Smckusickis set in
5053255Smckusick.Fa ss_flags ,
51*69141Smckusick.Fa ss_base
5253255Smckusickand
5353255Smckusick.Fa ss_size
5453255Smckusickare ignored and the signal stack will be disabled.
5553255SmckusickTrying to disable an active stack will cause
5653255Smckusick.Nm
5753255Smckusickto return -1 with
5853255Smckusick.Va errno
5953255Smckusickset to
6053255Smckusick.Dv EINVAL .
6153255SmckusickA disabled stack will cause all signals to be
6253255Smckusicktaken on the regular user stack.
6353255SmckusickIf the stack is later re-enabled then all signals that were specified
6453255Smckusickto be processed on an alternate stack will resume doing so.
6553255Smckusick.Pp
6653255SmckusickIf
6753255Smckusick.Fa oss
6853255Smckusickis non-zero, the current signal stack state is returned.
6953255SmckusickThe
7053255Smckusick.Fa ss_flags
7153255Smckusickfield will contain the value
7253255Smckusick.Dv SA_ONSTACK
7353255Smckusickif the process is currently on a signal stack and
7453255Smckusick.Dv SA_DISABLE
7553255Smckusickif the signal stack is currently disabled.
7653255Smckusick.Sh NOTES
7753255SmckusickThe value
7853255Smckusick.Dv SIGSTKSZ
7953255Smckusickis defined to be the number of bytes/chars that would be used to cover
8053255Smckusickthe usual case when allocating an alternate stack area.
8153255SmckusickThe following code fragment is typically used to allocate an alternate stack.
8253255Smckusick.Bd -literal -offset indent
83*69141Smckusickif ((sigstk.ss_base = malloc(SIGSTKSZ)) == NULL)
8453255Smckusick	/* error return */
8553255Smckusicksigstk.ss_size = SIGSTKSZ;
8653255Smckusicksigstk.ss_flags = 0;
8753255Smckusickif (sigaltstack(&sigstk,0) < 0)
8853255Smckusick	perror("sigaltstack");
8953255Smckusick.Ed
9053255SmckusickAn alternative approach is provided for programs with signal handlers
9153255Smckusickthat require a specific amount of stack space other than the default size.
9253255SmckusickThe value
9353255Smckusick.Dv MINSIGSTKSZ
9453255Smckusickis defined to be the number of bytes/chars that is required by
9553255Smckusickthe operating system to implement the alternate stack feature.
9653255SmckusickIn computing an alternate stack size,
9753255Smckusickprograms should add
9853255Smckusick.Dv MINSIGSTKSZ
9953255Smckusickto their stack requirements to allow for the operating system overhead.
10053255Smckusick.Pp
10153255SmckusickSignal stacks are automatically adjusted for the direction of stack
10253255Smckusickgrowth and alignment requirements.
10353255SmckusickSignal stacks may or may not be protected by the hardware and
10453255Smckusickare not ``grown'' automatically as is done for the normal stack.
10553255SmckusickIf the stack overflows and this space is not protected
10653255Smckusickunpredictable results may occur.
10753255Smckusick.Sh RETURN VALUES
10853255SmckusickUpon successful completion, a value of 0 is returned.
10953255SmckusickOtherwise, a value of -1 is returned and
11053255Smckusick.Va errno
11153255Smckusickis set to indicate the error.
11253255Smckusick.Sh ERRORS
11353255Smckusick.Fn Sigstack
11453255Smckusickwill fail and the signal stack context will remain unchanged
11553255Smckusickif one of the following occurs.
11653255Smckusick.Bl -tag -width [ENOMEM]
11753255Smckusick.It Bq Er EFAULT
11853255SmckusickEither
11953255Smckusick.Fa ss
12053255Smckusickor
12153255Smckusick.Fa oss
12253255Smckusickpoints to memory that is not a valid part of the process
12353255Smckusickaddress space.
12453255Smckusick.It Bq Er EINVAL
12553255SmckusickAn attempt was made to disable an active stack.
12653255Smckusick.It Bq Er ENOMEM
12753255SmckusickSize of alternate stack area is less than or equal to
12853255Smckusick.Dv MINSIGSTKSZ .
12953255Smckusick.El
13053255Smckusick.Sh SEE ALSO
13153255Smckusick.Xr sigaction 2 ,
13253255Smckusick.Xr setjmp 3
13353255Smckusick.Sh HISTORY
13453255SmckusickThe predecessor to
13553255Smckusick.Nm sigaltstack ,
13653255Smckusickthe
13753255Smckusick.Fn sigstack
13853255Smckusicksystem call, appeared in
13953255Smckusick.Bx 4.2 .
140