Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | .\" Copyright (c) 1991 Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 3. All advertising materials mentioning features or use of this software | |
13 | .\" must display the following acknowledgement: | |
14 | .\" This product includes software developed by the University of | |
15 | .\" California, Berkeley and its contributors. | |
16 | .\" 4. Neither the name of the University nor the names of its contributors | |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" @(#)mmap.2 6.2 (Berkeley) 6/5/91 | |
33 | .\" | |
34 | .Dd "June 5, 1991" | |
35 | .Dt MMAP 2 | |
36 | .Os BSD 4 | |
37 | .Sh NAME | |
38 | .Nm mmap | |
39 | .Nd map files or devices into memory | |
40 | .Sh SYNOPSIS | |
41 | .Fd #include <sys/types.h> | |
42 | .Fd #include <sys/mman.h> | |
43 | .Ft caddr_t | |
44 | .Fn mmap "caddr_t addr" "int len" "int prot" "int flags" "int fd" "off_t offset" | |
45 | .Sh DESCRIPTION | |
46 | The | |
47 | .Nm mmap | |
48 | function causes the pages starting at | |
49 | .Fa addr | |
50 | and continuing for at most | |
51 | .Fa len | |
52 | bytes to be mapped from the object described by | |
53 | .Fa fd , | |
54 | starting at byte offset | |
55 | .Fa offset . | |
56 | If | |
57 | .Fa offset | |
58 | or | |
59 | .Fa len | |
60 | is not a multiple of the pagesize, the mapped region may extend past the | |
61 | specified range. | |
62 | .Pp | |
63 | If | |
64 | .Fa addr | |
65 | is non-zero, it is used as a hint to the system. | |
66 | (As a convenience to the system, the actual address of the region may differ | |
67 | from the address supplied.) | |
68 | If | |
69 | .Fa addr | |
70 | is zero, an address will be selected by the system. | |
71 | The actual starting address of the region is returned. | |
72 | A successful | |
73 | .Fa mmap | |
74 | deletes any previous mapping in the allocated address range. | |
75 | .Pp | |
76 | The protections (region accessibility) are specified in the | |
77 | .Fa prot | |
78 | argument by | |
79 | .Em or Ap ing | |
80 | the following values: | |
81 | .Pp | |
82 | .Bl -tag -width MAP_FIXEDX | |
83 | .It Dv PROT_EXEC | |
84 | Pages may be executed. | |
85 | .It Dv PROT_READ | |
86 | Pages may be read. | |
87 | .It Dv PROT_WRITE | |
88 | Pages may be written. | |
89 | .El | |
90 | .Pp | |
91 | The | |
92 | .Fa flags | |
93 | parameter specifies the type of the mapped object, mapping options and | |
94 | whether modifications made to the mapped copy of the page are private | |
95 | to the process or are to be shared with other references. | |
96 | Sharing, mapping type and options are specified in the | |
97 | .Fa flags | |
98 | argument by | |
99 | .Em or Ap ing | |
100 | the following values: | |
101 | .Pp | |
102 | .Bl -tag -width MAP_FIXEDX | |
103 | .It Dv MAP_ANON | |
104 | Map anonymous memory not associated with any specific file. | |
105 | The file descriptor used for creating MAP_ANON regions is used only for | |
106 | naming, and may be specified as \-1 if no name is associated with the | |
107 | region. | |
108 | .It Dv MAP_FILE | |
109 | Mapped from a regular file or character-special device memory. | |
110 | .It Dv MAP_FIXED | |
111 | Do not permit the system to select a different address than the one | |
112 | specified. | |
113 | If the specified address cannot be used, | |
114 | .Nm mmap | |
115 | will fail. | |
116 | If MAP_FIXED is specified, | |
117 | .Fa addr | |
118 | must be a multiple of the pagesize. | |
119 | Use of this option is discouraged. | |
120 | .It Dv MAP_HASSEMAPHORE | |
121 | Notify the kernel that the region may contain semaphores and that special | |
122 | handling may be necessary. | |
123 | .It Dv MAP_INHERIT | |
124 | Permit regions to be inherited across | |
125 | .Xr exec 2 | |
126 | system calls. | |
127 | .It Dv MAP_PRIVATE | |
128 | Modifications are private. | |
129 | .It Dv MAP_SHARED | |
130 | Modifications are shared. | |
131 | .El | |
132 | .Pp | |
133 | The | |
134 | .Xr close 2 | |
135 | function does not unmap pages, see | |
136 | .Xr munmap 2 | |
137 | for further information. | |
138 | .Pp | |
139 | The current design does not allow a process to specify the location of | |
140 | swap space. | |
141 | In the future we may define an additional mapping type, MAP_SWAP, in which | |
142 | the file descriptor argument specifies a file or device to which swapping | |
143 | should be done. | |
144 | .Sh RETURN VALUES | |
145 | Upon successful completion, | |
146 | .Nm mmap | |
147 | returns a pointer to the mapped region. | |
148 | Otherwise, a value of -1 is returned and | |
149 | .Va errno | |
150 | is set to indicate the error. | |
151 | .Sh ERRORS | |
152 | .Fn Mmap | |
153 | will fail if: | |
154 | .Bl -tag -width Er | |
155 | .It Bq Er EACCES | |
156 | The flag PROT_READ was specified as part of the | |
157 | .Fa prot | |
158 | parameter and | |
159 | .Fa fd | |
160 | was not open for reading. | |
161 | The flags PROT_WRITE, MAP_SHARED and MAP_WRITE were specified as part | |
162 | of the | |
163 | .Fa flags | |
164 | and | |
165 | .Fa prot | |
166 | parameters and | |
167 | .Fa fd | |
168 | was not open for writing. | |
169 | .It Bq Er EBADF | |
170 | .Fa Fd | |
171 | is not a valid open file descriptor. | |
172 | .It Bq Er EINVAL | |
173 | One of MAP_ANON or MAP_FILE was not specified as part of the | |
174 | .Fa flags | |
175 | parameter. | |
176 | MAP_FIXED was specified and the | |
177 | .I addr | |
178 | parameter was not page aligned. | |
179 | .Fa Fd | |
180 | did not reference a regular or character special file. | |
181 | .It Bq Er ENOMEM | |
182 | MAP_FIXED was specified and the | |
183 | .Fa addr | |
184 | parameter wasn't available. | |
185 | MAP_ANON was specified an insufficient memory was available. | |
186 | .Sh "SEE ALSO" | |
187 | .Xr getpagesize 2 , | |
188 | .Xr msync 2 , | |
189 | .Xr munmap 2 , | |
190 | .Xr mprotect 2 , | |
191 | .Xr madvise 2 , | |
192 | .Xr mincore 2 |