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
11

NAME

13       pthread_attr_getguardsize, pthread_attr_setguardsize — get and set the
14       thread guardsize attribute
15

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

79   Retrieving the guardsize Attribute
80       This example shows how to obtain the guardsize attribute  of  a  thread
81       attribute object.
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‐2008, <pthread.h>, <sys_mman.h>
136
138       Portions of this text are reprinted and reproduced in  electronic  form
139       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
140       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
141       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
142       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
143       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
144       event of any discrepancy between this version and the original IEEE and
145       The  Open Group Standard, the original IEEE and The Open Group Standard
146       is the referee document. The original Standard can be  obtained  online
147       at http://www.unix.org/online.html .
148
149       Any  typographical  or  formatting  errors that appear in this page are
150       most likely to have been introduced during the conversion of the source
151       files  to  man page format. To report such errors, see https://www.ker
152       nel.org/doc/man-pages/reporting_bugs.html .
153
154
155
156IEEE/The Open Group                  2013        PTHREAD_ATTR_GETGUARDSIZE(3P)
Impressum