Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

sigaltstack - set/read alternative stack of signal

&pagelevel(4)&pagelevel

Syntax

#include <signal.h>

int sigaltstack(const stack_t *ss, stack_t *oss);

Description

sigaltstack() is used to define an alternative stack in which signals can be processed. If ss is not zero, a pointer to a stack_t structure describing a stack on which the signals can be processed is expected. With sigaction you can specify which signals are to be handled on the alternative signal stack. The system then switches over to the signal stack for the duration of the signal-handling routine.

The stack_t structure contains the following components:

int     *ss_sp
long    ss_size
int     ss_flags

If ss is not zero, the stack_t structure describes an alternative signal stack, which becomes effective after the return of sigaltstack(). The components ss_sp and ss_size
determine the base and the size of the stack. The ss_flags component indicates the status of the new stack and can have the following values:

SS_DISABLE

The stack is deactivated and ss_sp and ss_size are ignored. If SS_DISABLE is not set, the stack will be activated.


If oss is not zero, on successful return from sigaltstack the structure contains the description of the alternative signal stack which was active before the sigaltstack() call. ss_sp and ss_size specify the base and the size of the stack.

The ss_flags component indicates the status of the stack and can have the following values:

SS_ONSTACK

The process is currently executed with the alternative signal stack. Any attempts to modify the alternative signal stack during execution of the process will fail.

SS_DISABLE

The alternative signal stack is currently deactivated.


The value SIGSTKSZ represents the number of bytes that are generally necessary for an alternative stack. The value MINSIGSTKSZ defines here the minimum stack size for a signalhandling routine. When computing the stack size the program should still set up this minimum value in addition, to take into account the operating system’s own requirements. The constants SS_ONSTACK, SS_DISABLE, SIGSTKSZ and MINSIGSTKSZ are defined in <signal.h>.

Return val.

0

if executed successfully.


-1

if an error occurs. errno is set to indicate the error.

Errors

sigaltstack() will fail if:

 

EPERM

An attempt was made to modify an active stack (deactivate).

 

EINVAL

The ss argument is not zero and the ss_flags component to which ss points contains other flags than SS_DISABLE.

 

ENOMEM

The size of the alternative stack area is less than MINSIGSTKSZ.

Notes

The following program excerpt is used to allocate an alternative stack area:

if ((sigstk.ss_sp = (char *)malloc(SIGSTKSZ)) == NULL)
         /* Error handling */;
sigstk.ss_size = SIGSTKSZ;
sigstk.ss_flags = 0;
if (sigaltstack(&sigstk, (stack_t *)0) < 0)
      perror("sigaltstack");

See also

sigaction(), sigsetjmp(), signal.h.