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

210 lines
7.3 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>mprotect</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="mprotect"></a> <a name="tag_03_381"></a><!-- mprotect -->
<!--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_381_01"></a>NAME</h4>
<blockquote>mprotect - set protection of memory mapping</blockquote>
<h4><a name="tag_03_381_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<div class="box"><code><tt><sup>[<a href="javascript:open_code('MPR')">MPR</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> #include &lt;<a href="../basedefs/sys/mman.h.html">sys/mman.h</a>&gt;<br>
<br>
int mprotect(void *</tt><i>addr</i><tt>, size_t</tt> <i>len</i><tt>, int</tt> <i>prot</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_381_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>mprotect</i>() function shall change the access protections to be that specified by <i>prot</i> for those whole pages
containing any part of the address space of the process starting at address <i>addr</i> and continuing for <i>len</i> bytes. The
parameter <i>prot</i> determines whether read, write, execute, or some combination of accesses are permitted to the data being
mapped. The <i>prot</i> argument should be either PROT_NONE or the bitwise-inclusive OR of one or more of PROT_READ, PROT_WRITE,
and PROT_EXEC.</p>
<p>If an implementation cannot support the combination of access types specified by <i>prot</i>, the call to <i>mprotect</i>()
shall fail.</p>
<p>An implementation may permit accesses other than those specified by <i>prot</i>; however, no implementation shall permit a write
to succeed where PROT_WRITE has not been set or shall permit any access where PROT_NONE alone has been set. Implementations shall
support at least the following values of <i>prot</i>: PROT_NONE, PROT_READ, PROT_WRITE, and the bitwise-inclusive OR of PROT_READ
and PROT_WRITE. If PROT_WRITE is specified, the application shall ensure that it has opened the mapped objects in the specified
address range with write permission, unless MAP_PRIVATE was specified in the original mapping, regardless of whether the file
descriptors used to map the objects have since been closed.</p>
<p>The implementation shall require that <i>addr</i> be a multiple of the page size as returned by <a href=
"../functions/sysconf.html"><i>sysconf</i>()</a>.</p>
<p>The behavior of this function is unspecified if the mapping was not established by a call to <a href=
"../functions/mmap.html"><i>mmap</i>()</a>.</p>
<p>When <i>mprotect</i>() fails for reasons other than [EINVAL], the protections on some of the pages in the range
[<i>addr</i>,<i>addr</i>+<i>len</i>) may have been changed.</p>
</blockquote>
<h4><a name="tag_03_381_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>mprotect</i>() shall return 0; otherwise, it shall return -1 and set <i>errno</i> to indicate the
error.</p>
</blockquote>
<h4><a name="tag_03_381_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>mprotect</i>() function shall fail if:</p>
<dl compact>
<dt>[EACCES]</dt>
<dd>The <i>prot</i> argument specifies a protection that violates the access permission the process has to the underlying memory
object.</dd>
<dt>[EAGAIN]</dt>
<dd>The <i>prot</i> argument specifies PROT_WRITE over a MAP_PRIVATE mapping and there are insufficient memory resources to reserve
for locking the private page.</dd>
<dt>[EINVAL]</dt>
<dd>The <i>addr</i> argument is not a multiple of the page size as returned by <a href=
"../functions/sysconf.html"><i>sysconf</i>()</a>.</dd>
<dt>[ENOMEM]</dt>
<dd>Addresses in the range [<i>addr</i>,<i>addr</i>+<i>len</i>) are invalid for the address space of a process, or specify one or
more pages which are not mapped.</dd>
<dt>[ENOMEM]</dt>
<dd>The <i>prot</i> argument specifies PROT_WRITE on a MAP_PRIVATE mapping, and it would require more space than the system is able
to supply for locking the private pages, if required.</dd>
<dt>[ENOTSUP]</dt>
<dd>The implementation does not support the combination of accesses requested in the <i>prot</i> argument.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_381_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_381_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>The [EINVAL] error above is marked EX because it is defined as an optional error in the POSIX Realtime Extension.</p>
</blockquote>
<h4><a name="tag_03_381_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_381_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_381_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="mmap.html"><i>mmap</i>()</a> , <a href="sysconf.html"><i>sysconf</i>()</a> , the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/sys/mman.h.html"><i>&lt;sys/mman.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_381_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4, Version 2.</p>
</blockquote>
<h4><a name="tag_03_381_12"></a>Issue 5</h4>
<blockquote>
<p>Moved from X/OPEN UNIX extension to BASE.</p>
<p>Aligned with <i>mprotect</i>() in the POSIX Realtime Extension as follows:</p>
<ul>
<li>
<p>The DESCRIPTION is largely reworded.</p>
</li>
<li>
<p>[ENOTSUP] and a second form of [ENOMEM] are added as mandatory error conditions.</p>
</li>
<li>
<p>[EAGAIN] is moved from the optional to the mandatory error conditions.</p>
</li>
</ul>
</blockquote>
<h4><a name="tag_03_381_13"></a>Issue 6</h4>
<blockquote>
<p>The <i>mprotect</i>() function is marked as part of the Memory Protection option.</p>
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
<ul>
<li>
<p>The DESCRIPTION is updated to state that implementations require <i>addr</i> to be a multiple of the page size as returned by <a
href="../functions/sysconf.html"><i>sysconf</i>()</a>.</p>
</li>
<li>
<p>The [EINVAL] error condition is added.</p>
</li>
</ul>
<p>The DESCRIPTION is updated to avoid use of the term &quot;must&quot; for application requirements.</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>