Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/pthread_attr_getguardsize.html
2024-02-19 00:21:47 -05:00

172 lines
6.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>pthread_attr_getguardsize</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="pthread_attr_getguardsize"></a> <a name="tag_03_489"></a><!-- pthread_attr_getguardsize -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_489_01"></a>NAME</h4>
<blockquote>pthread_attr_getguardsize, pthread_attr_setguardsize - get and set the thread guardsize attribute</blockquote>
<h4><a name="tag_03_489_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> #include &lt;<a href="../basedefs/pthread.h.html">pthread.h</a>&gt;<br>
<br>
int pthread_attr_getguardsize(const pthread_attr_t *restrict</tt> <i>attr</i><tt>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size_t *restrict</tt> <i>guardsize</i><tt>);<br>
int pthread_attr_setguardsize(pthread_attr_t</tt> <i>*attr</i><tt>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size_t</tt> <i>guardsize</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]"
border="0"></tt></code></div>
<tt><br>
</tt></blockquote>
<h4><a name="tag_03_489_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>pthread_attr_getguardsize</i>() function shall get the <i>guardsize</i> attribute in the <i>attr</i> object. This
attribute shall be returned in the <i>guardsize</i> parameter.</p>
<p>The <i>pthread_attr_setguardsize</i>() function shall set the <i>guardsize</i> attribute in the <i>attr</i> object. The new
value of this attribute shall be obtained from the <i>guardsize</i> parameter. If <i>guardsize</i> is zero, a guard area shall not
be provided for threads created with <i>attr</i>. If <i>guardsize</i> is greater than zero, a guard area of at least size
<i>guardsize</i> bytes shall be provided for each thread created with <i>attr</i>.</p>
<p>The <i>guardsize</i> attribute controls the size of the guard area for the created thread's stack. The <i>guardsize</i>
attribute provides protection against overflow of the stack pointer. If a thread's stack is created with guard protection, the
implementation allocates extra memory at the overflow end of the stack as a buffer against stack overflow of the stack pointer. If
an application overflows into this buffer an error shall result (possibly in a SIGSEGV signal being delivered to the thread).</p>
<p>A conforming implementation may round up the value contained in <i>guardsize</i> to a multiple of the configurable system
variable {PAGESIZE} (see <a href="../basedefs/sys/mman.h.html"><i>&lt;sys/mman.h&gt;</i></a>). If an implementation rounds up the
value of <i>guardsize</i> to a multiple of {PAGESIZE}, a call to <i>pthread_attr_getguardsize</i>() specifying <i>attr</i> shall
store in the <i>guardsize</i> parameter the guard size specified by the previous <i>pthread_attr_setguardsize</i>() function
call.</p>
<p>The default value of the <i>guardsize</i> attribute is {PAGESIZE} bytes. The actual value of {PAGESIZE} is
implementation-defined.</p>
<p>If the <i>stackaddr</i> or <i>stack</i> attribute has been set (that is, the caller is allocating and managing its own thread
stacks), the <i>guardsize</i> attribute shall be ignored and no protection shall be provided by the implementation. It is the
responsibility of the application to manage stack overflow along with stack allocation and management in this case.</p>
</blockquote>
<h4><a name="tag_03_489_04"></a>RETURN VALUE</h4>
<blockquote>
<p>If successful, the <i>pthread_attr_getguardsize</i>() and <i>pthread_attr_setguardsize</i>() functions shall return zero;
otherwise, an error number shall be returned to indicate the error.</p>
</blockquote>
<h4><a name="tag_03_489_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>pthread_attr_getguardsize</i>() and <i>pthread_attr_setguardsize</i>() functions shall fail if:</p>
<dl compact>
<dt>[EINVAL]</dt>
<dd>The attribute <i>attr</i> is invalid.</dd>
<dt>[EINVAL]</dt>
<dd>The parameter <i>guardsize</i> is invalid.</dd>
</dl>
<p>These functions shall not return an error code of [EINTR].</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_489_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_489_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_489_08"></a>RATIONALE</h4>
<blockquote>
<p>The <i>guardsize</i> attribute is provided to the application for two reasons:</p>
<ol>
<li>
<p>Overflow protection can potentially result in wasted system resources. An application that creates a large number of threads,
and which knows its threads never overflow their stack, can save system resources by turning off guard areas.</p>
</li>
<li>
<p>When threads allocate large data structures on the stack, large guard areas may be needed to detect stack overflow.</p>
</li>
</ol>
</blockquote>
<h4><a name="tag_03_489_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_489_10"></a>SEE ALSO</h4>
<blockquote>
<p>The Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/pthread.h.html"><i>&lt;pthread.h&gt;</i></a>, <a href="../basedefs/sys/mman.h.html"><i>&lt;sys/mman.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_489_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 5.</p>
</blockquote>
<h4><a name="tag_03_489_12"></a>Issue 6</h4>
<blockquote>
<p>In the ERRORS section, a third [EINVAL] error condition is removed as it is covered by the second error condition.</p>
<p>The <b>restrict</b> keyword is added to the <i>pthread_attr_getguardsize</i>() prototype for alignment with the
ISO/IEC&nbsp;9899:1999 standard.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>