📄 mprotect.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>mprotect</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_007_717"> </a>NAME</h4><blockquote>mprotect - set protection of memory mapping</blockquote><h4><a name = "tag_000_007_718"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="sysmman.h.html">sys/mman.h</a>>int mprotect(void *<i>addr</i>, size_t <i>len</i>, int <i>prot</i>);</code></pre></blockquote><h4><a name = "tag_000_007_719"> </a>DESCRIPTION</h4><blockquote>The function<i>mprotect()</i>changes the access protectionsto be that specified by<i>prot</i>for those whole pages containing any part of theaddress 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 ofaccesses are permitted to the data being mapped.The<i>prot</i>argument should be either PROT_NONEor the bitwise inclusive OR of one or more of PROT_READ, PROT_WRITE andPROT_EXEC.<p>If an implementation cannot support the combination of access typesspecified by<i>prot</i>,the call to<i>mprotect()</i>fails.<p>An implementation may permit accesses other than those specified by<i>prot</i>;however, no implementation permits a write to succeed wherePROT_WRITE has not been set or permits any access wherePROT_NONE alone has been set.Implementations will support at least the following values of<i>prot</i>:PROT_NONE,PROT_READ,PROT_WRITE,and the inclusive OR ofPROT_READandPROT_WRITE.If PROT_WRITEis specified, the application must have opened the mapped objectsin the specified address range with write permission, unlessMAP_PRIVATEwas specified in the original mapping, regardless of whetherthe file descriptors used to map the objects have since been closed.<p>The implementation willrequire that<i>addr</i>be a multiple of the page size as returned by<i><a href="sysconf.html">sysconf()</a></i>.<p>The behaviour of this function is unspecifiedif the mapping was not established by a call to<i><a href="mmap.html">mmap()</a></i>.<p>When<i>mprotect()</i>fails for reasons other than [EINVAL], the protections on some of the pages inthe range [<i>addr, addr + len</i>) may have been changed.</blockquote><h4><a name = "tag_000_007_720"> </a>RETURN VALUE</h4><blockquote>Upon successful completion,<i>mprotect()</i>returns 0. Otherwise, it returns -1 and sets <i>errno</i> to indicate theerror.</blockquote><h4><a name = "tag_000_007_721"> </a>ERRORS</h4><blockquote>The<i>mprotect()</i>function will fail if:<dl compact><dt>[EACCES]<dd>The <i>prot</i> argument specifies a protection that violates the accesspermission the process has to the underlying memory object.<dt>[EAGAIN]<dd>The <i>prot</i> argument specifies PROT_WRITE over a MAP_PRIVATE mapping andthere are insufficient memory resources to reserve for locking the privatepage.<dt>[EINVAL]<dd>The <i>addr</i> argument is not a multiple of the page size as returned by<i><a href="sysconf.html">sysconf()</a></i>.<dt>[ENOMEM]<dd>Addresses in the range [<i>addr, addr + len</i>) are invalid for the addressspace of a process, or specify one or more pages which are not mapped.<dt>[ENOMEM]<dd>The<i>prot</i>argument specifies PROT_WRITE on a MAP_PRIVATE mapping,and it would require more space than the system is ableto supply for locking the private pages, if required.<dt>[ENOTSUP]<dd>The implementation does not support the combination of accessesrequested in the<i>prot</i>argument.</dl></blockquote><h4><a name = "tag_000_007_722"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_723"> </a>APPLICATION USAGE</h4><blockquote>The EINVAL error above is marked EX because it is defined as anoptional error in the POSIX Realtime Extension.</blockquote><h4><a name = "tag_000_007_724"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_725"> </a>SEE ALSO</h4><blockquote><i><a href="mmap.html">mmap()</a></i>,<i><a href="sysconf.html">sysconf()</a></i>,<i><a href="sysmman.h.html"><sys/mman.h></a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -