Blame man3/pthread_attr_setstack.3

Packit 7cfc04
.\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
Packit 7cfc04
.\"     <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH PTHREAD_ATTR_SETSTACK 3 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
pthread_attr_setstack, pthread_attr_getstack \- set/get stack
Packit 7cfc04
attributes in thread attributes object
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <pthread.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int pthread_attr_setstack(pthread_attr_t *" attr ,
Packit 7cfc04
.BI "                          void *" stackaddr ", size_t " stacksize );
Packit 7cfc04
.BI "int pthread_attr_getstack(const pthread_attr_t *" attr ,
Packit 7cfc04
.BI "                          void **" stackaddr ", size_t *" stacksize );
Packit 7cfc04
.PP
Packit 7cfc04
Compile and link with \fI\-pthread\fP.
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.in -4n
Packit 7cfc04
Feature Test Macro Requirements for glibc (see
Packit 7cfc04
.BR feature_test_macros (7)):
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.ad l
Packit 7cfc04
.BR pthread_attr_getstack (),
Packit 7cfc04
.BR pthread_attr_setstack ():
Packit 7cfc04
.RS 4
Packit 7cfc04
_POSIX_C_SOURCE\ >=\ 200112L
Packit 7cfc04
.RE
Packit 7cfc04
.ad b
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR pthread_attr_setstack ()
Packit 7cfc04
function sets the stack address and stack size attributes of the
Packit 7cfc04
thread attributes object referred to by
Packit 7cfc04
.I attr
Packit 7cfc04
to the values specified in
Packit 7cfc04
.IR stackaddr
Packit 7cfc04
and
Packit 7cfc04
.IR stacksize ,
Packit 7cfc04
respectively.
Packit 7cfc04
These attributes specify the location and size of the stack that should
Packit 7cfc04
be used by a thread that is created using the thread attributes object
Packit 7cfc04
.IR attr .
Packit 7cfc04
.PP
Packit 7cfc04
.I stackaddr
Packit 7cfc04
should point to the lowest addressable byte of a buffer of
Packit 7cfc04
.I stacksize
Packit 7cfc04
bytes that was allocated by the caller.
Packit 7cfc04
The pages of the allocated buffer should be both readable and writable.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR pthread_attr_getstack ()
Packit 7cfc04
function returns the stack address and stack size attributes of the
Packit 7cfc04
thread attributes object referred to by
Packit 7cfc04
.I attr
Packit 7cfc04
in the buffers pointed to by
Packit 7cfc04
.IR stackaddr
Packit 7cfc04
and
Packit 7cfc04
.IR stacksize ,
Packit 7cfc04
respectively.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success, these functions return 0;
Packit 7cfc04
on error, they return a nonzero error number.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.BR pthread_attr_setstack ()
Packit 7cfc04
can fail with the following error:
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.I stacksize
Packit 7cfc04
is less than
Packit 7cfc04
.BR PTHREAD_STACK_MIN
Packit 7cfc04
(16384) bytes.
Packit 7cfc04
On some systems, this error may also occur if
Packit 7cfc04
.IR stackaddr
Packit 7cfc04
or
Packit 7cfc04
.IR "stackaddr\ +\ stacksize"
Packit 7cfc04
is not suitably aligned.
Packit 7cfc04
.PP
Packit 7cfc04
POSIX.1 also documents an
Packit 7cfc04
.BR EACCES
Packit 7cfc04
error if the stack area described by
Packit 7cfc04
.I stackaddr
Packit 7cfc04
and
Packit 7cfc04
.I stacksize
Packit 7cfc04
is not both readable and writable by the caller.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
These functions are provided by glibc since version 2.2.
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lbw24 lb lb
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR pthread_attr_setstack (),
Packit 7cfc04
.BR pthread_attr_getstack ()
Packit 7cfc04
T}	Thread safety	MT-Safe
Packit 7cfc04
.TE
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1-2001, POSIX.1-2008.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
These functions are provided for applications that must ensure that
Packit 7cfc04
a thread's stack is placed in a particular location.
Packit 7cfc04
For most applications, this is not necessary,
Packit 7cfc04
and the use of these functions should be avoided.
Packit 7cfc04
(Use
Packit 7cfc04
.BR pthread_attr_setstacksize (3)
Packit 7cfc04
if an application simply requires a stack size other than the default.)
Packit 7cfc04
.PP
Packit 7cfc04
When an application employs
Packit 7cfc04
.BR pthread_attr_setstack (),
Packit 7cfc04
it takes over the responsibility of allocating the stack.
Packit 7cfc04
Any guard size value that was set using
Packit 7cfc04
.BR pthread_attr_setguardsize (3)
Packit 7cfc04
is ignored.
Packit 7cfc04
If deemed necessary,
Packit 7cfc04
it is the application's responsibility to allocate a guard area
Packit 7cfc04
(one or more pages protected against reading and writing)
Packit 7cfc04
to handle the possibility of stack overflow.
Packit 7cfc04
.PP
Packit 7cfc04
The address specified in
Packit 7cfc04
.I stackaddr
Packit 7cfc04
should be suitably aligned:
Packit 7cfc04
for full portability, align it on a page boundary
Packit 7cfc04
.RI ( sysconf(_SC_PAGESIZE) ).
Packit 7cfc04
.BR posix_memalign (3)
Packit 7cfc04
may be useful for allocation.
Packit 7cfc04
Probably,
Packit 7cfc04
.IR stacksize
Packit 7cfc04
should also be a multiple of the system page size.
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I attr
Packit 7cfc04
is used to create multiple threads, then the caller must change the
Packit 7cfc04
stack address attribute between calls to
Packit 7cfc04
.BR pthread_create (3);
Packit 7cfc04
otherwise, the threads will attempt to use the same memory area
Packit 7cfc04
for their stacks, and chaos will ensue.
Packit 7cfc04
.SH EXAMPLE
Packit 7cfc04
See
Packit 7cfc04
.BR pthread_attr_init (3).
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.ad l
Packit 7cfc04
.nh
Packit 7cfc04
.BR mmap (2),
Packit 7cfc04
.BR mprotect (2),
Packit 7cfc04
.BR posix_memalign (3),
Packit 7cfc04
.BR pthread_attr_init (3),
Packit 7cfc04
.BR pthread_attr_setguardsize (3),
Packit 7cfc04
.BR pthread_attr_setstackaddr (3),
Packit 7cfc04
.BR pthread_attr_setstacksize (3),
Packit 7cfc04
.BR pthread_create (3),
Packit 7cfc04
.BR pthreads (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.