📄 mmap.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-2004 IEEE and The Open Group, All Rights Reserved --><title>mmap</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="mmap"></a> <a name="tag_03_379"></a><!-- mmap --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_379_01"></a>NAME</h4><blockquote>mmap - map pages of memory</blockquote><h4><a name="tag_03_379_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('MC3')">MC3</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/sys/mman.h.html">sys/mman.h</a>><br><br> void *mmap(void *</tt><i>addr</i><tt>, size_t</tt> <i>len</i><tt>, int</tt> <i>prot</i><tt>, int</tt> <i>flags</i><tt>,<br> int</tt> <i>fildes</i><tt>, off_t</tt> <i>off</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_379_03"></a>DESCRIPTION</h4><blockquote><p>The <i>mmap</i>() function shall establish a mapping between a process' address space and a file, shared memory object, or<sup>[<a href="javascript:open_code('TYM')">TYM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> typed memory object. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> The format of the call is asfollows:</p><pre><i>pa</i><tt>=</tt><i>mmap</i><tt>(</tt><i>addr</i><tt>,</tt> <i>len</i><tt>,</tt> <i>prot</i><tt>,</tt> <i>flags</i><tt>,</tt> <i>fildes</i><tt>,</tt> <i>off</i><tt>);</tt></pre><p>The <i>mmap</i>() function shall establish a mapping between the address space of the process at an address <i>pa</i> for<i>len</i> bytes to the memory object represented by the file descriptor <i>fildes</i> at offset <i>off</i> for <i>len</i> bytes.The value of <i>pa</i> is an implementation-defined function of the parameter <i>addr</i> and the values of <i>flags</i>, furtherdescribed below. A successful <i>mmap</i>() call shall return <i>pa</i> as its result. The address range starting at <i>pa</i> andcontinuing for <i>len</i> bytes shall be legitimate for the possible (not necessarily current) address space of the process. Therange of bytes starting at <i>off</i> and continuing for <i>len</i> bytes shall be legitimate for the possible (not necessarilycurrent) offsets in the file, shared memory object, or <sup>[<a href="javascript:open_code('TYM')">TYM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> typed memory object <img src="../images/opt-end.gif" alt="[Option End]" border="0"> represented by <i>fildes</i>.</p><p><sup>[<a href="javascript:open_code('TYM')">TYM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If <i>fildes</i> represents a typed memory object opened with either the POSIX_TYPED_MEM_ALLOCATE flag or thePOSIX_TYPED_MEM_ALLOCATE_CONTIG flag, the memory object to be mapped shall be that portion of the typed memory object allocated bythe implementation as specified below. In this case, if <i>off</i> is non-zero, the behavior of <i>mmap</i>() is undefined. If<i>fildes</i> refers to a valid typed memory object that is not accessible from the calling process, <i>mmap</i>() shall fail. <imgsrc="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>The mapping established by <i>mmap</i>() shall replace any previous mappings for those whole pages containing any part of theaddress space of the process starting at <i>pa</i> and continuing for <i>len</i> bytes.</p><p>If the size of the mapped file changes after the call to <i>mmap</i>() as a result of some other operation on the mapped file,the effect of references to portions of the mapped region that correspond to added or removed portions of the file isunspecified.</p><p>The <i>mmap</i>() function shall be supported for regular files, shared memory objects, and <sup>[<a href="javascript:open_code('TYM')">TYM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> typed memoryobjects. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> Support for any other type of file is unspecified.</p><p>If <i>len</i> is zero, <i>mmap</i>() shall fail and no mapping shall be established.</p><p>The parameter <i>prot</i> determines whether read, write, execute, or some combination of accesses are permitted to the databeing mapped. The <i>prot</i> shall be either PROT_NONE or the bitwise-inclusive OR of one or more of the other flags in thefollowing table, defined in the <a href="../basedefs/sys/mman.h.html"><i><sys/mman.h></i></a> header.</p><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Symbolic Constant</b></p></th><th align="center"><p class="tent"><b>Description</b></p></th></tr><tr valign="top"><td align="left"><p class="tent">PROT_READ</p></td><td align="left"><p class="tent">Data can be read.</p></td></tr><tr valign="top"><td align="left"><p class="tent">PROT_WRITE</p></td><td align="left"><p class="tent">Data can be written.</p></td></tr><tr valign="top"><td align="left"><p class="tent">PROT_EXEC</p></td><td align="left"><p class="tent">Data can be executed.</p></td></tr><tr valign="top"><td align="left"><p class="tent">PROT_NONE</p></td><td align="left"><p class="tent">Data cannot be accessed.</p></td></tr></table></center><p>If an implementation cannot support the combination of access types specified by <i>prot</i>, the call to <i>mmap</i>() shallfail.</p><p>An implementation may permit accesses other than those specified by <i>prot</i>; <sup>[<a href="javascript:open_code('MPR')">MPR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> however, ifthe Memory Protection option is supported, the implementation shall not permit a write to succeed where PROT_WRITE has not been setor shall not permit any access where PROT_NONE alone has been set. The implementation shall support at least the following valuesof <i>prot</i>: PROT_NONE, PROT_READ, PROT_WRITE, and the bitwise-inclusive OR of PROT_READ and PROT_WRITE. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> If the Memory Protection option is not supported, the result of any accessthat conflicts with the specified protection is undefined. The file descriptor <i>fildes</i> shall have been opened with readpermission, regardless of the protection options specified. If PROT_WRITE is specified, the application shall ensure that it hasopened the file descriptor <i>fildes</i> with write permission unless MAP_PRIVATE is specified in the <i>flags</i> parameter asdescribed below.</p><p>The parameter <i>flags</i> provides other information about the handling of the mapped data. The value of <i>flags</i> is thebitwise-inclusive OR of these options, defined in <a href="../basedefs/sys/mman.h.html"><i><sys/mman.h></i></a>:</p><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Symbolic Constant</b></p></th><th align="center"><p class="tent"><b>Description</b></p></th></tr><tr valign="top"><td align="left"><p class="tent">MAP_SHARED</p></td><td align="left"><p class="tent">Changes are shared.</p></td></tr><tr valign="top"><td align="left"><p class="tent">MAP_PRIVATE</p></td><td align="left"><p class="tent">Changes are private.</p></td></tr><tr valign="top"><td align="left"><p class="tent">MAP_FIXED</p></td><td align="left"><p class="tent">Interpret <i>addr</i> exactly.</p></td></tr></table></center><p>Implementations that do not support the Memory Mapped Files option are not required to support MAP_PRIVATE.</p><p>It is implementation-defined whether MAP_FIXED shall be supported. <sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup><img src="../images/opt-start.gif" alt="[Option Start]" border="0"> MAP_FIXED shall be supported on XSI-conformant systems.<img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>MAP_SHARED and MAP_PRIVATE describe the disposition of write references to the memory object. If MAP_SHARED is specified, writereferences shall change the underlying object. If MAP_PRIVATE is specified, modifications to the mapped data by the calling processshall be visible only to the calling process and shall not change the underlying object. It is unspecified whether modifications tothe underlying object done after the MAP_PRIVATE mapping is established are visible through the MAP_PRIVATE mapping. EitherMAP_SHARED or MAP_PRIVATE can be specified, but not both. The mapping type is retained across <a href="../functions/fork.html"><i>fork</i>()</a>.</p><p><sup>[<a href="javascript:open_code('TYM')">TYM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">When <i>fildes</i> represents a typed memory object opened with either the POSIX_TYPED_MEM_ALLOCATE flag or thePOSIX_TYPED_MEM_ALLOCATE_CONTIG flag, <i>mmap</i>() shall, if there are enough resources available, map <i>len</i> bytes allocatedfrom the corresponding typed memory object which were not previously allocated to any process in any processor that may access thattyped memory object. If there are not enough resources available, the function shall fail. If <i>fildes</i> represents a typed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -