SIGALTSTACK(3)             POSIX Programmer's Manual            SIGALTSTACK(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       sigaltstack -- set and get signal alternate stack context

SSYYNNOOPPSSIISS
       #include <signal.h>

       int sigaltstack(const stack_t *restrict _s_s, stack_t *restrict _o_s_s);

DDEESSCCRRIIPPTTIIOONN
       The _s_i_g_a_l_t_s_t_a_c_k() function allows a process to define and examine the
       state of an alternate stack for signal handlers for the current thread.
       Signals that have been explicitly declared to execute on the alternate
       stack shall be delivered on the alternate stack.

       If _s_s is not a null pointer, it points to a ssttaacckk__tt structure that
       specifies the alternate signal stack that shall take effect upon return
       from _s_i_g_a_l_t_s_t_a_c_k().  The _s_s___f_l_a_g_s member specifies the new stack state.
       If it is set to SS_DISABLE, the stack is disabled and _s_s___s_p and _s_s___s_i_z_e
       are ignored. Otherwise, the stack shall be enabled, and the _s_s___s_p and
       _s_s___s_i_z_e members specify the new address and size of the stack.

       The range of addresses starting at _s_s___s_p up to but not including
       _s_s___s_p+_s_s___s_i_z_e is available to the implementation for use as the stack.
       This function makes no assumptions regarding which end is the stack
       base and in which direction the stack grows as items are pushed.

       If _o_s_s is not a null pointer, upon successful completion it shall point
       to a ssttaacckk__tt structure that specifies the alternate signal stack that
       was in effect prior to the call to _s_i_g_a_l_t_s_t_a_c_k().  The _s_s___s_p and
       _s_s___s_i_z_e members specify the address and size of that stack. The
       _s_s___f_l_a_g_s member specifies the stack's state, and may contain one of the
       following values:

       SS_ONSTACK  The process is currently executing on the alternate signal
                   stack.  Attempts to modify the alternate signal stack while
                   the process is executing on it fail. This flag shall not be
                   modified by processes.

       SS_DISABLE  The alternate signal stack is currently disabled.

       The value SIGSTKSZ is a system default specifying the number of bytes
       that would be used to cover the usual case when manually allocating an
       alternate stack area. The value MINSIGSTKSZ is defined to be the
       minimum stack size for a signal handler. In computing an alternate
       stack size, a program should add that amount to its stack requirements
       to allow for the system implementation overhead. The constants
       SS_ONSTACK, SS_DISABLE, SIGSTKSZ, and MINSIGSTKSZ are defined in
       _<_s_i_g_n_a_l_._h_>.

       After a successful call to one of the _e_x_e_c functions, there are no
       alternate signal stacks in the new process image.

       In some implementations, a signal (whether or not indicated to execute
       on the alternate stack) shall always execute on the alternate stack if
       it is delivered while another signal is being caught using the
       alternate stack.

       Use of this function by library threads that are not bound to kernel-
       scheduled entities results in undefined behavior.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _s_i_g_a_l_t_s_t_a_c_k() shall return 0; otherwise, it
       shall return -1 and set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       The _s_i_g_a_l_t_s_t_a_c_k() function shall fail if:

       EEIINNVVAALL The _s_s argument is not a null pointer, and the _s_s___f_l_a_g_s member
              pointed to by _s_s contains flags other than SS_DISABLE.

       EENNOOMMEEMM The size of the alternate stack area is less than MINSIGSTKSZ.

       EEPPEERRMM  An attempt was made to modify an active stack.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   AAllllooccaattiinngg MMeemmoorryy ffoorr aann AAlltteerrnnaattee SSttaacckk
       The following example illustrates a method for allocating memory for an
       alternate stack.

           ##iinncclluuddee <<ssiiggnnaall..hh>>
           ......
           iiff ((((ssiiggssttkk..ssss__sspp == mmaalllloocc((SSIIGGSSTTKKSSZZ)))) ==== NNUULLLL))
               //** EErrrroorr rreettuurrnn.. **//
           ssiiggssttkk..ssss__ssiizzee == SSIIGGSSTTKKSSZZ;;
           ssiiggssttkk..ssss__ffllaaggss == 00;;
           iiff ((ssiiggaallttssttaacckk((&&ssiiggssttkk,,((ssttaacckk__tt **))00)) << 00))
               ppeerrrroorr((""ssiiggaallttssttaacckk""));;

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       On some implementations, stack space is automatically extended as
       needed. On those implementations, automatic extension is typically not
       available for an alternate stack. If the stack overflows, the behavior
       is undefined.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._4, _S_i_g_n_a_l _C_o_n_c_e_p_t_s, _e_x_e_c, _s_i_g_a_c_t_i_o_n(), _s_i_g_s_e_t_j_m_p()

       The Base Definitions volume of POSIX.1-2008, <<ssiiggnnaall..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                       SIGALTSTACK(3)
