1PTHREAD_ATTR_GETGUARDSIZE(3PP)OSIX Programmer's ManuPaTlHREAD_ATTR_GETGUARDSIZE(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       pthread_attr_getguardsize, pthread_attr_setguardsize — get and set the
13       thread guardsize attribute
14

SYNOPSIS

16       #include <pthread.h>
17
18       int pthread_attr_getguardsize(const pthread_attr_t *restrict attr,
19           size_t *restrict guardsize);
20       int pthread_attr_setguardsize(pthread_attr_t *attr,
21           size_t guardsize);
22

DESCRIPTION

24       The   pthread_attr_getguardsize()  function  shall  get  the  guardsize
25       attribute in the attr object. This attribute shall be returned  in  the
26       guardsize parameter.
27
28       The   pthread_attr_setguardsize()  function  shall  set  the  guardsize
29       attribute in the attr object. The new value of this attribute shall  be
30       obtained  from  the  guardsize parameter. If guardsize is zero, a guard
31       area shall not be provided for threads created with attr.  If guardsize
32       is  greater  than  zero,  a guard area of at least size guardsize bytes
33       shall be provided for each thread created with attr.
34
35       The guardsize attribute controls the size of the  guard  area  for  the
36       created  thread's  stack.  The  guardsize attribute provides protection
37       against overflow of the stack pointer. If a thread's stack  is  created
38       with guard protection, the implementation allocates extra memory at the
39       overflow end of the stack as a buffer against  stack  overflow  of  the
40       stack  pointer.  If  an application overflows into this buffer an error
41       shall result (possibly in a  SIGSEGV  signal  being  delivered  to  the
42       thread).
43
44       A  conforming implementation may round up the value contained in guard‐
45       size to a multiple of the configurable system variable {PAGESIZE}  (see
46       <sys/mman.h>).   If  an implementation rounds up the value of guardsize
47       to a multiple of  {PAGESIZE},  a  call  to  pthread_attr_getguardsize()
48       specifying  attr  shall store in the guardsize parameter the guard size
49       specified by the previous pthread_attr_setguardsize() function call.
50
51       The default value of the guardsize attribute is implementation-defined.
52
53       If the stackaddr attribute has been set (that is, the caller  is  allo‐
54       cating  and  managing  its  own thread stacks), the guardsize attribute
55       shall be ignored and no protection shall be provided by the implementa‐
56       tion. It is the responsibility of the application to manage stack over‐
57       flow along with stack allocation and management in this case.
58
59       The behavior is undefined if the value specified by the  attr  argument
60       to  pthread_attr_getguardsize() or pthread_attr_setguardsize() does not
61       refer to an initialized thread attributes object.
62

RETURN VALUE

64       If successful, the  pthread_attr_getguardsize()  and  pthread_attr_set‐
65       guardsize()  functions  shall  return  zero; otherwise, an error number
66       shall be returned to indicate the error.
67

ERRORS

69       These functions shall fail if:
70
71       EINVAL The parameter guardsize is invalid.
72
73       These functions shall not return an error code of [EINTR].
74
75       The following sections are informative.
76

EXAMPLES

78   Retrieving the guardsize Attribute
79       This example shows how to obtain the guardsize attribute  of  a  thread
80       attribute object.
81
82
83           #include <pthread.h>
84
85           pthread_attr_t thread_attr;
86           size_t  guardsize;
87           int     rc;
88
89           /* code initializing thread_attr */
90           ...
91
92           rc = pthread_attr_getguardsize (&thread_attr, &guardsize);
93           if (rc != 0)  {
94               /* handle error */
95               ...
96           }
97           else {
98               if (guardsize > 0) {
99               /* a guard area of at least guardsize bytes is provided */
100               ...
101               }
102               else {
103               /* no guard area provided */
104               ...
105               }
106           }
107

APPLICATION USAGE

109       None.
110

RATIONALE

112       The guardsize attribute is provided to the application for two reasons:
113
114        1. Overflow   protection  can  potentially  result  in  wasted  system
115           resources.  An application that creates a large number of  threads,
116           and  which  knows  its threads never overflow their stack, can save
117           system resources by turning off guard areas.
118
119        2. When threads allocate large data structures  on  the  stack,  large
120           guard areas may be needed to detect stack overflow.
121
122       The default size of the guard area is left implementation-defined since
123       on systems supporting very large page sizes, the overhead might be sub‐
124       stantial if at least one guard page is required by default.
125
126       If an implementation detects that the value specified by the attr argu‐
127       ment to pthread_attr_getguardsize() or pthread_attr_setguardsize() does
128       not refer to an initialized thread attributes object, it is recommended
129       that the function should fail and report an [EINVAL] error.
130

FUTURE DIRECTIONS

132       None.
133

SEE ALSO

135       The Base Definitions volume of POSIX.1‐2017, <pthread.h>, <sys_mman.h>
136
138       Portions of this text are reprinted and reproduced in  electronic  form
139       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
140       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
141       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
142       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
143       event of any discrepancy between this version and the original IEEE and
144       The Open Group Standard, the original IEEE and The Open Group  Standard
145       is  the  referee document. The original Standard can be obtained online
146       at http://www.opengroup.org/unix/online.html .
147
148       Any typographical or formatting errors that appear  in  this  page  are
149       most likely to have been introduced during the conversion of the source
150       files to man page format. To report such errors,  see  https://www.ker
151       nel.org/doc/man-pages/reporting_bugs.html .
152
153
154
155IEEE/The Open Group                  2017        PTHREAD_ATTR_GETGUARDSIZE(3P)
Impressum