1SIGALTSTACK(3P)            POSIX Programmer's Manual           SIGALTSTACK(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       sigaltstack — set and get signal alternate stack context
14

SYNOPSIS

16       #include <signal.h>
17
18       int sigaltstack(const stack_t *restrict ss, stack_t *restrict oss);
19

DESCRIPTION

21       The sigaltstack() function allows a process to define and  examine  the
22       state of an alternate stack for signal handlers for the current thread.
23       Signals that have been explicitly declared to execute on the  alternate
24       stack shall be delivered on the alternate stack.
25
26       If  ss  is  not  a  null pointer, it points to a stack_t structure that
27       specifies the alternate signal stack that shall take effect upon return
28       from sigaltstack().  The ss_flags member specifies the new stack state.
29       If it is set to SS_DISABLE, the stack is disabled and ss_sp and ss_size
30       are  ignored.  Otherwise, the stack shall be enabled, and the ss_sp and
31       ss_size members specify the new address and size of the stack.
32
33       The range of addresses starting  at  ss_sp  up  to  but  not  including
34       ss_sp+ss_size  is available to the implementation for use as the stack.
35       This function makes no assumptions regarding which  end  is  the  stack
36       base and in which direction the stack grows as items are pushed.
37
38       If oss is not a null pointer, upon successful completion it shall point
39       to a stack_t structure that specifies the alternate signal  stack  that
40       was  in  effect  prior  to  the  call  to sigaltstack().  The ss_sp and
41       ss_size members specify  the  address  and  size  of  that  stack.  The
42       ss_flags member specifies the stack's state, and may contain one of the
43       following values:
44
45       SS_ONSTACK  The process is currently executing on the alternate  signal
46                   stack.  Attempts to modify the alternate signal stack while
47                   the process is executing on it fail. This flag shall not be
48                   modified by processes.
49
50       SS_DISABLE  The alternate signal stack is currently disabled.
51
52       The  value  SIGSTKSZ is a system default specifying the number of bytes
53       that would be used to cover the usual case when manually allocating  an
54       alternate  stack area. The value MINSIGSTKSZ is defined to be the mini‐
55       mum stack size for a signal handler. In computing  an  alternate  stack
56       size,  a  program  should  add that amount to its stack requirements to
57       allow for the system implementation overhead. The constants SS_ONSTACK,
58       SS_DISABLE, SIGSTKSZ, and MINSIGSTKSZ are defined in <signal.h>.
59
60       After  a  successful  call  to  one of the exec functions, there are no
61       alternate signal stacks in the new process image.
62
63       In some implementations, a signal (whether or not indicated to  execute
64       on  the alternate stack) shall always execute on the alternate stack if
65       it is delivered while another signal is being caught using  the  alter‐
66       nate stack.
67
68       Use  of  this function by library threads that are not bound to kernel-
69       scheduled entities results in undefined behavior.
70

RETURN VALUE

72       Upon successful completion, sigaltstack() shall return 0; otherwise, it
73       shall return −1 and set errno to indicate the error.
74

ERRORS

76       The sigaltstack() function shall fail if:
77
78       EINVAL The  ss  argument is not a null pointer, and the ss_flags member
79              pointed to by ss contains flags other than SS_DISABLE.
80
81       ENOMEM The size of the alternate stack area is less than MINSIGSTKSZ.
82
83       EPERM  An attempt was made to modify an active stack.
84
85       The following sections are informative.
86

EXAMPLES

88   Allocating Memory for an Alternate Stack
89       The following example illustrates a method for allocating memory for an
90       alternate stack.
91
92           #include <signal.h>
93           ...
94           if ((sigstk.ss_sp = malloc(SIGSTKSZ)) == NULL)
95               /* Error return. */
96           sigstk.ss_size = SIGSTKSZ;
97           sigstk.ss_flags = 0;
98           if (sigaltstack(&sigstk,(stack_t *)0) < 0)
99               perror("sigaltstack");
100

APPLICATION USAGE

102       On  some  implementations,  stack  space  is  automatically extended as
103       needed. On those implementations, automatic extension is typically  not
104       available  for an alternate stack. If the stack overflows, the behavior
105       is undefined.
106

RATIONALE

108       None.
109

FUTURE DIRECTIONS

111       None.
112

SEE ALSO

114       Section 2.4, Signal Concepts, exec, sigaction(), sigsetjmp()
115
116       The Base Definitions volume of POSIX.1‐2008, <signal.h>
117
119       Portions of this text are reprinted and reproduced in  electronic  form
120       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
121       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
122       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
123       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
124       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
125       event of any discrepancy between this version and the original IEEE and
126       The  Open Group Standard, the original IEEE and The Open Group Standard
127       is the referee document. The original Standard can be  obtained  online
128       at http://www.unix.org/online.html .
129
130       Any  typographical  or  formatting  errors that appear in this page are
131       most likely to have been introduced during the conversion of the source
132       files  to  man page format. To report such errors, see https://www.ker
133       nel.org/doc/man-pages/reporting_bugs.html .
134
135
136
137IEEE/The Open Group                  2013                      SIGALTSTACK(3P)
Impressum