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

NAME

12       sigaltstack - set and get signal alternate stack context
13

SYNOPSIS

15       #include <signal.h>
16
17       int sigaltstack(const stack_t *restrict ss, stack_t *restrict oss);
18
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 ss_sp+
34       ss_size  is  available to the implementation for use as the stack. This
35       function makes no assumptions regarding which end is the stack base and
36       in which direction the stack grows as items are pushed.
37
38       If  oss  is not a null pointer, on 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
46              The process is  currently  executing  on  the  alternate  signal
47              stack.   Attempts to modify the alternate signal stack while the
48              process is executing on it fail. This flag shall not be modified
49              by processes.
50
51       SS_DISABLE
52              The alternate signal stack is currently disabled.
53
54
55       The  value  SIGSTKSZ is a system default specifying the number of bytes
56       that would be used to cover the usual case when manually allocating  an
57       alternate  stack area. The value MINSIGSTKSZ is defined to be the mini‐
58       mum stack size for a signal handler. In computing  an  alternate  stack
59       size,  a  program  should  add that amount to its stack requirements to
60       allow for the system implementation overhead. The constants SS_ONSTACK,
61       SS_DISABLE, SIGSTKSZ, and MINSIGSTKSZ are defined in <signal.h>.
62
63       After  a  successful  call  to  one of the exec functions, there are no
64       alternate signal stacks in the new process image.
65
66       In some implementations, a signal (whether or not indicated to  execute
67       on  the alternate stack) shall always execute on the alternate stack if
68       it is delivered while another signal is being caught using  the  alter‐
69       nate stack.
70
71       Use  of  this function by library threads that are not bound to kernel-
72       scheduled entities results in undefined behavior.
73

RETURN VALUE

75       Upon successful completion, sigaltstack() shall return 0; otherwise, it
76       shall return -1 and set errno to indicate the error.
77

ERRORS

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

EXAMPLES

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

APPLICATION USAGE

107       On  some  implementations,  stack  space  is  automatically extended as
108       needed. On those implementations, automatic extension is typically  not
109       available  for an alternate stack. If the stack overflows, the behavior
110       is undefined.
111

RATIONALE

113       None.
114

FUTURE DIRECTIONS

116       None.
117

SEE ALSO

119       Signal Concepts, sigaction(), sigsetjmp(), the Base Definitions  volume
120       of IEEE Std 1003.1-2001, <signal.h>
121
123       Portions  of  this text are reprinted and reproduced in electronic form
124       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
125       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
126       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
127       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
128       event of any discrepancy between this version and the original IEEE and
129       The  Open Group Standard, the original IEEE and The Open Group Standard
130       is the referee document. The original Standard can be  obtained  online
131       at http://www.opengroup.org/unix/online.html .
132
133
134
135IEEE/The Open Group                  2003                      SIGALTSTACK(3P)
Impressum