1PTHREAD_ATTR_GETSTACK(3P)  POSIX Programmer's Manual PTHREAD_ATTR_GETSTACK(3P)
2
3
4

PROLOG

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
11

NAME

13       pthread_attr_getstack,  pthread_attr_setstack  —  get  and  set   stack
14       attributes
15

SYNOPSIS

17       #include <pthread.h>
18
19       int pthread_attr_getstack(const pthread_attr_t *restrict attr,
20           void **restrict stackaddr, size_t *restrict stacksize);
21       int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr,
22           size_t stacksize);
23

DESCRIPTION

25       The   pthread_attr_getstack()  and  pthread_attr_setstack()  functions,
26       respectively, shall get and set the thread  creation  stack  attributes
27       stackaddr and stacksize in the attr object.
28
29       The  stack  attributes  specify  the area of storage to be used for the
30       created thread's stack. The base (lowest addressable byte) of the stor‐
31       age  shall be stackaddr, and the size of the storage shall be stacksize
32       bytes. The  stacksize  shall  be  at  least  {PTHREAD_STACK_MIN}.   The
33       pthread_attr_setstack()  function  may  fail with [EINVAL] if stackaddr
34       does not meet implementation-defined alignment requirements.  All pages
35       within  the  stack  described  by stackaddr and stacksize shall be both
36       readable and writable by the thread.
37
38       If the pthread_attr_getstack() function is called before the  stackaddr
39       attribute has been set, the behavior is unspecified.
40
41       The  behavior  is undefined if the value specified by the attr argument
42       to pthread_attr_getstack() or pthread_attr_setstack() does not refer to
43       an initialized thread attributes object.
44

RETURN VALUE

46       Upon  successful completion, these functions shall return a value of 0;
47       otherwise, an error number shall be returned to indicate the error.
48
49       The pthread_attr_getstack() function shall store  the  stack  attribute
50       values in stackaddr and stacksize if successful.
51

ERRORS

53       The pthread_attr_setstack() function shall fail if:
54
55       EINVAL The  value  of  stacksize  is  less  than {PTHREAD_STACK_MIN} or
56              exceeds an implementation-defined limit.
57
58       The pthread_attr_setstack() function may fail if:
59
60       EINVAL The value of stackaddr does not have proper alignment to be used
61              as  a  stack,  or  ((char  *)stackaddr + stacksize) lacks proper
62              alignment.
63
64       EACCES The stack page(s) described by stackaddr and stacksize  are  not
65              both readable and writable by the thread.
66
67       These functions shall not return an error code of [EINTR].
68
69       The following sections are informative.
70

EXAMPLES

72       None.
73

APPLICATION USAGE

75       These  functions are appropriate for use by applications in an environ‐
76       ment where the stack for a thread must be  placed  in  some  particular
77       region of memory.
78
79       While  it might seem that an application could detect stack overflow by
80       providing a protected page outside the  specified  stack  region,  this
81       cannot be done portably. Implementations are free to place the thread's
82       initial stack pointer anywhere within the specified region to  accommo‐
83       date  the machine's stack pointer behavior and allocation requirements.
84       Furthermore, on some architectures, such  as  the  IA‐64,  ``overflow''
85       might mean that two separate stack pointers allocated within the region
86       will overlap somewhere in the middle of the region.
87
88       After a successful call to pthread_attr_setstack(),  the  storage  area
89       specified by the stackaddr parameter is under the control of the imple‐
90       mentation, as described in Section 2.9.8,  Use  of  Application-Managed
91       Thread Stacks.
92
93       The  specification of the stackaddr attribute presents several ambigui‐
94       ties that make portable use of these functions impossible. For example,
95       the  standard  allows  implementations  to  impose  arbitrary alignment
96       requirements on stackaddr.  Applications cannot assume  that  a  buffer
97       obtained  from  malloc()  is  suitably  aligned. Note that although the
98       stacksize value passed to pthread_attr_setstack() must  satisfy  align‐
99       ment requirements, the same is not true for pthread_attr_setstacksize()
100       where the implementation must increase the specified size if  necessary
101       to achieve the proper alignment.
102

RATIONALE

104       If an implementation detects that the value specified by the attr argu‐
105       ment to pthread_attr_getstack()  or  pthread_attr_setstack()  does  not
106       refer  to  an  initialized  thread attributes object, it is recommended
107       that the function should fail and report an [EINVAL] error.
108

FUTURE DIRECTIONS

110       None.
111

SEE ALSO

113       pthread_attr_destroy(), pthread_attr_getdetachstate(),
114       pthread_attr_getstacksize(), pthread_create()
115
116       The Base Definitions volume of POSIX.1‐2008, <limits.h>, <pthread.h>
117
119       Portions  of  this text are reprinted and reproduced in electronic form
120       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
121       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
122       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
123       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
124       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
125       event of any discrepancy between this version and the original IEEE and
126       The Open Group Standard, the original IEEE and The Open Group  Standard
127       is  the  referee document. The original Standard can be obtained online
128       at http://www.unix.org/online.html .
129
130       Any typographical or formatting errors that appear  in  this  page  are
131       most likely to have been introduced during the conversion of the source
132       files to man page format. To report such errors,  see  https://www.ker
133       nel.org/doc/man-pages/reporting_bugs.html .
134
135
136
137IEEE/The Open Group                  2013            PTHREAD_ATTR_GETSTACK(3P)
Impressum