1 .\" $NetBSD: mmap.2,v 1.48 2015/02/27 16:18:00 christos Exp $
3 .\" Copyright (c) 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)mmap.2 8.4 (Berkeley) 5/11/95
37 .Nd map files or devices into memory
43 .Fn mmap "void *addr" "size_t len" "int prot" "int flags" "int fd" "off_t offset"
47 function causes the pages starting at
49 and continuing for at most
51 bytes to be mapped from the object described by
53 starting at byte offset
57 is not a multiple of the pagesize, the mapped region may extend past the
59 Any such extension beyond the end of the mapped object will be zero-filled.
63 is non-zero, it is used as a hint to the system.
64 (As a convenience to the system, the actual address of the region may differ
65 from the address supplied.)
68 is zero, an address will be selected by the system.
69 The actual starting address of the region is returned.
72 deletes any previous mapping in the allocated address range.
74 The protections (region accessibility) are specified in the
80 .Bl -tag -width PROT_WRITEXX -offset indent
82 Pages may be executed.
88 Pages may not be accessed.
92 Note that, due to hardware limitations, on some platforms
100 Portable programs should not rely on these flags being separately
106 parameter specifies the type of the mapped object, mapping options and
107 whether modifications made to the mapped copy of the page are private
108 to the process or are to be shared with other references.
114 Sharing, mapping type and options are specified in the
118 the following values:
120 .Bl -tag -width MAP_HASSEMAPHOREXX -offset indent
121 .It Dv MAP_ALIGNED(n)
122 Request that the allocation be aligned to the given boundary.
125 should be the base 2 logarithm of the desired alignment (e.g., to
126 request alignment to 16K, use 14 as the value for n).
127 The alignment must be equal to or greater than the platform's page
134 Map anonymous memory not associated with any specific file.
135 The file descriptor is not used for creating
137 regions, and must be specified as \-1.
138 The mapped memory will be zero filled.
140 Mapped from a regular file or character-special device memory.
141 Read accesses beyond the end of of the file or device but less
142 than the current page size will be zero-filled.
143 Write accesses beyond the end of the file or device but less
144 than the current page size will not affect the file or device.
145 References beyond the end of file that are beyond the current
146 page size will result in the delivery of
150 Do not permit the system to select a different address than the one
152 If the specified address cannot be used,
155 If MAP_FIXED is specified,
157 must be a multiple of the pagesize.
158 Use of this option is discouraged.
159 .It Dv MAP_HASSEMAPHORE
160 Notify the kernel that the region may contain semaphores and that special
161 handling may be necessary.
163 Permit regions to be inherited across
167 Attempt to use the address
169 even if it falls within the normally protected process data or
170 text segment memory regions.
171 If the requested region of memory
172 is actually present in the memory map, a different address will
175 had not been specified.
180 this flag is ignored and the system will select a mapping address.
182 Lock the mapped region into memory as with
185 Modifications made by this process are private, however modifications made by
186 other processes using
190 Modifications are shared.
195 function does not unmap pages, see
197 for further information.
199 The current design does not allow a process to specify the location of
201 In the future we may define an additional mapping type,
204 the file descriptor argument specifies a file or device to which swapping
209 is not specified, the system will attempt to place the mapping in an
210 unused portion of the address space chosen to minimize possible
211 collision between mapped regions and the heap.
213 Upon successful completion,
215 returns a pointer to the mapped region.
216 Otherwise, a value of
220 is set to indicate the error.
223 is defined in the header
224 .Ao Pa sys/mman.h Ac .
225 No successful return from
227 will return the value
236 was specified as part of the
240 was not open for reading.
245 were specified as part of the
251 was not open for writing.
254 is not a valid open file descriptor.
260 .\"was not specified as part of the
264 was specified and the
266 parameter was not page aligned or was outside of the
267 valid address range for a process.
268 .Dv MAP_ANON was specified and
273 did not reference a regular or character special file.
276 was specified and the
278 parameter wasn't available.
280 was specified and insufficient memory was available.
283 references a regular file and the value of
287 would exceed the offset maximum established in its open file description.
306 interface was first designed in