]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/pthread_attr_setstack.3
0f883c26ca70d1cc3fce58b644ca38221731ddec
[thirdparty/man-pages.git] / man3 / pthread_attr_setstack.3
1 '\" t
2 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH pthread_attr_setstack 3 (date) "Linux man-pages (unreleased)"
8 .SH NAME
9 pthread_attr_setstack, pthread_attr_getstack \- set/get stack
10 attributes in thread attributes object
11 .SH LIBRARY
12 POSIX threads library
13 .RI ( libpthread ", " \-lpthread )
14 .SH SYNOPSIS
15 .nf
16 .B #include <pthread.h>
17 .PP
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 );
24 .fi
25 .PP
26 .RS -4
27 Feature Test Macro Requirements for glibc (see
28 .BR feature_test_macros (7)):
29 .RE
30 .PP
31 .BR pthread_attr_getstack (),
32 .BR pthread_attr_setstack ():
33 .nf
34 _POSIX_C_SOURCE >= 200112L
35 .fi
36 .SH DESCRIPTION
37 The
38 .BR pthread_attr_setstack ()
39 function sets the stack address and stack size attributes of the
40 thread attributes object referred to by
41 .I attr
42 to the values specified in
43 .I stackaddr
44 and
45 .IR stacksize ,
46 respectively.
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
49 .IR attr .
50 .PP
51 .I stackaddr
52 should point to the lowest addressable byte of a buffer of
53 .I stacksize
54 bytes that was allocated by the caller.
55 The pages of the allocated buffer should be both readable and writable.
56 .PP
57 The
58 .BR pthread_attr_getstack ()
59 function returns the stack address and stack size attributes of the
60 thread attributes object referred to by
61 .I attr
62 in the buffers pointed to by
63 .I stackaddr
64 and
65 .IR stacksize ,
66 respectively.
67 .SH RETURN VALUE
68 On success, these functions return 0;
69 on error, they return a nonzero error number.
70 .SH ERRORS
71 .BR pthread_attr_setstack ()
72 can fail with the following error:
73 .TP
74 .B EINVAL
75 .I stacksize
76 is less than
77 .B PTHREAD_STACK_MIN
78 (16384) bytes.
79 On some systems, this error may also occur if
80 .I stackaddr
81 or
82 .I stackaddr\~+\~stacksize
83 is not suitably aligned.
84 .PP
85 POSIX.1 also documents an
86 .B EACCES
87 error if the stack area described by
88 .I stackaddr
89 and
90 .I stacksize
91 is not both readable and writable by the caller.
92 .SH ATTRIBUTES
93 For an explanation of the terms used in this section, see
94 .BR attributes (7).
95 .ad l
96 .nh
97 .TS
98 allbox;
99 lbx lb lb
100 l l l.
101 Interface Attribute Value
102 T{
103 .BR pthread_attr_setstack (),
104 .BR pthread_attr_getstack ()
105 T} Thread safety MT-Safe
106 .TE
107 .hy
108 .ad
109 .sp 1
110 .SH STANDARDS
111 POSIX.1-2008.
112 .SH HISTORY
113 glibc 2.2.
114 POSIX.1-2001.
115 .SH NOTES
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.
120 (Use
121 .BR pthread_attr_setstacksize (3)
122 if an application simply requires a stack size other than the default.)
123 .PP
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)
129 is ignored.
130 If deemed necessary,
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.
134 .PP
135 The address specified in
136 .I stackaddr
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.
142 Probably,
143 .I stacksize
144 should also be a multiple of the system page size.
145 .PP
146 If
147 .I attr
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.
153 .SH EXAMPLES
154 See
155 .BR pthread_attr_init (3).
156 .SH SEE ALSO
157 .ad l
158 .nh
159 .BR mmap (2),
160 .BR mprotect (2),
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),
167 .BR pthreads (7)