OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / original / man3 / pthread_attr_setstack.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .TH PTHREAD_ATTR_SETSTACK 3 2008-10-24 "Linux" "Linux Programmer's Manual"
25 .SH NAME
26 pthread_attr_setstack, pthread_attr_getstack \- set/get stack
27 attributes in thread attributes object
28 .SH SYNOPSIS
29 .nf
30 .B #include <pthread.h>
31
32 .BI "int pthread_attr_setstack(pthread_attr_t *" attr ,
33 .BI "                          void *" stackaddr ", size_t " stacksize );
34 .BI "int pthread_attr_getstack(pthread_attr_t *" attr ,
35 .BI "                          void **" stackaddr ", size_t *" stacksize );
36 .sp
37 Compile and link with \fI\-pthread\fP.
38 .fi
39 .sp
40 .in -4n
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
43 .in
44 .sp
45 .ad l
46 .BR pthread_attr_getstack (),
47 .BR pthread_attr_setstack ():
48 _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
49 .ad b
50 .SH DESCRIPTION
51 The
52 .BR pthread_attr_setstack ()
53 function sets the stack address and stack size attributes of the
54 thread attributes object referred to by
55 .I attr
56 to the values specified in
57 .IR stackaddr
58 and
59 .IR stacksize ,
60 respectively.
61 These attributes specify the location and size of the stack that should
62 be used by a thread that is created using the thread attributes object
63 .IR attr .
64
65 .I stackaddr
66 should point to the lowest addressable byte of a buffer of
67 .I stacksize
68 bytes that was allocated by the caller.
69 The pages of the allocated buffer should be both readable and writable.
70
71 The
72 .BR pthread_attr_getstack ()
73 function returns the stack address and stack size attributes of the
74 thread attributes object referred to by
75 .I attr
76 in the buffers pointed to by
77 .IR stackaddr
78 and
79 .IR stacksize ,
80 respectively.
81 .SH RETURN VALUE
82 On success, these functions return 0;
83 on error, they return a nonzero error number.
84 .SH ERRORS
85 .BR pthread_attr_setstack ()
86 can fail with the following error:
87 .TP
88 .B EINVAL
89 .I stacksize
90 is less than
91 .BR PTHREAD_STACK_MIN
92 (16384) bytes.
93 On some systems, this error may also occur if
94 .IR stackaddr
95 or
96 .IR "stackaddr\ +\ stacksize"
97 is not suitably aligned.
98 .PP
99 POSIX.1-2001 also documents an
100 .BR EACCES
101 error if the stack area described by
102 .I stackaddr
103 and
104 .I stacksize
105 is not both readable and writable by the caller.
106 .SH VERSIONS
107 These functions are provided by glibc since version 2.2.
108 .SH CONFORMING TO
109 POSIX.1-2001.
110 .SH NOTES
111 These functions are provided for applications that must ensure that
112 a thread's stack is placed in a particular location.
113 For most applications, this is not necessary,
114 and the use of these functions should be avoided.
115 (Use
116 .BR pthread_attr_setstacksize (3)
117 if an application simply requires a stack size other than the default.)
118
119 When an application employs
120 .BR pthread_attr_setstack (),
121 it takes over the responsibility of allocating the stack.
122 Any guard size value that was set using
123 .BR pthread_attr_setguardsize (3)
124 is ignored.
125 If deemed necessary,
126 it is the application's responsibility to allocate a guard area
127 (one or more pages protected against reading and writing)
128 to handle the possibility of stack overflow.
129
130 The address specified in
131 .I stackaddr
132 should be suitably aligned:
133 for full portability, align it on a page boundary
134 .RI ( sysconf(_SC_PAGESIZE) ).
135 .BR posix_memalign (3)
136 may be useful for allocation.
137 Probably,
138 .IR stacksize
139 should also be a multiple of the system page size.
140
141 If
142 .I attr
143 is used to create multiple threads, then the caller must change the
144 stack address attribute between calls to
145 .BR pthread_create (3);
146 otherwise, the threads will attempt to use the same memory area
147 for their stacks, and chaos will ensue.
148 .BR
149 .SH EXAMPLE
150 See
151 .BR pthread_attr_init (3).
152 .SH SEE ALSO
153 .BR mmap (2),
154 .BR mprotect (2),
155 .BR posix_memalign (3),
156 .BR pthread_attr_init (3),
157 .BR pthread_attr_setguardsize (3),
158 .BR pthread_attr_setstackaddr (3),
159 .BR pthread_attr_setstacksize (3),
160 .BR pthread_create (3),
161 .BR pthreads (7)