1 .\" $NetBSD: mmap.2,v 1.5 1995/06/24 10:48:59 cgd 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. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)mmap.2 8.1 (Berkeley) 6/4/93
41 .Nd map files or devices into memory
43 .Fd #include <sys/mman.h>
56 function causes the pages starting at
58 and continuing for at most
60 bytes to be mapped from the object described by
62 starting at byte offset
68 is not a multiple of the pagesize, the mapped region may extend past the
73 is non-zero, it is used as a hint to the system.
74 (As a convenience to the system, the actual address of the region may differ
75 from the address supplied.)
78 is zero, an address will be selected by the system.
79 The actual starting address of the region is returned.
82 deletes any previous mapping in the allocated address range.
84 The protections (region accessibility) are specified in the
90 .Bl -tag -width MAP_FIXEDX
92 Pages may be executed.
101 parameter specifies the type of the mapped object, mapping options,
102 and whether modifications made to the mapped copy of the page
103 are private to the process (copy-on-write)
104 or are to be shared with other references.
105 Sharing, mapping type, and options are specified in the
109 the following values:
111 .Bl -tag -width MAP_HASSEMAPHOREX
113 Map anonymous memory not associated with any specific file.
114 Mac OS X specific: the file descriptor used for creating
116 regions can be used to pass some Mach VM flags, and can
117 be specified as \-1 if no such flags are associated with
118 the region. Mach VM flags are defined in
119 <mach/vm_statistics.h> and the ones that currently apply
124 VM_FLAGS_PURGABLE to create Mach purgable (i.e. volatile) memory
125 VM_MAKE_TAG(tag) to associate an 8-bit tag with the region
127 <mach/vm_statistics.h> defines some preset tags (with a VM_MEMORY_ prefix).
128 Users are encouraged to use tags between 240 and 255.
129 Tags are used by tools such as vmmap(1) to help identify specific memory regions.
131 Mapped from a regular file or character-special device memory. (This is
132 the default mapping type, and need not be specified.)
134 Do not permit the system to select a different address than the one
136 If the specified address cannot be used,
139 If MAP_FIXED is specified,
141 must be a multiple of the pagesize.
142 Use of this option is discouraged.
143 .It Dv MAP_HASSEMAPHORE
144 Notify the kernel that the region may contain semaphores and that special
145 handling may be necessary.
147 Modifications are private (copy-on-write).
149 Modifications are shared.
151 Pages in this mapping are not retained in the kernel's memory cache.
152 If the system runs low on memory, pages in MAP_NOCACHE mappings will be among
153 the first to be reclaimed.
154 This flag is intended for mappings that have little locality and
155 provides a hint to the kernel that pages in this mapping are unlikely to be needed
156 again in the near future.
159 Conforming applications must specify either MAP_PRIVATE or MAP_SHARED.
163 function does not unmap pages, see
165 for further information.
167 The current design does not allow a process to specify the location of
169 In the future we may define an additional mapping type,
172 the file descriptor argument specifies a file or device to which swapping
175 Upon successful completion,
177 returns a pointer to the mapped region.
178 Otherwise, a value of -1 is returned and
180 is set to indicate the error.
188 is not open for reading.
195 are specified as part of the
201 is not open for writing.
205 is not a valid file descriptor for an open file.
210 parameter is not page aligned.
214 does not reference a regular or character special file.
218 does not include either MAP_PRIVATE or MAP_SHARED.
222 is not greater than zero.
226 is not a multiple of the page size,
231 The limit on mapped regions (per process or system) is exceeded.
236 is not supported for mapping.
240 is specified and the address range specified
241 exceeds the address space limit for the process.
245 is specified and the address specified by the
247 parameter isn't available.
251 is specified and insufficient memory is available.
254 Addresses in the specified range are invalid for fildes.
257 Addresses in the specified range exceed the maximum offset
261 .Fd #include <sys/types.h>
262 .Fd #include <sys/mman.h>
271 set to EINVAL in places that historically succeeded.
272 The rules have changed as follows:
277 parameter must specify either MAP_PRIVATE or MAP_SHARED.
281 parameter must not be 0.
285 parameter must be a multiple of pagesize,