PTHREAD_ATTR_GETGUARDSIZE(3)POSIX Programmer's ManuaPlTHREAD_ATTR_GETGUARDSIZE(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
       pthread_attr_getguardsize, pthread_attr_setguardsize -- get and set the
       thread guardsize attribute

SSYYNNOOPPSSIISS
       #include <pthread.h>

       int pthread_attr_getguardsize(const pthread_attr_t *restrict _a_t_t_r,
           size_t *restrict _g_u_a_r_d_s_i_z_e);
       int pthread_attr_setguardsize(pthread_attr_t *_a_t_t_r,
           size_t _g_u_a_r_d_s_i_z_e);

DDEESSCCRRIIPPTTIIOONN
       The _p_t_h_r_e_a_d___a_t_t_r___g_e_t_g_u_a_r_d_s_i_z_e() function shall get the _g_u_a_r_d_s_i_z_e
       attribute in the _a_t_t_r object. This attribute shall be returned in the
       _g_u_a_r_d_s_i_z_e parameter.

       The _p_t_h_r_e_a_d___a_t_t_r___s_e_t_g_u_a_r_d_s_i_z_e() function shall set the _g_u_a_r_d_s_i_z_e
       attribute in the _a_t_t_r object. The new value of this attribute shall be
       obtained from the _g_u_a_r_d_s_i_z_e parameter. If _g_u_a_r_d_s_i_z_e is zero, a guard
       area shall not be provided for threads created with _a_t_t_r.  If _g_u_a_r_d_s_i_z_e
       is greater than zero, a guard area of at least size _g_u_a_r_d_s_i_z_e bytes
       shall be provided for each thread created with _a_t_t_r.

       The _g_u_a_r_d_s_i_z_e attribute controls the size of the guard area for the
       created thread's stack. The _g_u_a_r_d_s_i_z_e attribute provides protection
       against overflow of the stack pointer. If a thread's stack is created
       with guard protection, the implementation allocates extra memory at the
       overflow end of the stack as a buffer against stack overflow of the
       stack pointer. If an application overflows into this buffer an error
       shall result (possibly in a SIGSEGV signal being delivered to the
       thread).

       A conforming implementation may round up the value contained in
       _g_u_a_r_d_s_i_z_e to a multiple of the configurable system variable {PAGESIZE}
       (see _<_s_y_s_/_m_m_a_n_._h_>).  If an implementation rounds up the value of
       _g_u_a_r_d_s_i_z_e to a multiple of {PAGESIZE}, a call to
       _p_t_h_r_e_a_d___a_t_t_r___g_e_t_g_u_a_r_d_s_i_z_e() specifying _a_t_t_r shall store in the
       _g_u_a_r_d_s_i_z_e parameter the guard size specified by the previous
       _p_t_h_r_e_a_d___a_t_t_r___s_e_t_g_u_a_r_d_s_i_z_e() function call.

       The default value of the _g_u_a_r_d_s_i_z_e attribute is implementation-defined.

       If the _s_t_a_c_k_a_d_d_r attribute has been set (that is, the caller is
       allocating and managing its own thread stacks), the _g_u_a_r_d_s_i_z_e attribute
       shall be ignored and no protection shall be provided by the
       implementation. It is the responsibility of the application to manage
       stack overflow along with stack allocation and management in this case.

       The behavior is undefined if the value specified by the _a_t_t_r argument
       to _p_t_h_r_e_a_d___a_t_t_r___g_e_t_g_u_a_r_d_s_i_z_e() or _p_t_h_r_e_a_d___a_t_t_r___s_e_t_g_u_a_r_d_s_i_z_e() does not
       refer to an initialized thread attributes object.

RREETTUURRNN VVAALLUUEE
       If successful, the _p_t_h_r_e_a_d___a_t_t_r___g_e_t_g_u_a_r_d_s_i_z_e() and
       _p_t_h_r_e_a_d___a_t_t_r___s_e_t_g_u_a_r_d_s_i_z_e() functions shall return zero; otherwise, an
       error number shall be returned to indicate the error.

EERRRROORRSS
       These functions shall fail if:

       EEIINNVVAALL The parameter _g_u_a_r_d_s_i_z_e is invalid.

       These functions shall not return an error code of [[EEIINNTTRR]].

       _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
   RReettrriieevviinngg tthhee gguuaarrddssiizzee AAttttrriibbuuttee
       This example shows how to obtain the _g_u_a_r_d_s_i_z_e attribute of a thread
       attribute object.


           #include <pthread.h>

           pthread_attr_t thread_attr;
           size_t  guardsize;
           int     rc;

           /* code initializing thread_attr */
           ...

           rc = pthread_attr_getguardsize (&thread_attr, &guardsize);
           if (rc != 0)  {
               /* handle error */
               ...
           }
           else {
               if (guardsize > 0) {
               /* a guard area of at least guardsize bytes is provided */
               ...
               }
               else {
               /* no guard area provided */
               ...
               }
           }

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       The _g_u_a_r_d_s_i_z_e attribute is provided to the application for two reasons:

        1. Overflow protection can potentially result in wasted system
           resources.  An application that creates a large number of threads,
           and which knows its threads never overflow their stack, can save
           system resources by turning off guard areas.

        2. When threads allocate large data structures on the stack, large
           guard areas may be needed to detect stack overflow.

       The default size of the guard area is left implementation-defined since
       on systems supporting very large page sizes, the overhead might be
       substantial if at least one guard page is required by default.

       If an implementation detects that the value specified by the _a_t_t_r
       argument to _p_t_h_r_e_a_d___a_t_t_r___g_e_t_g_u_a_r_d_s_i_z_e() or _p_t_h_r_e_a_d___a_t_t_r___s_e_t_g_u_a_r_d_s_i_z_e()
       does not refer to an initialized thread attributes object, it is
       recommended that the function should fail and report an [[EEIINNVVAALL]] error.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       The Base Definitions volume of POSIX.1-2017, <<pptthhrreeaadd..hh>>, <<ssyyss__mmmmaann..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  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.opengroup.org/unix/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                  2017         PTHREAD_ATTR_GETGUARDSIZE(3)
