logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

pthread_attr_getguardsize.3p (5972B)


  1. '\" et
  2. .TH PTHREAD_ATTR_GETGUARDSIZE "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. .ad l
  12. pthread_attr_getguardsize,
  13. pthread_attr_setguardsize
  14. \(em get and set the thread guardsize attribute
  15. .ad b
  16. .SH SYNOPSIS
  17. .LP
  18. .nf
  19. #include <pthread.h>
  20. .P
  21. int pthread_attr_getguardsize(const pthread_attr_t *restrict \fIattr\fP,
  22. size_t *restrict \fIguardsize\fP);
  23. int pthread_attr_setguardsize(pthread_attr_t *\fIattr\fP,
  24. size_t \fIguardsize\fP);
  25. .fi
  26. .SH DESCRIPTION
  27. The
  28. \fIpthread_attr_getguardsize\fR()
  29. function shall get the
  30. .IR guardsize
  31. attribute in the
  32. .IR attr
  33. object. This attribute shall be returned in the
  34. .IR guardsize
  35. parameter.
  36. .P
  37. The
  38. \fIpthread_attr_setguardsize\fR()
  39. function shall set the
  40. .IR guardsize
  41. attribute in the
  42. .IR attr
  43. object. The new value of this attribute shall be obtained from the
  44. .IR guardsize
  45. parameter. If
  46. .IR guardsize
  47. is zero, a guard area shall not be provided for threads created with
  48. .IR attr .
  49. If
  50. .IR guardsize
  51. is greater than zero, a guard area of at least size
  52. .IR guardsize
  53. bytes shall be provided for each thread created with
  54. .IR attr .
  55. .P
  56. The
  57. .IR guardsize
  58. attribute controls the size of the guard area for the created thread's
  59. stack. The
  60. .IR guardsize
  61. attribute provides protection against overflow of the stack pointer. If
  62. a thread's stack is created with guard protection, the implementation
  63. allocates extra memory at the overflow end of the stack as a buffer
  64. against stack overflow of the stack pointer. If an application
  65. overflows into this buffer an error shall result (possibly in a SIGSEGV
  66. signal being delivered to the thread).
  67. .P
  68. A conforming implementation may round up the value contained in
  69. .IR guardsize
  70. to a multiple of the configurable system variable
  71. {PAGESIZE}
  72. (see
  73. .IR <sys/mman.h> ).
  74. If an implementation rounds up the value of
  75. .IR guardsize
  76. to a multiple of
  77. {PAGESIZE},
  78. a call to
  79. \fIpthread_attr_getguardsize\fR()
  80. specifying
  81. .IR attr
  82. shall store in the
  83. .IR guardsize
  84. parameter the guard size specified by the previous
  85. \fIpthread_attr_setguardsize\fR()
  86. function call.
  87. .P
  88. The default value of the
  89. .IR guardsize
  90. attribute is implementation-defined.
  91. .P
  92. If the
  93. .IR stackaddr
  94. attribute has been set (that is, the caller is allocating and managing
  95. its own thread stacks), the
  96. .IR guardsize
  97. attribute shall be ignored and no protection shall be provided by the
  98. implementation. It is the responsibility of the application to manage
  99. stack overflow along with stack allocation and management in this
  100. case.
  101. .P
  102. The behavior is undefined if the value specified by the
  103. .IR attr
  104. argument to
  105. \fIpthread_attr_getguardsize\fR()
  106. or
  107. \fIpthread_attr_setguardsize\fR()
  108. does not refer to an initialized thread attributes object.
  109. .SH "RETURN VALUE"
  110. If successful, the
  111. \fIpthread_attr_getguardsize\fR()
  112. and
  113. \fIpthread_attr_setguardsize\fR()
  114. functions shall return zero; otherwise, an error number shall be
  115. returned to indicate the error.
  116. .SH ERRORS
  117. These functions shall fail if:
  118. .TP
  119. .BR EINVAL
  120. The parameter
  121. .IR guardsize
  122. is invalid.
  123. .P
  124. These functions shall not return an error code of
  125. .BR [EINTR] .
  126. .LP
  127. .IR "The following sections are informative."
  128. .SH EXAMPLES
  129. .SS "Retrieving the guardsize Attribute"
  130. .P
  131. This example shows how to obtain the
  132. .IR guardsize
  133. attribute of a thread attribute object.
  134. .sp
  135. .RS 4
  136. .nf
  137. #include <pthread.h>
  138. .P
  139. pthread_attr_t thread_attr;
  140. size_t guardsize;
  141. int rc;
  142. .P
  143. /* code initializing thread_attr */
  144. \&...
  145. .P
  146. rc = pthread_attr_getguardsize (&thread_attr, &guardsize);
  147. if (rc != 0) {
  148. /* handle error */
  149. ...
  150. }
  151. else {
  152. if (guardsize > 0) {
  153. /* a guard area of at least guardsize bytes is provided */
  154. ...
  155. }
  156. else {
  157. /* no guard area provided */
  158. ...
  159. }
  160. }
  161. .fi
  162. .P
  163. .RE
  164. .SH "APPLICATION USAGE"
  165. None.
  166. .SH RATIONALE
  167. The
  168. .IR guardsize
  169. attribute is provided to the application for two reasons:
  170. .IP " 1." 4
  171. Overflow protection can potentially result in wasted system resources.
  172. An application that creates a large number of threads, and which knows
  173. its threads never overflow their stack, can save system resources by
  174. turning off guard areas.
  175. .IP " 2." 4
  176. When threads allocate large data structures on the stack, large guard
  177. areas may be needed to detect stack overflow.
  178. .P
  179. The default size of the guard area is left implementation-defined
  180. since on systems supporting very large page sizes, the overhead
  181. might be substantial if at least one guard page is required by default.
  182. .P
  183. If an implementation detects that the value specified by the
  184. .IR attr
  185. argument to
  186. \fIpthread_attr_getguardsize\fR()
  187. or
  188. \fIpthread_attr_setguardsize\fR()
  189. does not refer to an initialized thread attributes object, it is
  190. recommended that the function should fail and report an
  191. .BR [EINVAL]
  192. error.
  193. .SH "FUTURE DIRECTIONS"
  194. None.
  195. .SH "SEE ALSO"
  196. The Base Definitions volume of POSIX.1\(hy2017,
  197. .IR "\fB<pthread.h>\fP",
  198. .IR "\fB<sys_mman.h>\fP"
  199. .\"
  200. .SH COPYRIGHT
  201. Portions of this text are reprinted and reproduced in electronic form
  202. from IEEE Std 1003.1-2017, Standard for Information Technology
  203. -- Portable Operating System Interface (POSIX), The Open Group Base
  204. Specifications Issue 7, 2018 Edition,
  205. Copyright (C) 2018 by the Institute of
  206. Electrical and Electronics Engineers, Inc and The Open Group.
  207. In the event of any discrepancy between this version and the original IEEE and
  208. The Open Group Standard, the original IEEE and The Open Group Standard
  209. is the referee document. The original Standard can be obtained online at
  210. http://www.opengroup.org/unix/online.html .
  211. .PP
  212. Any typographical or formatting errors that appear
  213. in this page are most likely
  214. to have been introduced during the conversion of the source files to
  215. man page format. To report such errors, see
  216. https://www.kernel.org/doc/man-pages/reporting_bugs.html .