Changes: Ready for 5.13
[man-pages.git] / man3 / pthread_attr_setstack.3
blob8a7e4a7b309728cca1d5cb80629862a92416de4b
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
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.
8 .\"
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.
13 .\"
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
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH PTHREAD_ATTR_SETSTACK 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 pthread_attr_setstack, pthread_attr_getstack \- set/get stack
29 attributes in thread attributes object
30 .SH SYNOPSIS
31 .nf
32 .B #include <pthread.h>
33 .PP
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 *restrict " attr ,
37 .BI "                          void **restrict " stackaddr ,
38 .BI "                          size_t *restrict " stacksize );
39 .PP
40 Compile and link with \fI\-pthread\fP.
41 .fi
42 .PP
43 .RS -4
44 Feature Test Macro Requirements for glibc (see
45 .BR feature_test_macros (7)):
46 .RE
47 .PP
48 .BR pthread_attr_getstack (),
49 .BR pthread_attr_setstack ():
50 .nf
51     _POSIX_C_SOURCE >= 200112L
52 .fi
53 .SH DESCRIPTION
54 The
55 .BR pthread_attr_setstack ()
56 function sets the stack address and stack size attributes of the
57 thread attributes object referred to by
58 .I attr
59 to the values specified in
60 .IR stackaddr
61 and
62 .IR stacksize ,
63 respectively.
64 These attributes specify the location and size of the stack that should
65 be used by a thread that is created using the thread attributes object
66 .IR attr .
67 .PP
68 .I stackaddr
69 should point to the lowest addressable byte of a buffer of
70 .I stacksize
71 bytes that was allocated by the caller.
72 The pages of the allocated buffer should be both readable and writable.
73 .PP
74 The
75 .BR pthread_attr_getstack ()
76 function returns the stack address and stack size attributes of the
77 thread attributes object referred to by
78 .I attr
79 in the buffers pointed to by
80 .IR stackaddr
81 and
82 .IR stacksize ,
83 respectively.
84 .SH RETURN VALUE
85 On success, these functions return 0;
86 on error, they return a nonzero error number.
87 .SH ERRORS
88 .BR pthread_attr_setstack ()
89 can fail with the following error:
90 .TP
91 .B EINVAL
92 .I stacksize
93 is less than
94 .BR PTHREAD_STACK_MIN
95 (16384) bytes.
96 On some systems, this error may also occur if
97 .IR stackaddr
99 .IR "stackaddr\ +\ stacksize"
100 is not suitably aligned.
102 POSIX.1 also documents an
103 .BR EACCES
104 error if the stack area described by
105 .I stackaddr
107 .I stacksize
108 is not both readable and writable by the caller.
109 .SH VERSIONS
110 These functions are provided by glibc since version 2.2.
111 .SH ATTRIBUTES
112 For an explanation of the terms used in this section, see
113 .BR attributes (7).
114 .ad l
117 allbox;
118 lbx lb lb
119 l l l.
120 Interface       Attribute       Value
122 .BR pthread_attr_setstack (),
123 .BR pthread_attr_getstack ()
124 T}      Thread safety   MT-Safe
128 .sp 1
129 .SH CONFORMING TO
130 POSIX.1-2001, POSIX.1-2008.
131 .SH NOTES
132 These functions are provided for applications that must ensure that
133 a thread's stack is placed in a particular location.
134 For most applications, this is not necessary,
135 and the use of these functions should be avoided.
136 (Use
137 .BR pthread_attr_setstacksize (3)
138 if an application simply requires a stack size other than the default.)
140 When an application employs
141 .BR pthread_attr_setstack (),
142 it takes over the responsibility of allocating the stack.
143 Any guard size value that was set using
144 .BR pthread_attr_setguardsize (3)
145 is ignored.
146 If deemed necessary,
147 it is the application's responsibility to allocate a guard area
148 (one or more pages protected against reading and writing)
149 to handle the possibility of stack overflow.
151 The address specified in
152 .I stackaddr
153 should be suitably aligned:
154 for full portability, align it on a page boundary
155 .RI ( sysconf(_SC_PAGESIZE) ).
156 .BR posix_memalign (3)
157 may be useful for allocation.
158 Probably,
159 .IR stacksize
160 should also be a multiple of the system page size.
163 .I attr
164 is used to create multiple threads, then the caller must change the
165 stack address attribute between calls to
166 .BR pthread_create (3);
167 otherwise, the threads will attempt to use the same memory area
168 for their stacks, and chaos will ensue.
169 .SH EXAMPLES
171 .BR pthread_attr_init (3).
172 .SH SEE ALSO
173 .ad l
175 .BR mmap (2),
176 .BR mprotect (2),
177 .BR posix_memalign (3),
178 .BR pthread_attr_init (3),
179 .BR pthread_attr_setguardsize (3),
180 .BR pthread_attr_setstackaddr (3),
181 .BR pthread_attr_setstacksize (3),
182 .BR pthread_create (3),
183 .BR pthreads (7)