1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH PTHREAD_ATTR_SETSTACK 3 2017-09-15 "Linux" "Linux Programmer's Manual"
28 pthread_attr_setstack, pthread_attr_getstack \- set/get stack
29 attributes in thread attributes object
32 .B #include <pthread.h>
34 .BI "int pthread_attr_setstack(pthread_attr_t *" attr ,
35 .BI " void *" stackaddr ", size_t " stacksize );
36 .BI "int pthread_attr_getstack(const pthread_attr_t *" attr ,
37 .BI " void **" stackaddr ", size_t *" stacksize );
39 Compile and link with \fI\-pthread\fP.
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
48 .BR pthread_attr_getstack (),
49 .BR pthread_attr_setstack ():
51 _POSIX_C_SOURCE\ >=\ 200112L
56 .BR pthread_attr_setstack ()
57 function sets the stack address and stack size attributes of the
58 thread attributes object referred to by
60 to the values specified in
65 These attributes specify the location and size of the stack that should
66 be used by a thread that is created using the thread attributes object
70 should point to the lowest addressable byte of a buffer of
72 bytes that was allocated by the caller.
73 The pages of the allocated buffer should be both readable and writable.
76 .BR pthread_attr_getstack ()
77 function returns the stack address and stack size attributes of the
78 thread attributes object referred to by
80 in the buffers pointed to by
86 On success, these functions return 0;
87 on error, they return a nonzero error number.
89 .BR pthread_attr_setstack ()
90 can fail with the following error:
97 On some systems, this error may also occur if
100 .IR "stackaddr\ +\ stacksize"
101 is not suitably aligned.
103 POSIX.1 also documents an
105 error if the stack area described by
109 is not both readable and writable by the caller.
111 These functions are provided by glibc since version 2.2.
113 For an explanation of the terms used in this section, see
119 Interface Attribute Value
121 .BR pthread_attr_setstack (),
122 .BR pthread_attr_getstack ()
123 T} Thread safety MT-Safe
126 POSIX.1-2001, POSIX.1-2008.
128 These functions are provided for applications that must ensure that
129 a thread's stack is placed in a particular location.
130 For most applications, this is not necessary,
131 and the use of these functions should be avoided.
133 .BR pthread_attr_setstacksize (3)
134 if an application simply requires a stack size other than the default.)
136 When an application employs
137 .BR pthread_attr_setstack (),
138 it takes over the responsibility of allocating the stack.
139 Any guard size value that was set using
140 .BR pthread_attr_setguardsize (3)
143 it is the application's responsibility to allocate a guard area
144 (one or more pages protected against reading and writing)
145 to handle the possibility of stack overflow.
147 The address specified in
149 should be suitably aligned:
150 for full portability, align it on a page boundary
151 .RI ( sysconf(_SC_PAGESIZE) ).
152 .BR posix_memalign (3)
153 may be useful for allocation.
156 should also be a multiple of the system page size.
160 is used to create multiple threads, then the caller must change the
161 stack address attribute between calls to
162 .BR pthread_create (3);
163 otherwise, the threads will attempt to use the same memory area
164 for their stacks, and chaos will ensue.
167 .BR pthread_attr_init (3).
173 .BR posix_memalign (3),
174 .BR pthread_attr_init (3),
175 .BR pthread_attr_setguardsize (3),
176 .BR pthread_attr_setstackaddr (3),
177 .BR pthread_attr_setstacksize (3),
178 .BR pthread_create (3),