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
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 to
48       a multiple of {PAGESIZE}, a call to pthread_attr_getguardsize()  speci‐
49       fying attr shall store in the guardsize parameter the guard size speci‐
50       fied by the previous pthread_attr_setguardsize() function call.
51
52       The default value of the guardsize attribute is {PAGESIZE} bytes.   The
53       actual value of {PAGESIZE} is implementation-defined.
54
55       If  the  stackaddr or stack attribute has been set (that is, the caller
56       is allocating and  managing  its  own  thread  stacks),  the  guardsize
57       attribute  shall  be ignored and no protection shall be provided by the
58       implementation. It is the responsibility of the application  to  manage
59       stack overflow along with stack allocation and management in this case.
60

RETURN VALUE

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

ERRORS

67       The  pthread_attr_getguardsize()  and pthread_attr_setguardsize() func‐
68       tions shall fail if:
69
70       EINVAL The attribute attr is invalid.
71
72       EINVAL The parameter guardsize is invalid.
73
74
75       These functions shall not return an error code of [EINTR].
76
77       The following sections are informative.
78

EXAMPLES

80       None.
81

APPLICATION USAGE

83       None.
84

RATIONALE

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

FUTURE DIRECTIONS

97       None.
98

SEE ALSO

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