1pthread_attr_getguardsize(S3tCa)ndard C Library Functipotnhsread_attr_getguardsize(3C)
2
3
4
6 pthread_attr_getguardsize, pthread_attr_setguardsize - get or set
7 thread guardsize attribute
8
10 cc -mt [ flag... ] file... -lpthread [ library... ]
11 #include <pthread.h>
12
13 int pthread_attr_getguardsize(const pthread_attr_t *restrict attr,
14 size_t *restrict guardsize);
15
16
17 int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
18
19
21 The guardsize attribute controls the size of the guard area for the
22 created thread's stack. The guardsize attribute provides protection
23 against overflow of the stack pointer. If a thread's stack is created
24 with guard protection, the implementation allocates extra memory at the
25 overflow end of the stack as a buffer against stack overflow of the
26 stack pointer. If an application overflows into this buffer an error
27 results (possibly in a SIGSEGV signal being delivered to the thread).
28
29
30 The guardsize attribute is provided to the application for two reasons:
31
32 1. Overflow protection can potentially result in wasted system
33 resources. An application that creates a large number of
34 threads, and which knows its threads will never overflow
35 their stack, can save system resources by turning off guard
36 areas.
37
38 2. When threads allocate large data structures on the stack,
39 large guard areas may be needed to detect stack overflow.
40
41
42 The pthread_attr_getguardsize() function gets the guardsize attribute
43 in the attr object. This attribute is returned in the guardsize parame‐
44 ter.
45
46
47 The pthread_attr_setguardsize() function sets the guardsize attribute
48 in the attr object. The new value of this attribute is obtained from
49 the guardsize parameter. If guardsize is 0, a guard area will not be
50 provided for threads created with attr. If guardsize is greater than
51 0, a guard area of at least size guardsize bytes is provided for each
52 thread created with attr.
53
54
55 A conforming implementation is permitted to round up the value con‐
56 tained in guardsize to a multiple of the configurable system variable
57 PAGESIZE. If an implementation rounds up the value of guardsize to a
58 multiple of PAGESIZE, a call to pthread_attr_getguardsize() specifying
59 attr will store in the guardsize parameter the guard size specified by
60 the previous pthread_attr_setguardsize() function call.
61
62
63 The default value of the guardsize attribute is PAGESIZE bytes. The
64 actual value of PAGESIZE is implementation-dependent and may not be
65 the same on all implementations.
66
67
68 If the stackaddr attribute has been set (that is, the caller is allo‐
69 cating and managing its own thread stacks), the guardsize attribute is
70 ignored and no protection will be provided by the implementation. It is
71 the responsibility of the application to manage stack overflow along
72 with stack allocation and management in this case.
73
75 If successful, the pthread_attr_getguardsize() and pthread_attr_set‐
76 guardsize() functions return 0. Otherwise, an error number is returned
77 to indicate the error.
78
80 The pthread_attr_getguardsize() and pthread_attr_setguardsize() func‐
81 tions will fail if:
82
83 EINVAL The attribute attr is invalid.
84
85
86 EINVAL The parameter guardsize is invalid.
87
88
89 EINVAL The parameter guardsize contains an invalid value.
90
91
93 See attributes(5) for descriptions of the following attributes:
94
95
96
97
98 ┌─────────────────────────────┬─────────────────────────────┐
99 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
100 ├─────────────────────────────┼─────────────────────────────┤
101 │Interface Stability │Standard │
102 ├─────────────────────────────┼─────────────────────────────┤
103 │MT-Level │MT-Safe │
104 └─────────────────────────────┴─────────────────────────────┘
105
107 sysconf(3C), pthread_attr_init(3C), attributes(5), standards(5)
108
109
110
111SunOS 5.11 23 mar 2005 pthread_attr_getguardsize(3C)