1pthread_attr_setstack(3)   Library Functions Manual   pthread_attr_setstack(3)
2
3
4

NAME

6       pthread_attr_setstack, pthread_attr_getstack - set/get stack attributes
7       in thread attributes object
8

LIBRARY

10       POSIX threads library (libpthread, -lpthread)
11

SYNOPSIS

13       #include <pthread.h>
14
15       int pthread_attr_setstack(pthread_attr_t *attr,
16                                 void stackaddr[.stacksize],
17                                 size_t stacksize);
18       int pthread_attr_getstack(const pthread_attr_t *restrict attr,
19                                 void **restrict stackaddr,
20                                 size_t *restrict stacksize);
21
22   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
23
24       pthread_attr_getstack(), pthread_attr_setstack():
25           _POSIX_C_SOURCE >= 200112L
26

DESCRIPTION

28       The pthread_attr_setstack() function sets the stack address  and  stack
29       size  attributes of the thread attributes object referred to by attr to
30       the values specified in stackaddr and stacksize,  respectively.   These
31       attributes  specify  the  location and size of the stack that should be
32       used by a thread that is created using  the  thread  attributes  object
33       attr.
34
35       stackaddr  should  point  to the lowest addressable byte of a buffer of
36       stacksize bytes that was allocated by the caller.  The pages of the al‐
37       located buffer should be both readable and writable.
38
39       The  pthread_attr_getstack()  function  returns  the  stack address and
40       stack size attributes of the thread attributes object  referred  to  by
41       attr  in  the  buffers  pointed  to by stackaddr and stacksize, respec‐
42       tively.
43

RETURN VALUE

45       On success, these functions return 0; on error, they return  a  nonzero
46       error number.
47

ERRORS

49       pthread_attr_setstack() can fail with the following error:
50
51       EINVAL stacksize is less than PTHREAD_STACK_MIN (16384) bytes.  On some
52              systems, this error  may  also  occur  if  stackaddr  or  stack‐
53              addr + stacksize is not suitably aligned.
54
55       POSIX.1  also  documents an EACCES error if the stack area described by
56       stackaddr and stacksize is  not  both  readable  and  writable  by  the
57       caller.
58

ATTRIBUTES

60       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
61       tributes(7).
62
63       ┌────────────────────────────────────────────┬───────────────┬─────────┐
64Interface                                   Attribute     Value   
65       ├────────────────────────────────────────────┼───────────────┼─────────┤
66pthread_attr_setstack(),                    │ Thread safety │ MT-Safe │
67pthread_attr_getstack()                     │               │         │
68       └────────────────────────────────────────────┴───────────────┴─────────┘
69

STANDARDS

71       POSIX.1-2008.
72

HISTORY

74       glibc 2.2.  POSIX.1-2001.
75

NOTES

77       These  functions  are provided for applications that must ensure that a
78       thread's  stack  is  placed  in  a  particular  location.    For   most
79       applications,  this  is  not  necessary, and the use of these functions
80       should be avoided.  (Use pthread_attr_setstacksize(3) if an application
81       simply requires a stack size other than the default.)
82
83       When  an application employs pthread_attr_setstack(), it takes over the
84       responsibility of allocating the stack.  Any guard size value that  was
85       set   using   pthread_attr_setguardsize(3)   is   ignored.   If  deemed
86       necessary, it is the application's responsibility to allocate  a  guard
87       area  (one  or  more  pages  protected  against reading and writing) to
88       handle the possibility of stack overflow.
89
90       The address specified in stackaddr should be suitably aligned: for full
91       portability,  align  it  on  a  page  boundary (sysconf(_SC_PAGESIZE)).
92       posix_memalign(3) may be useful for  allocation.   Probably,  stacksize
93       should also be a multiple of the system page size.
94
95       If attr is used to create multiple threads, then the caller must change
96       the  stack  address  attribute  between  calls  to   pthread_create(3);
97       otherwise,  the  threads  will  attempt to use the same memory area for
98       their stacks, and chaos will ensue.
99

EXAMPLES

101       See pthread_attr_init(3).
102

SEE ALSO

104       mmap(2), mprotect(2), posix_memalign(3), pthread_attr_init(3),
105       pthread_attr_setguardsize(3), pthread_attr_setstackaddr(3),
106       pthread_attr_setstacksize(3), pthread_create(3), pthreads(7)
107
108
109
110Linux man-pages 6.05              2023-07-20          pthread_attr_setstack(3)
Impressum