1PTHREAD_ATTR_GETSTACK(3P) POSIX Programmer's Manual PTHREAD_ATTR_GETSTACK(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 pthread_attr_getstack, pthread_attr_setstack — get and set stack
13 attributes
14
16 #include <pthread.h>
17
18 int pthread_attr_getstack(const pthread_attr_t *restrict attr,
19 void **restrict stackaddr, size_t *restrict stacksize);
20 int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr,
21 size_t stacksize);
22
24 The pthread_attr_getstack() and pthread_attr_setstack() functions,
25 respectively, shall get and set the thread creation stack attributes
26 stackaddr and stacksize in the attr object.
27
28 The stack attributes specify the area of storage to be used for the
29 created thread's stack. The base (lowest addressable byte) of the stor‐
30 age shall be stackaddr, and the size of the storage shall be stacksize
31 bytes. The stacksize shall be at least {PTHREAD_STACK_MIN}. The
32 pthread_attr_setstack() function may fail with [EINVAL] if stackaddr
33 does not meet implementation-defined alignment requirements. All pages
34 within the stack described by stackaddr and stacksize shall be both
35 readable and writable by the thread.
36
37 If the pthread_attr_getstack() function is called before the stackaddr
38 attribute has been set, the behavior is unspecified.
39
40 The behavior is undefined if the value specified by the attr argument
41 to pthread_attr_getstack() or pthread_attr_setstack() does not refer to
42 an initialized thread attributes object.
43
45 Upon successful completion, these functions shall return a value of 0;
46 otherwise, an error number shall be returned to indicate the error.
47
48 The pthread_attr_getstack() function shall store the stack attribute
49 values in stackaddr and stacksize if successful.
50
52 The pthread_attr_setstack() function shall fail if:
53
54 EINVAL The value of stacksize is less than {PTHREAD_STACK_MIN} or
55 exceeds an implementation-defined limit.
56
57 The pthread_attr_setstack() function may fail if:
58
59 EINVAL The value of stackaddr does not have proper alignment to be used
60 as a stack, or ((char *)stackaddr + stacksize) lacks proper
61 alignment.
62
63 EACCES The stack page(s) described by stackaddr and stacksize are not
64 both readable and writable by the thread.
65
66 These functions shall not return an error code of [EINTR].
67
68 The following sections are informative.
69
71 None.
72
74 These functions are appropriate for use by applications in an environ‐
75 ment where the stack for a thread must be placed in some particular
76 region of memory.
77
78 While it might seem that an application could detect stack overflow by
79 providing a protected page outside the specified stack region, this
80 cannot be done portably. Implementations are free to place the thread's
81 initial stack pointer anywhere within the specified region to accommo‐
82 date the machine's stack pointer behavior and allocation requirements.
83 Furthermore, on some architectures, such as the IA‐64, ``overflow''
84 might mean that two separate stack pointers allocated within the region
85 will overlap somewhere in the middle of the region.
86
87 After a successful call to pthread_attr_setstack(), the storage area
88 specified by the stackaddr parameter is under the control of the imple‐
89 mentation, as described in Section 2.9.8, Use of Application-Managed
90 Thread Stacks.
91
92 The specification of the stackaddr attribute presents several ambigui‐
93 ties that make portable use of these functions impossible. For example,
94 the standard allows implementations to impose arbitrary alignment
95 requirements on stackaddr. Applications cannot assume that a buffer
96 obtained from malloc() is suitably aligned. Note that although the
97 stacksize value passed to pthread_attr_setstack() must satisfy align‐
98 ment requirements, the same is not true for pthread_attr_setstacksize()
99 where the implementation must increase the specified size if necessary
100 to achieve the proper alignment.
101
103 If an implementation detects that the value specified by the attr argu‐
104 ment to pthread_attr_getstack() or pthread_attr_setstack() does not
105 refer to an initialized thread attributes object, it is recommended
106 that the function should fail and report an [EINVAL] error.
107
109 None.
110
112 pthread_attr_destroy(), pthread_attr_getdetachstate(),
113 pthread_attr_getstacksize(), pthread_create()
114
115 The Base Definitions volume of POSIX.1‐2017, <limits.h>, <pthread.h>
116
118 Portions of this text are reprinted and reproduced in electronic form
119 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
120 table Operating System Interface (POSIX), The Open Group Base Specifi‐
121 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
122 Electrical and Electronics Engineers, Inc and The Open Group. In the
123 event of any discrepancy between this version and the original IEEE and
124 The Open Group Standard, the original IEEE and The Open Group Standard
125 is the referee document. The original Standard can be obtained online
126 at http://www.opengroup.org/unix/online.html .
127
128 Any typographical or formatting errors that appear in this page are
129 most likely to have been introduced during the conversion of the source
130 files to man page format. To report such errors, see https://www.ker‐
131 nel.org/doc/man-pages/reporting_bugs.html .
132
133
134
135IEEE/The Open Group 2017 PTHREAD_ATTR_GETSTACK(3P)