]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/mmap.2
xnu-344.tar.gz
[apple/xnu.git] / bsd / man / man2 / mmap.2
CommitLineData
9bccf70c
A
1.\" $NetBSD: mmap.2,v 1.5 1995/06/24 10:48:59 cgd Exp $
2.\"
3.\" Copyright (c) 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
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.
21.\"
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
32.\" SUCH DAMAGE.
33.\"
34.\" @(#)mmap.2 8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt MMAP 2
38.Os BSD 4
39.Sh NAME
40.Nm mmap
41.Nd map files or devices into memory
42.Sh SYNOPSIS
43.Fd #include <sys/types.h>
44.Fd #include <sys/mman.h>
45.Ft void *
46.Fn mmap "void *addr" "size_t len" "int prot" "int flags" "int fd" "off_t offset"
47.Sh DESCRIPTION
48The
49.Nm mmap
50function causes the pages starting at
51.Fa addr
52and continuing for at most
53.Fa len
54bytes to be mapped from the object described by
55.Fa fd ,
56starting at byte offset
57.Fa offset .
58If
59.Fa offset
60or
61.Fa len
62is not a multiple of the pagesize, the mapped region may extend past the
63specified range.
64.Pp
65If
66.Fa addr
67is 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
69from the address supplied.)
70If
71.Fa addr
72is zero, an address will be selected by the system.
73The actual starting address of the region is returned.
74A successful
75.Fa mmap
76deletes any previous mapping in the allocated address range.
77.Pp
78The protections (region accessibility) are specified in the
79.Fa prot
80argument by
81.Em or Ns 'ing
82the following values:
83.Pp
84.Bl -tag -width MAP_FIXEDX
85.It Dv PROT_EXEC
86Pages may be executed.
87.It Dv PROT_READ
88Pages may be read.
89.It Dv PROT_WRITE
90Pages may be written.
91.El
92.Pp
93The
94.Fa flags
95parameter specifies the type of the mapped object, mapping options and
96whether modifications made to the mapped copy of the page are private
97to the process or are to be shared with other references.
98Sharing, mapping type and options are specified in the
99.Fa flags
100argument by
101.Em or Ns 'ing
102the following values:
103.Pp
104.Bl -tag -width MAP_FIXEDX
105.It Dv MAP_ANON
106Map anonymous memory not associated with any specific file.
107The file descriptor used for creating
108.Dv MAP_ANON
109regions is used only for
110naming, and may be specified as \-1 if no name is associated with the
111region.
112.It Dv MAP_FILE
113Mapped from a regular file or character-special device memory. (This is
114the default mapping type, and need not be specified.)
115.It Dv MAP_FIXED
116Do not permit the system to select a different address than the one
117specified.
118If the specified address cannot be used,
119.Nm mmap
120will fail.
121If MAP_FIXED is specified,
122.Fa addr
123must be a multiple of the pagesize.
124Use of this option is discouraged.
125.It Dv MAP_HASSEMAPHORE
126Notify the kernel that the region may contain semaphores and that special
127handling may be necessary.
128.It Dv MAP_INHERIT
129Permit regions to be inherited across
130.Xr exec 2
131system calls.
132.It Dv MAP_PRIVATE
133Modifications are private.
134.It Dv MAP_SHARED
135Modifications are shared.
136.El
137.Pp
138The
139.Xr close 2
140function does not unmap pages, see
141.Xr munmap 2
142for further information.
143.Pp
144The current design does not allow a process to specify the location of
145swap space.
146In the future we may define an additional mapping type,
147.Dv MAP_SWAP ,
148in which
149the file descriptor argument specifies a file or device to which swapping
150should be done.
151.Sh RETURN VALUES
152Upon successful completion,
153.Nm mmap
154returns a pointer to the mapped region.
155Otherwise, a value of -1 is returned and
156.Va errno
157is set to indicate the error.
158.Sh ERRORS
159.Fn Mmap
160will fail if:
161.Bl -tag -width Er
162.It Bq Er EACCES
163The flag
164.Dv PROT_READ
165was specified as part of the
166.Fa prot
167parameter and
168.Fa fd
169was not open for reading.
170The flags
171.Dv PROT_WRITE
172and
173.Dv MAP_SHARED
174were specified as part
175of the
176.Fa flags
177and
178.Fa prot
179parameters and
180.Fa fd
181was not open for writing.
182.It Bq Er EBADF
183.Fa fd
184is not a valid open file descriptor.
185.It Bq Er EINVAL
186.Dv MAP_FIXED
187was specified and the
188.I addr
189parameter was not page aligned.
190.Fa fd
191did not reference a regular or character special file.
192.It Bq Er ENOMEM
193.Dv MAP_FIXED
194was specified and the
195.Fa addr
196parameter wasn't available.
197.Dv MAP_ANON
198was specified and insufficient memory was available.
199.El
200.Sh "SEE ALSO"
201.Xr getpagesize 2 ,
202.Xr msync 2 ,
203.Xr munmap 2 ,
204.Xr mprotect 2 ,
205.Xr madvise 2 ,
206.Xr mincore 2 ,
207.Xr mlock 2