2 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .TH pthread_attr_setstack 3 (date) "Linux man-pages (unreleased)"
9 pthread_attr_setstack, pthread_attr_getstack \- set/get stack
10 attributes in thread attributes object
13 .RI ( libpthread ", " \-lpthread )
16 .B #include <pthread.h>
18 .BI "int pthread_attr_setstack(pthread_attr_t *" attr ,
19 .BI " void " stackaddr [. stacksize ],
20 .BI " size_t " stacksize );
21 .BI "int pthread_attr_getstack(const pthread_attr_t *restrict " attr ,
22 .BI " void **restrict " stackaddr ,
23 .BI " size_t *restrict " stacksize );
27 Feature Test Macro Requirements for glibc (see
28 .BR feature_test_macros (7)):
31 .BR pthread_attr_getstack (),
32 .BR pthread_attr_setstack ():
34 _POSIX_C_SOURCE >= 200112L
38 .BR pthread_attr_setstack ()
39 function sets the stack address and stack size attributes of the
40 thread attributes object referred to by
42 to the values specified in
47 These attributes specify the location and size of the stack that should
48 be used by a thread that is created using the thread attributes object
52 should point to the lowest addressable byte of a buffer of
54 bytes that was allocated by the caller.
55 The pages of the allocated buffer should be both readable and writable.
58 .BR pthread_attr_getstack ()
59 function returns the stack address and stack size attributes of the
60 thread attributes object referred to by
62 in the buffers pointed to by
68 On success, these functions return 0;
69 on error, they return a nonzero error number.
71 .BR pthread_attr_setstack ()
72 can fail with the following error:
79 On some systems, this error may also occur if
82 .I stackaddr\~+\~stacksize
83 is not suitably aligned.
85 POSIX.1 also documents an
87 error if the stack area described by
91 is not both readable and writable by the caller.
93 For an explanation of the terms used in this section, see
101 Interface Attribute Value
103 .BR pthread_attr_setstack (),
104 .BR pthread_attr_getstack ()
105 T} Thread safety MT-Safe
116 These functions are provided for applications that must ensure that
117 a thread's stack is placed in a particular location.
118 For most applications, this is not necessary,
119 and the use of these functions should be avoided.
121 .BR pthread_attr_setstacksize (3)
122 if an application simply requires a stack size other than the default.)
124 When an application employs
125 .BR pthread_attr_setstack (),
126 it takes over the responsibility of allocating the stack.
127 Any guard size value that was set using
128 .BR pthread_attr_setguardsize (3)
131 it is the application's responsibility to allocate a guard area
132 (one or more pages protected against reading and writing)
133 to handle the possibility of stack overflow.
135 The address specified in
137 should be suitably aligned:
138 for full portability, align it on a page boundary
139 .RI ( sysconf(_SC_PAGESIZE) ).
140 .BR posix_memalign (3)
141 may be useful for allocation.
144 should also be a multiple of the system page size.
148 is used to create multiple threads, then the caller must change the
149 stack address attribute between calls to
150 .BR pthread_create (3);
151 otherwise, the threads will attempt to use the same memory area
152 for their stacks, and chaos will ensue.
155 .BR pthread_attr_init (3).
161 .BR posix_memalign (3),
162 .BR pthread_attr_init (3),
163 .BR pthread_attr_setguardsize (3),
164 .BR pthread_attr_setstackaddr (3),
165 .BR pthread_attr_setstacksize (3),
166 .BR pthread_create (3),