1PTHREAD_ATTR_GETGUARDSIZE(P)POSIX Programmer's ManuaPlTHREAD_ATTR_GETGUARDSIZE(P)
2
3
4

NAME

6       pthread_attr_getguardsize,  pthread_attr_setguardsize - get and set the
7       thread guardsize attribute
8

SYNOPSIS

10       #include <pthread.h>
11
12       int pthread_attr_getguardsize(const pthread_attr_t *restrict attr,
13              size_t *restrict guardsize);
14       int pthread_attr_setguardsize(pthread_attr_t *attr,
15              size_t guardsize);
16
17

DESCRIPTION

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

RETURN VALUE

56       If successful, the  pthread_attr_getguardsize()  and  pthread_attr_set‐
57       guardsize()  functions  shall  return  zero; otherwise, an error number
58       shall be returned to indicate the error.
59

ERRORS

61       The pthread_attr_getguardsize() and  pthread_attr_setguardsize()  func‐
62       tions shall fail if:
63
64       EINVAL The attribute attr is invalid.
65
66       EINVAL The parameter guardsize is invalid.
67
68
69       These functions shall not return an error code of [EINTR].
70
71       The following sections are informative.
72

EXAMPLES

74       None.
75

APPLICATION USAGE

77       None.
78

RATIONALE

80       The guardsize attribute is provided to the application for two reasons:
81
82        1. Overflow   protection  can  potentially  result  in  wasted  system
83           resources.  An application that creates a large number of  threads,
84           and  which  knows  its threads never overflow their stack, can save
85           system resources by turning off guard areas.
86
87        2. When threads allocate large data structures  on  the  stack,  large
88           guard areas may be needed to detect stack overflow.
89

FUTURE DIRECTIONS

91       None.
92

SEE ALSO

94       The  Base  Definitions  volume  of  IEEE Std 1003.1-2001,  <pthread.h>,
95       <sys/mman.h>
96
98       Portions of this text are reprinted and reproduced in  electronic  form
99       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
100       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
101       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
102       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
103       event of any discrepancy between this version and the original IEEE and
104       The Open Group Standard, the original IEEE and The Open Group  Standard
105       is  the  referee document. The original Standard can be obtained online
106       at http://www.opengroup.org/unix/online.html .
107
108
109
110IEEE/The Open Group                  2003         PTHREAD_ATTR_GETGUARDSIZE(P)
Impressum