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
99 Interface Attribute Value
103 .BR pthread_attr_setstack (),
104 .BR pthread_attr_getstack ()
105 T} Thread safety MT-Safe
113 These functions are provided for applications that must ensure that
114 a thread's stack is placed in a particular location.
115 For most applications, this is not necessary,
116 and the use of these functions should be avoided.
118 .BR pthread_attr_setstacksize (3)
119 if an application simply requires a stack size other than the default.)
121 When an application employs
122 .BR pthread_attr_setstack (),
123 it takes over the responsibility of allocating the stack.
124 Any guard size value that was set using
125 .BR pthread_attr_setguardsize (3)
128 it is the application's responsibility to allocate a guard area
129 (one or more pages protected against reading and writing)
130 to handle the possibility of stack overflow.
132 The address specified in
134 should be suitably aligned:
135 for full portability, align it on a page boundary
136 .RI ( sysconf(_SC_PAGESIZE) ).
137 .BR posix_memalign (3)
138 may be useful for allocation.
141 should also be a multiple of the system page size.
145 is used to create multiple threads, then the caller must change the
146 stack address attribute between calls to
147 .BR pthread_create (3);
148 otherwise, the threads will attempt to use the same memory area
149 for their stacks, and chaos will ensue.
152 .BR pthread_attr_init (3).
158 .BR posix_memalign (3),
159 .BR pthread_attr_init (3),
160 .BR pthread_attr_setguardsize (3),
161 .BR pthread_attr_setstackaddr (3),
162 .BR pthread_attr_setstacksize (3),
163 .BR pthread_create (3),