Node:Signal Stack, Next:BSD Signal Handling, Previous:Waiting for a Signal, Up:Signal Handling
A signal stack is a special area of memory to be used as the execution
stack during signal handlers. It should be fairly large, to avoid any
danger that it will overflow in turn; the macro SIGSTKSZ
is
defined to a canonical size for signal stacks. You can use
malloc
to allocate the space for the stack. Then call
sigaltstack
or sigstack
to tell the system to use that
space for the signal stack.
You don't need to write signal handlers differently in order to use a signal stack. Switching from one stack to the other happens automatically. (Some non-GNU debuggers on some machines may get confused if you examine a stack trace while a handler that uses the signal stack is running.)
There are two interfaces for telling the system to use a separate signal
stack. sigstack
is the older interface, which comes from 4.2
BSD. sigaltstack
is the newer interface, and comes from 4.4
BSD. The sigaltstack
interface has the advantage that it does
not require your program to know which direction the stack grows, which
depends on the specific machine and operating system.
stack_t | Data Type |
This structure describes a signal stack. It contains the following members:
|
int sigaltstack (const stack_t *restrict stack, stack_t *restrict oldstack) | Function |
The sigaltstack function specifies an alternate stack for use
during signal handling. When a signal is received by the process and
its action indicates that the signal stack is used, the system arranges
a switch to the currently installed signal stack while the handler for
that signal is executed.
If oldstack is not a null pointer, information about the currently installed signal stack is returned in the location it points to. If stack is not a null pointer, then this is installed as the new stack for use by signal handlers. The return value is
|
Here is the older sigstack
interface. You should use
sigaltstack
instead on systems that have it.
struct sigstack | Data Type |
This structure describes a signal stack. It contains the following members:
|
int sigstack (const struct sigstack *stack, struct sigstack *oldstack) | Function |
The sigstack function specifies an alternate stack for use during
signal handling. When a signal is received by the process and its
action indicates that the signal stack is used, the system arranges a
switch to the currently installed signal stack while the handler for
that signal is executed.
If oldstack is not a null pointer, information about the currently installed signal stack is returned in the location it points to. If stack is not a null pointer, then this is installed as the new stack for use by signal handlers. The return value is |