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/types.h>
44 .Fd #include <sys/mman.h>
46 .Fn mmap "void *addr" "size_t len" "int prot" "int flags" "int fd" "off_t offset"
50 function causes the pages starting at
52 and continuing for at most
54 bytes to be mapped from the object described by
56 starting at byte offset
62 is not a multiple of the pagesize, the mapped region may extend past the
67 is non-zero, it is used as a hint to the system.
68 (As a convenience to the system, the actual address of the region may differ
69 from the address supplied.)
72 is zero, an address will be selected by the system.
73 The actual starting address of the region is returned.
76 deletes any previous mapping in the allocated address range.
78 The protections (region accessibility) are specified in the
84 .Bl -tag -width MAP_FIXEDX
86 Pages may be executed.
95 parameter specifies the type of the mapped object, mapping options and
96 whether modifications made to the mapped copy of the page are private
97 to the process or are to be shared with other references.
98 Sharing, mapping type and options are specified in the
102 the following values:
104 .Bl -tag -width MAP_FIXEDX
106 Map anonymous memory not associated with any specific file.
107 The file descriptor used for creating
109 regions is used only for
110 naming, and may be specified as \-1 if no name is associated with the
113 Mapped from a regular file or character-special device memory. (This is
114 the default mapping type, and need not be specified.)
116 Do not permit the system to select a different address than the one
118 If the specified address cannot be used,
121 If MAP_FIXED is specified,
123 must be a multiple of the pagesize.
124 Use of this option is discouraged.
125 .It Dv MAP_HASSEMAPHORE
126 Notify the kernel that the region may contain semaphores and that special
127 handling may be necessary.
129 Modifications are private.
131 Modifications are shared.
136 function does not unmap pages, see
138 for further information.
140 The current design does not allow a process to specify the location of
142 In the future we may define an additional mapping type,
145 the file descriptor argument specifies a file or device to which swapping
148 Upon successful completion,
150 returns a pointer to the mapped region.
151 Otherwise, a value of -1 is returned and
153 is set to indicate the error.
161 was specified as part of the
165 was not open for reading.
170 were specified as part
177 was not open for writing.
180 is not a valid open file descriptor.
183 was specified and the
185 parameter was not page aligned.
187 did not reference a regular or character special file.
190 was specified and the
192 parameter wasn't available.
194 was specified and insufficient memory was available.