Print this page
12010 extra whitespace in mmap(2)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man2/mmap.2
+++ new/usr/src/man/man2/mmap.2
1 1 .\"
2 2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 3 .\" permission to reproduce portions of its copyrighted documentation.
4 4 .\" Original documentation from The Open Group can be obtained online at
5 5 .\" http://www.opengroup.org/bookstore/.
6 6 .\"
7 7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 8 .\" Group, have given us permission to reprint portions of their
9 9 .\" documentation.
10 10 .\"
11 11 .\" In the following statement, the phrase ``this text'' refers to portions
12 12 .\" of the system documentation.
13 13 .\"
14 14 .\" Portions of this text are reprinted and reproduced in electronic form
15 15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 16 .\" Standard for Information Technology -- Portable Operating System
17 17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 20 .\" between these versions and the original IEEE and The Open Group
21 21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 22 .\" document. The original Standard can be obtained online at
23 23 .\" http://www.opengroup.org/unix/online.html.
24 24 .\"
25 25 .\" This notice shall appear on any product containing this material.
26 26 .\"
27 27 .\" The contents of this file are subject to the terms of the
28 28 .\" Common Development and Distribution License (the "License").
29 29 .\" You may not use this file except in compliance with the License.
30 30 .\"
31 31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 32 .\" or http://www.opensolaris.org/os/licensing.
33 33 .\" See the License for the specific language governing permissions
34 34 .\" and limitations under the License.
35 35 .\"
36 36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
38 38 .\" If applicable, add the following below this CDDL HEADER, with the
39 39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 41 .\"
42 42 .\"
43 43 .\" Copyright 1989 AT&T
44 44 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
45 45 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
46 46 .\" Copyright 2013 OmniTI Computer Consulting, Inc. All Rights Reserved.
47 47 .\" Copyright 2016 James S Blachly, MD. All Rights Reserved.
48 +.\" Copyright 2019 Joyent, Inc.
48 49 .\"
49 -.TH MMAP 2 "August 29, 2016"
50 +.TH MMAP 2 "Nov 19, 2019"
50 51 .SH NAME
51 52 mmap \- map pages of memory
52 53 .SH SYNOPSIS
53 -.LP
54 54 .nf
55 55 #include <sys/mman.h>
56 56
57 57 \fBvoid *\fR\fBmmap\fR(\fBvoid *\fR\fIaddr\fR, \fBsize_t\fR \fIlen\fR, \fBint\fR \fIprot\fR, \fBint\fR \fIflags\fR,
58 58 \fBint\fR \fIfildes\fR, \fBoff_t\fR \fIoff\fR);
59 59 .fi
60 60
61 61 .SH DESCRIPTION
62 -.LP
63 62 The \fBmmap()\fR function establishes a mapping between a process's address
64 63 space and a file or shared memory object. The format of the call is as follows:
65 64 .sp
66 65 .LP
67 66 \fIpa\fR = \fBmmap(\fR\fIaddr\fR\fB, \fR\fIlen\fR\fB, \fR\fIprot\fR\fB,
68 67 \fR\fIflags\fR\fB, \fR\fIfildes\fR\fB, \fR\fIoff\fR\fB);\fR
69 68 .sp
70 69 .LP
71 70 The \fBmmap()\fR function establishes a mapping between the address space of
72 71 the process at an address \fIpa\fR for \fIlen\fR bytes to the memory object
73 72 represented by the file descriptor \fIfildes\fR at offset \fIoff\fR for
74 -\fIlen\fR bytes. The value of \fIpa\fR is a function of the \fIaddr\fR
73 +\fIlen\fR bytes. The value of \fIpa\fR is a function of the \fIaddr\fR
75 74 argument and values of \fIflags\fR, further described below. A successful
76 75 \fBmmap()\fR call returns \fIpa\fR as its result. The address range starting at
77 76 \fIpa\fR and continuing for \fIlen\fR bytes will be legitimate for the possible
78 77 (not necessarily current) address space of the process. The range of bytes
79 78 starting at \fIoff\fR and continuing for \fIlen\fR bytes will be legitimate for
80 79 the possible (not necessarily current) offsets in the file or shared memory
81 80 object represented by \fIfildes\fR.
82 81 .sp
83 82 .LP
84 83 The \fBmmap()\fR function allows [\fIpa, pa + len\fR) to extend beyond the end
85 84 of the object both at the time of the \fBmmap()\fR and while the mapping
86 85 persists, such as when the file is created prior to the \fBmmap()\fR call and
87 86 has no contents, or when the file is truncated. Any reference to addresses
88 87 beyond the end of the object, however, will result in the delivery of a
89 88 \fBSIGBUS\fR or \fBSIGSEGV\fR signal. The \fBmmap()\fR function cannot be used
90 89 to implicitly extend the length of files.
91 90 .sp
92 91 .LP
93 92 The mapping established by \fBmmap()\fR replaces any previous mappings for
94 93 those whole pages containing any part of the address space of the process
95 94 starting at \fIpa\fR and continuing for \fIlen\fR bytes.
96 95 .sp
97 96 .LP
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
98 97 If the size of the mapped file changes after the call to \fBmmap()\fR as a
99 98 result of some other operation on the mapped file, the effect of references to
100 99 portions of the mapped region that correspond to added or removed portions of
101 100 the file is unspecified.
102 101 .sp
103 102 .LP
104 103 The \fBmmap()\fR function is supported for regular files and shared memory
105 104 objects. Support for any other type of file is unspecified.
106 105 .sp
107 106 .LP
108 -The \fIprot\fR argument determines whether read, write, execute, or some
107 +The \fIprot\fR argument determines whether read, write, execute, or some
109 108 combination of accesses are permitted to the data being mapped. The \fIprot\fR
110 109 argument should be either \fBPROT_NONE\fR or the bitwise inclusive \fBOR\fR of
111 110 one or more of the other flags in the following table, defined in the header
112 111 <\fBsys/mman.h\fR>.
113 112 .sp
114 113 .ne 2
115 114 .na
116 115 \fB\fBPROT_READ\fR\fR
117 116 .ad
118 117 .RS 14n
119 118 Data can be read.
120 119 .RE
121 120
122 121 .sp
123 122 .ne 2
124 123 .na
125 124 \fB\fBPROT_WRITE\fR\fR
126 125 .ad
127 126 .RS 14n
128 127 Data can be written.
129 128 .RE
130 129
131 130 .sp
132 131 .ne 2
133 132 .na
134 133 \fB\fBPROT_EXEC\fR\fR
135 134 .ad
136 135 .RS 14n
137 136 Data can be executed.
138 137 .RE
139 138
140 139 .sp
141 140 .ne 2
142 141 .na
143 142 \fB\fBPROT_NONE\fR\fR
144 143 .ad
145 144 .RS 14n
146 145 Data cannot be accessed.
147 146 .RE
148 147
149 148 .sp
150 149 .LP
151 150 If an implementation of \fBmmap()\fR for a specific platform cannot support the
152 151 combination of access types specified by \fIprot\fR, the call to \fBmmap()\fR
153 152 fails. An implementation may permit accesses other than those specified by
154 153 \fIprot\fR; however, the implementation will not permit a write to succeed
155 154 where \fBPROT_WRITE\fR has not been set or permit any access where
156 155 \fBPROT_NONE\fR alone has been set. Each platform-specific implementation of
157 156 \fBmmap()\fR supports the following values of \fIprot\fR: \fBPROT_NONE\fR,
↓ open down ↓ |
39 lines elided |
↑ open up ↑ |
158 157 \fBPROT_READ\fR, \fBPROT_WRITE\fR, and the inclusive \fBOR\fR of
159 158 \fBPROT_READ\fR and \fBPROT_WRITE\fR. On some platforms, the \fBPROT_WRITE\fR
160 159 protection option is implemented as \fBPROT_READ|PROT_WRITE\fR and
161 160 \fBPROT_EXEC\fR as \fBPROT_READ|PROT_EXEC\fR. The file descriptor \fIfildes\fR
162 161 is opened with read permission, regardless of the protection options specified.
163 162 If \fBPROT_WRITE\fR is specified, the application must have opened the file
164 163 descriptor \fIfildes\fR with write permission unless \fBMAP_PRIVATE\fR is
165 164 specified in the \fIflags\fR argument as described below.
166 165 .sp
167 166 .LP
168 -The \fIflags\fR argument provides other information about the handling of the
167 +The \fIflags\fR argument provides other information about the handling of the
169 168 mapped data. The value of \fIflags\fR is the bitwise inclusive \fBOR\fR of
170 169 these options, defined in <\fBsys/mman.h\fR>:
171 170 .sp
172 171 .ne 2
173 172 .na
174 173 \fB\fBMAP_SHARED\fR\fR
175 174 .ad
176 175 .RS 17n
177 176 Changes are shared.
178 177 .RE
179 178
180 179 .sp
181 180 .ne 2
182 181 .na
183 182 \fB\fBMAP_PRIVATE\fR\fR
184 183 .ad
185 184 .RS 17n
186 185 Changes are private.
187 186 .RE
188 187
189 188 .sp
190 189 .ne 2
191 190 .na
192 191 \fB\fBMAP_FIXED\fR\fR
193 192 .ad
194 193 .RS 17n
195 194 Interpret \fIaddr\fR exactly.
196 195 .RE
197 196
198 197 .sp
199 198 .ne 2
200 199 .na
201 200 \fB\fBMAP_NORESERVE\fR\fR
202 201 .ad
203 202 .RS 17n
204 203 Do not reserve swap space.
205 204 .RE
206 205
207 206 .sp
208 207 .ne 2
209 208 .na
210 209 \fB\fBMAP_ANON\fR\fR
211 210 .ad
212 211 .RS 17n
213 212 Map anonymous memory.
214 213 .RE
215 214
216 215 .sp
217 216 .ne 2
218 217 .na
219 218 \fB\fBMAP_ALIGN\fR\fR
220 219 .ad
221 220 .RS 17n
222 221 Interpret \fIaddr\fR as required alignment.
223 222 .RE
224 223
225 224 .sp
226 225 .ne 2
227 226 .na
228 227 \fB\fBMAP_TEXT\fR\fR
229 228 .ad
230 229 .RS 17n
231 230 Map text.
232 231 .RE
233 232
234 233 .sp
235 234 .ne 2
236 235 .na
237 236 \fB\fBMAP_INITDATA\fR\fR
238 237 .ad
239 238 .RS 17n
240 239 Map initialized data segment.
241 240 .RE
242 241
243 242 .sp
244 243 .ne 2
245 244 .na
246 245 \fB\fBMAP_32BIT\fR\fR
247 246 .ad
248 247 .RS 17n
249 248 Map to the lower 32 bits of address space.
250 249 .RE
251 250
252 251 .sp
253 252 .ne 2
254 253 .na
255 254 \fB\fBMAP_FILE\fR\fR
256 255 .ad
257 256 .RS 17n
258 257 Map a regular file. This is the default behavior;
259 258 specifying this flag is not required. It is provided
260 259 for compatibility with other systems and should not be
261 260 included in new code.
262 261 .RE
263 262
264 263 .sp
265 264 .LP
266 265 The \fBMAP_SHARED\fR and \fBMAP_PRIVATE\fR options describe the disposition of
267 266 write references to the underlying object. If \fBMAP_SHARED\fR is specified,
268 267 write references will change the memory object. If \fBMAP_PRIVATE\fR is
269 268 specified, the initial write reference will create a private copy of the memory
270 269 object page and redirect the mapping to the copy. The private copy is not
271 270 created until the first write; until then, other users who have the object
272 271 mapped \fBMAP_SHARED\fR can change the object. Either \fBMAP_SHARED\fR or
273 272 \fBMAP_PRIVATE\fR must be specified, but not both. The mapping type is retained
274 273 across \fBfork\fR(2).
275 274 .sp
276 275 .LP
277 276 When \fBMAP_FIXED\fR is set in the \fIflags\fR argument, the system is informed
278 277 that the value of \fIpa\fR must be \fIaddr\fR, exactly. If \fBMAP_FIXED\fR is
279 278 set, \fBmmap()\fR may return (\fBvoid *\fR)\(mi1 and set \fBerrno\fR to
280 279 \fBEINVAL\fR. If a \fBMAP_FIXED\fR request is successful, the mapping
281 280 established by \fBmmap()\fR replaces any previous mappings for the process's
282 281 pages in the range [\fIpa, pa + len\fR). The use of \fBMAP_FIXED\fR is
283 282 discouraged, since it may prevent a system from making the most effective use
284 283 of its resources.
285 284 .sp
286 285 .LP
287 286 When \fBMAP_FIXED\fR is set and the requested address is the same as previous
288 287 mapping, the previous address is unmapped and the new mapping is created on top
289 288 of the old one.
290 289 .sp
291 290 .LP
292 291 When \fBMAP_FIXED\fR is not set, the system uses \fIaddr\fR to arrive at
293 292 \fIpa\fR. The \fIpa\fR so chosen will be an area of the address space that the
294 293 system deems suitable for a mapping of \fIlen\fR bytes to the file. The
295 294 \fBmmap()\fR function interprets an \fIaddr\fR value of 0 as granting the
296 295 system complete freedom in selecting \fIpa\fR, subject to constraints described
↓ open down ↓ |
118 lines elided |
↑ open up ↑ |
297 296 below. A non-zero value of \fIaddr\fR is taken to be a suggestion of a process
298 297 address near which the mapping should be placed. When the system selects a
299 298 value for \fIpa\fR, it will never place a mapping at address 0, nor will it
300 299 replace any extant mapping, nor map into areas considered part of the potential
301 300 data or stack "segments".
302 301 .sp
303 302 .LP
304 303 When \fBMAP_ALIGN\fR is set, the system is informed that the alignment of
305 304 \fIpa\fR must be the same as \fIaddr\fR. The alignment value in \fIaddr\fR must
306 305 be 0 or some power of two multiple of page size as returned by
307 -\fBsysconf\fR(3C). If addr is 0, the system will choose a suitable alignment.
306 +\fBsysconf\fR(3C). If addr is 0, the system will choose a suitable alignment.
308 307 .sp
309 308 .LP
310 309 The \fBMAP_NORESERVE\fR option specifies that no swap space be reserved for a
311 310 mapping. Without this flag, the creation of a writable \fBMAP_PRIVATE\fR
312 311 mapping reserves swap space equal to the size of the mapping; when the mapping
313 312 is written into, the reserved space is employed to hold private copies of the
314 313 data. A write into a \fBMAP_NORESERVE\fR mapping produces results which depend
315 -on the current availability of swap space in the system. If space is
316 -available, the write succeeds and a private copy of the written page is
314 +on the current availability of swap space in the system. If space is
315 +available, the write succeeds and a private copy of the written page is
317 316 created; if space is not available, the write fails and a \fBSIGBUS\fR or
318 317 \fBSIGSEGV\fR signal is delivered to the writing process. \fBMAP_NORESERVE\fR
319 -mappings are inherited across \fBfork()\fR; at the time of the \fBfork()\fR,
318 +mappings are inherited across \fBfork()\fR; at the time of the \fBfork()\fR,
320 319 swap space is reserved in the child for all private pages that currently exist
321 320 in the parent; thereafter the child's mapping behaves as described above.
322 321 .sp
323 322 .LP
324 323 When \fBMAP_ANON\fR is set in \fIflags\fR, and \fIfildes\fR is set to -1,
325 324 \fBmmap()\fR provides a direct path to return anonymous pages to the caller.
326 325 This operation is equivalent to passing \fBmmap()\fR an open file descriptor on
327 326 \fB/dev/zero\fR with \fBMAP_ANON\fR elided from the \fIflags\fR argument.
328 327 .sp
329 328 .LP
330 329 The \fBMAP_TEXT\fR option informs the system that the mapped region will be
331 330 used primarily for executing instructions. This information can help the system
332 331 better utilize MMU resources on some platforms. This flag is always passed by
333 332 the dynamic linker when it maps text segments of shared objects. When the
334 333 \fBMAP_TEXT\fR option is used for regular file mappings on some platforms, the
335 334 system can choose a mapping size larger than the page size returned by
336 335 \fBsysconf\fR(3C). The specific page sizes that are used depend on the platform
337 336 and the alignment of the addr and len arguments. Several different mapping sizes
338 337 can be used to map the region with larger page sizes used in the parts of the
339 338 region that meet alignment and size requirements for those page sizes.
340 339 .sp
341 340 .LP
342 341 The \fBMAP_INITDATA\fR option informs the system that the mapped region is an
343 342 initialized data segment of an executable or shared object. When the
344 343 \fBMAP_INITDATA\fR option is used for regular file mappings on some platforms,
345 344 the system can choose a mapping size larger than the page size returned by
346 345 \fBsysconf()\fR. The \fBMAP_INITDATA\fR option should be used only by the
347 346 dynamic linker for mapping initialized data of shared objects.
348 347 .sp
349 348 .LP
350 349 The \fBMAP_32BIT\fR option informs the system that the search space for
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
351 350 mapping assignment should be limited to the first 32 bits (4 Gbytes) of the
352 351 caller's address space. This flag is accepted in both 32-bit and 64-bit
353 352 process models, but does not alter the mapping strategy when used in a
354 353 32-bit process model.
355 354 .sp
356 355 .LP
357 356 The \fIoff\fR argument is constrained to be aligned and sized according to the
358 357 value returned by \fBsysconf()\fR when passed \fB_SC_PAGESIZE\fR or
359 358 \fB_SC_PAGE_SIZE\fR. When \fBMAP_FIXED\fR is specified, the \fIaddr\fR argument
360 359 must also meet these constraints. The system performs mapping operations over
361 -whole pages. Thus, while the \fIlen\fR argument need not meet a size or
360 +whole pages. Thus, while the \fIlen\fR argument need not meet a size or
362 361 alignment constraint, the system will include, in any mapping operation, any
363 362 partial page specified by the range [\fIpa, pa + len\fR).
364 363 .sp
365 364 .LP
366 365 The system will always zero-fill any partial page at the end of an object.
367 366 Further, the system will never write out any modified portions of the last page
368 367 of an object which are beyond its end. References to whole pages following the
369 368 end of an object will result in the delivery of a \fBSIGBUS\fR or \fBSIGSEGV\fR
370 369 signal. \fBSIGBUS\fR signals may also be delivered on various file system
371 370 conditions, including quota exceeded errors.
372 371 .sp
373 372 .LP
374 373 The \fBmmap()\fR function adds an extra reference to the file associated with
375 374 the file descriptor \fIfildes\fR which is not removed by a subsequent
376 375 \fBclose\fR(2) on that file descriptor. This reference is removed when there
377 376 are no more mappings to the file by a call to the \fBmunmap\fR(2) function.
378 377 .sp
379 378 .LP
380 379 The \fBst_atime\fR field of the mapped file may be marked for update at any
381 380 time between the \fBmmap()\fR call and the corresponding \fBmunmap\fR(2) call.
382 381 The initial read or write reference to a mapped region will cause the file's
383 382 \fBst_atime\fR field to be marked for update if it has not already been marked
384 383 for update.
385 384 .sp
386 385 .LP
387 386 The \fBst_ctime\fR and \fBst_mtime\fR fields of a file that is mapped with
388 387 \fBMAP_SHARED\fR and \fBPROT_WRITE\fR, will be marked for update at some point
389 388 in the interval between a write reference to the mapped region and the next
390 389 call to \fBmsync\fR(3C) with \fBMS_ASYNC\fR or \fBMS_SYNC\fR for that portion
391 390 of the file by any process. If there is no such call, these fields may be
392 391 marked for update at any time after a write reference if the underlying file is
393 392 modified as a result.
394 393 .sp
395 394 .LP
396 395 If the process calls \fBmlockall\fR(3C) with the \fBMCL_FUTURE\fR flag, the
397 396 pages mapped by all future calls to \fBmmap()\fR will be locked in memory. In
398 397 this case, if not enough memory could be locked, \fBmmap()\fR fails and sets
399 398 \fBerrno\fR to \fBEAGAIN\fR.
400 399 .sp
401 400 .LP
402 401 The \fBmmap()\fR function aligns based on the length of the mapping. When
403 402 determining the amount of space to add to the address space, \fBmmap()\fR
404 403 includes two 8-Kbyte pages, one at each end of the mapping that are not mapped
405 404 and are therefore used as "red-zone" pages. Attempts to reference these pages
406 405 result in access violations.
407 406 .sp
408 407 .LP
409 408 The size requested is incremented by the 16 Kbytes for these pages and is then
410 409 subject to rounding constraints. The constraints are:
411 410 .RS +4
412 411 .TP
413 412 .ie t \(bu
414 413 .el o
415 414 For 32-bit processes:
416 415 .sp
417 416 .in +2
418 417 .nf
419 418 If length > 4 Mbytes
420 419 round to 4-Mbyte multiple
421 420 elseif length > 512 Kbytes
422 421 round to 512-Kbyte multiple
423 422 else
424 423 round to 64-Kbyte multiple
425 424 .fi
426 425 .in -2
427 426
428 427 .RE
429 428 .RS +4
430 429 .TP
431 430 .ie t \(bu
432 431 .el o
433 432 For 64-bit processes:
434 433 .sp
435 434 .in +2
436 435 .nf
437 436 If length > 4 Mbytes
438 437 round to 4-Mbyte multiple
439 438 else
440 439 round to 1-Mbyte multiple
441 440 .fi
442 441 .in -2
443 442
444 443 .RE
445 444 .sp
446 445 .LP
447 446 The net result is that for a 32-bit process:
448 447 .RS +4
449 448 .TP
450 449 .ie t \(bu
451 450 .el o
452 451 If an \fBmmap()\fR request is made for 4 Mbytes, it results in 4 Mbytes + 16
453 452 Kbytes and is rounded up to 8 Mbytes.
454 453 .RE
455 454 .RS +4
456 455 .TP
457 456 .ie t \(bu
458 457 .el o
459 458 If an \fBmmap()\fR request is made for 512 Kbytes, it results in 512 Kbytes +
460 459 16 Kbytes and is rounded up to 1 Mbyte.
461 460 .RE
462 461 .RS +4
463 462 .TP
464 463 .ie t \(bu
465 464 .el o
466 465 If an \fBmmap()\fR request is made for 1 Mbyte, it results in 1 Mbyte + 16
467 466 Kbytes and is rounded up to 1.5 Mbytes.
468 467 .RE
469 468 .RS +4
470 469 .TP
471 470 .ie t \(bu
472 471 .el o
473 472 Each 8-Kbyte mmap request "consumes" 64 Kbytes of virtual address space.
474 473 .RE
475 474 .sp
476 475 .LP
477 476 To obtain maximal address space usage for a 32-bit process:
478 477 .RS +4
479 478 .TP
480 479 .ie t \(bu
481 480 .el o
482 481 Combine 8-Kbyte requests up to a limit of 48 Kbytes.
483 482 .RE
484 483 .RS +4
485 484 .TP
486 485 .ie t \(bu
487 486 .el o
488 487 Combine amounts over 48 Kbytes into 496-Kbyte chunks.
489 488 .RE
490 489 .RS +4
491 490 .TP
492 491 .ie t \(bu
493 492 .el o
494 493 Combine amounts over 496 Kbytes into 4080-Kbyte chunks.
495 494 .RE
496 495 .sp
497 496 .LP
498 497 To obtain maximal address space usage for a 64-bit process:
499 498 .RS +4
500 499 .TP
501 500 .ie t \(bu
502 501 .el o
503 502 Combine amounts < 1008 Kbytes into chunks <= 1008 Kbytes.
504 503 .RE
505 504 .RS +4
506 505 .TP
507 506 .ie t \(bu
508 507 .el o
509 508 Combine amounts over 1008 Kbytes into 4080-Kbyte chunks.
510 509 .RE
511 510 .sp
512 511 .LP
513 512 The following is the output from a 32-bit program demonstrating this:
514 513 .sp
515 514 .ne 2
516 515 .na
517 516 \fBmap 8192 bytes: \fB0xff390000\fR\fR
518 517 .ad
519 518 .br
520 519 .na
521 520 \fBmap 8192 bytes: \fB0xff380000\fR\fR
522 521 .ad
523 522 .sp .6
524 523 .RS 4n
525 524 64-Kbyte delta between starting addresses.
526 525 .RE
527 526
528 527 .sp
529 528 .ne 2
530 529 .na
531 530 \fBmap 512 Kbytes: \fB0xff180000\fR\fR
532 531 .ad
533 532 .br
534 533 .na
535 534 \fBmap 512 Kbytes: \fB0xff080000\fR\fR
536 535 .ad
537 536 .sp .6
538 537 .RS 4n
539 538 1-Mbyte delta between starting addresses.
540 539 .RE
541 540
542 541 .sp
543 542 .ne 2
544 543 .na
545 544 \fBmap 496 Kbytes: \fB0xff000000\fR\fR
546 545 .ad
547 546 .br
548 547 .na
549 548 \fBmap 496 Kbytes: \fB0xfef80000\fR\fR
550 549 .ad
551 550 .sp .6
552 551 .RS 4n
553 552 512-Kbyte delta between starting addresses
554 553 .RE
555 554
556 555 .sp
557 556 .ne 2
558 557 .na
559 558 \fBmap 1 Mbyte: \fB0xfee00000\fR\fR
560 559 .ad
561 560 .br
562 561 .na
563 562 \fBmap 1 Mbyte: \fB0xfec80000\fR\fR
564 563 .ad
565 564 .sp .6
566 565 .RS 4n
567 566 1536-Kbyte delta between starting addresses
568 567 .RE
569 568
570 569 .sp
571 570 .ne 2
572 571 .na
573 572 \fBmap 1008 Kbytes: \fB0xfeb80000\fR\fR
574 573 .ad
575 574 .br
576 575 .na
577 576 \fBmap 1008 Kbytes: \fB0xfea80000\fR\fR
578 577 .ad
579 578 .sp .6
580 579 .RS 4n
581 580 1-Mbyte delta between starting addresses
582 581 .RE
583 582
584 583 .sp
585 584 .ne 2
586 585 .na
587 586 \fBmap 4 Mbytes: \fB0xfe400000\fR\fR
588 587 .ad
589 588 .br
590 589 .na
591 590 \fBmap 4 Mbytes: \fB0xfdc00000\fR\fR
592 591 .ad
593 592 .sp .6
594 593 .RS 4n
595 594 8-Mbyte delta between starting addresses
596 595 .RE
597 596
598 597 .sp
599 598 .ne 2
600 599 .na
601 600 \fBmap 4080 Kbytes: \fB0xfd800000\fR\fR
602 601 .ad
603 602 .br
604 603 .na
605 604 \fBmap 4080 Kbytes: \fB0xfd400000\fR\fR
606 605 .ad
607 606 .sp .6
608 607 .RS 4n
609 608 4-Mbyte delta between starting addresses
610 609 .RE
611 610
612 611 .sp
613 612 .LP
614 613 The following is the output of the same program compiled as a 64-bit
615 614 application:
616 615 .sp
617 616 .ne 2
618 617 .na
619 618 \fBmap 8192 bytes: \fB0xffffffff7f000000\fR\fR
620 619 .ad
621 620 .br
622 621 .na
623 622 \fBmap 8192 bytes: \fB0xffffffff7ef00000\fR\fR
624 623 .ad
625 624 .sp .6
626 625 .RS 4n
627 626 1-Mbyte delta between starting addresses
628 627 .RE
629 628
630 629 .sp
631 630 .ne 2
632 631 .na
633 632 \fBmap 512 Kbytes: \fB0xffffffff7ee00000\fR\fR
634 633 .ad
635 634 .br
636 635 .na
637 636 \fBmap 512 Kbytes: \fB0xffffffff7ed00000\fR\fR
638 637 .ad
639 638 .sp .6
640 639 .RS 4n
641 640 1-Mbyte delta between starting addresses
642 641 .RE
643 642
644 643 .sp
645 644 .ne 2
646 645 .na
647 646 \fBmap 496 Kbytes: \fB0xffffffff7ec00000\fR\fR
648 647 .ad
649 648 .br
650 649 .na
651 650 \fBmap 496 Kbytes: \fB0xffffffff7eb00000\fR\fR
652 651 .ad
653 652 .sp .6
654 653 .RS 4n
655 654 1-Mbyte delta between starting addresses
656 655 .RE
657 656
658 657 .sp
659 658 .ne 2
660 659 .na
661 660 \fBmap 1 Mbyte: \fB0xffffffff7e900000\fR\fR
662 661 .ad
663 662 .br
664 663 .na
665 664 \fBmap 1 Mbyte: \fB0xffffffff7e700000\fR\fR
666 665 .ad
667 666 .sp .6
668 667 .RS 4n
669 668 2-Mbyte delta between starting addresses
670 669 .RE
671 670
672 671 .sp
673 672 .ne 2
674 673 .na
675 674 \fBmap 1008 Kbytes: \fB0xffffffff7e600000\fR\fR
676 675 .ad
677 676 .br
678 677 .na
679 678 \fBmap 1008 Kbytes: \fB0xffffffff7e500000\fR\fR
680 679 .ad
681 680 .sp .6
682 681 .RS 4n
683 682 1-Mbyte delta between starting addresses
684 683 .RE
685 684
686 685 .sp
687 686 .ne 2
688 687 .na
689 688 \fBmap 4 Mbytes: \fB0xffffffff7e000000\fR\fR
690 689 .ad
691 690 .br
692 691 .na
693 692 \fBmap 4 Mbytes: \fB0xffffffff7d800000\fR\fR
694 693 .ad
695 694 .sp .6
696 695 .RS 4n
697 696 8-Mbyte delta between starting addresses
698 697 .RE
699 698
700 699 .sp
701 700 .ne 2
702 701 .na
703 702 \fBmap 4080 Kbytes: \fB0xffffffff7d400000\fR\fR
704 703 .ad
↓ open down ↓ |
333 lines elided |
↑ open up ↑ |
705 704 .br
706 705 .na
707 706 \fBmap 4080 Kbytes: \fB0xffffffff7d000000\fR\fR
708 707 .ad
709 708 .sp .6
710 709 .RS 4n
711 710 4-Mbyte delta between starting addresses
712 711 .RE
713 712
714 713 .SH RETURN VALUES
715 -.LP
716 714 Upon successful completion, the \fBmmap()\fR function returns the address at
717 715 which the mapping was placed (\fIpa\fR); otherwise, it returns a value of
718 716 \fBMAP_FAILED\fR and sets \fBerrno\fR to indicate the error. The symbol
719 717 \fBMAP_FAILED\fR is defined in the header <\fBsys/mman.h\fR>. No successful
720 718 return from \fBmmap()\fR will return the value \fBMAP_FAILED\fR.
721 719 .sp
722 720 .LP
723 721 If \fBmmap()\fR fails for reasons other than \fBEBADF\fR, \fBEINVAL\fR or
724 722 \fBENOTSUP\fR, some of the mappings in the address range starting at \fIaddr\fR
725 723 and continuing for \fIlen\fR bytes may have been unmapped.
726 724 .SH ERRORS
727 -.LP
728 725 The \fBmmap()\fR function will fail if:
729 726 .sp
730 727 .ne 2
731 728 .na
732 729 \fB\fBEACCES\fR\fR
733 730 .ad
734 731 .RS 13n
735 732 The \fIfildes\fR file descriptor is not open for read, regardless of the
736 733 protection specified; or \fIfildes\fR is not open for write and
737 734 \fBPROT_WRITE\fR was specified for a \fBMAP_SHARED\fR type mapping.
738 735 .RE
739 736
740 737 .sp
741 738 .ne 2
742 739 .na
743 740 \fB\fBEAGAIN\fR\fR
744 741 .ad
745 742 .RS 13n
746 743 The mapping could not be locked in memory.
747 744 .sp
748 745 There was insufficient room to reserve swap space for the mapping.
749 746 .RE
750 747
751 748 .sp
752 749 .ne 2
753 750 .na
754 751 \fB\fBEBADF\fR\fR
755 752 .ad
756 753 .RS 13n
757 754 The \fIfildes\fR file descriptor is not open (and \fBMAP_ANON\fR was not
758 755 specified).
759 756 .RE
760 757
761 758 .sp
762 759 .ne 2
763 760 .na
764 761 \fB\fBEINVAL\fR\fR
765 762 .ad
766 763 .RS 13n
767 764 The arguments \fIaddr\fR (if \fBMAP_FIXED\fR was specified) or \fIoff\fR are
768 765 not multiples of the page size as returned by \fBsysconf()\fR.
769 766 .sp
770 767 The argument \fIaddr\fR (if \fBMAP_ALIGN\fR was specified) is not 0 or some
771 768 power of two multiple of page size as returned by \fBsysconf\fR(3C).
772 769 .sp
773 770 \fBMAP_FIXED\fR and \fBMAP_ALIGN\fR are both specified.
774 771 .sp
775 772 The field in \fIflags\fR is invalid (neither \fBMAP_PRIVATE\fR or
776 773 \fBMAP_SHARED\fR is set).
777 774 .sp
778 775 The argument \fIlen\fR has a value equal to 0.
779 776 .sp
780 777 \fBMAP_ANON\fR was specified, but the file descriptor was not \(mi1.
781 778 .sp
782 779 \fBMAP_TEXT\fR was specified but \fBPROT_EXEC\fR was not.
783 780 .sp
784 781 \fBMAP_TEXT\fR and \fBMAP_INITDATA\fR were both specified.
785 782 .RE
786 783
787 784 .sp
788 785 .ne 2
789 786 .na
790 787 \fB\fBEMFILE\fR\fR
791 788 .ad
792 789 .RS 13n
793 790 The number of mapped regions would exceed an implementation-dependent limit
794 791 (per process or per system).
795 792 .RE
796 793
797 794 .sp
798 795 .ne 2
799 796 .na
800 797 \fB\fBENODEV\fR\fR
801 798 .ad
802 799 .RS 13n
803 800 The \fIfildes\fR argument refers to an object for which \fBmmap()\fR is
804 801 meaningless, such as a terminal.
805 802 .RE
806 803
807 804 .sp
808 805 .ne 2
809 806 .na
810 807 \fB\fBENOMEM\fR\fR
811 808 .ad
812 809 .RS 13n
↓ open down ↓ |
75 lines elided |
↑ open up ↑ |
813 810 The \fBMAP_FIXED\fR option was specified and the range [\fIaddr, addr + len\fR)
814 811 exceeds that allowed for the address space of a process.
815 812 .sp
816 813 The \fBMAP_FIXED\fR option was \fInot\fR specified and there is insufficient
817 814 room in the address space to effect the mapping.
818 815 .sp
819 816 The mapping could not be locked in memory, if required by \fBmlockall\fR(3C),
820 817 because it would require more space than the system is able to supply.
821 818 .sp
822 819 The composite size of \fIlen\fR plus the lengths obtained from all previous
823 -calls to \fBmmap()\fR exceeds \fBRLIMIT_VMEM\fR (see \fBgetrlimit\fR(2)).
820 +calls to \fBmmap()\fR exceeds \fBRLIMIT_VMEM\fR (see \fBgetrlimit\fR(2)).
824 821 .RE
825 822
826 823 .sp
827 824 .ne 2
828 825 .na
829 826 \fB\fBENOTSUP\fR\fR
830 827 .ad
831 828 .RS 13n
832 829 The system does not support the combination of accesses requested in the
833 830 \fIprot\fR argument.
834 831 .RE
835 832
836 833 .sp
837 834 .ne 2
838 835 .na
839 836 \fB\fBENXIO\fR\fR
840 837 .ad
841 838 .RS 13n
842 839 Addresses in the range [\fIoff, off + len\fR) are invalid for the object
843 840 specified by \fIfildes\fR.
844 841 .sp
845 842 The \fBMAP_FIXED\fR option was specified in \fIflags\fR and the combination of
846 843 \fIaddr\fR, \fIlen\fR and \fIoff\fR is invalid for the object specified by
847 844 \fIfildes\fR.
848 845 .RE
849 846
850 847 .sp
851 848 .ne 2
852 849 .na
853 850 \fB\fBEOVERFLOW\fR\fR
854 851 .ad
855 852 .RS 13n
856 853 The file is a regular file and the value of \fIoff\fR plus \fIlen\fR exceeds
857 854 the offset maximum establish in the open file description associated with
858 855 \fIfildes\fR.
859 856 .RE
860 857
861 858 .sp
862 859 .LP
863 860 The \fBmmap()\fR function may fail if:
864 861 .sp
↓ open down ↓ |
31 lines elided |
↑ open up ↑ |
865 862 .ne 2
866 863 .na
867 864 \fB\fBEAGAIN\fR\fR
868 865 .ad
869 866 .RS 10n
870 867 The file to be mapped is already locked using advisory or mandatory record
871 868 locking. See \fBfcntl\fR(2).
872 869 .RE
873 870
874 871 .SH USAGE
875 -.LP
876 872 Use of \fBmmap()\fR may reduce the amount of memory available to other memory
877 873 allocation functions.
878 874 .sp
879 875 .LP
880 876 \fBMAP_ALIGN\fR is useful to assure a properly aligned value of \fIpa\fR for
881 877 subsequent use with \fBmemcntl\fR(2) and the \fBMC_HAT_ADVISE\fR command. This
882 878 is best used for large, long-lived, and heavily referenced regions.
883 879 \fBMAP_FIXED\fR and \fBMAP_ALIGN\fR are always mutually-exclusive.
884 880 .sp
885 881 .LP
886 882 Use of \fBMAP_FIXED\fR may result in unspecified behavior in further use of
887 883 \fBbrk\fR(2), \fBsbrk\fR(2), \fBmalloc\fR(3C), and \fBshmat\fR(2). The use of
888 884 \fBMAP_FIXED\fR is discouraged, as it may prevent an implementation from making
889 885 the most effective use of resources.
890 886 .sp
891 887 .LP
892 888 The application must ensure correct synchronization when using \fBmmap()\fR in
893 889 conjunction with any other file access method, such as \fBread\fR(2) and
894 890 \fBwrite\fR(2), standard input/output, and \fBshmat\fR(2).
895 891 .sp
896 892 .LP
897 893 The \fBmmap()\fR function has a transitional interface for 64-bit file offsets.
898 894 See \fBlf64\fR(5).
899 895 .sp
900 896 .LP
901 897 The \fBmmap()\fR function allows access to resources using address space
902 898 manipulations instead of the \fBread()\fR/\fBwrite()\fR interface. Once a file
903 899 is mapped, all a process has to do to access it is use the data at the address
904 900 to which the object was mapped.
905 901 .sp
906 902 .LP
907 903 Consider the following pseudo-code:
908 904 .sp
909 905 .in +2
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
910 906 .nf
911 907 fildes = open(\|.\|.\|.)
912 908 lseek(fildes, offset, whence)
913 909 read(fildes, buf, len)
914 910 /* use data in buf */
915 911 .fi
916 912 .in -2
917 913
918 914 .sp
919 915 .LP
920 -The following is a rewrite using \fBmmap()\fR:
916 +The following is a rewrite using \fBmmap()\fR:
921 917 .sp
922 918 .in +2
923 919 .nf
924 920 fildes = open(\|.\|.\|.)
925 921 address = mmap((caddr_t) 0, len, (PROT_READ | PROT_WRITE),
926 922 MAP_PRIVATE, fildes, offset)
927 923 /* use data at address */
928 924 .fi
929 925 .in -2
930 926
931 927 .SH ATTRIBUTES
932 -.LP
933 928 See \fBattributes\fR(5) for descriptions of the following attributes:
934 929 .sp
935 930
936 931 .sp
937 932 .TS
938 933 box;
939 934 c | c
940 935 l | l .
941 936 ATTRIBUTE TYPE ATTRIBUTE VALUE
942 937 _
943 938 Interface Stability Standard
944 939 _
945 940 MT-Level Async-Signal-Safe
946 941 .TE
947 942
948 943 .SH SEE ALSO
949 -.LP
950 944 \fBclose\fR(2), \fBexec\fR(2), \fBfcntl\fR(2), \fBfork\fR(2),
951 945 \fBgetrlimit\fR(2), \fBmemcntl\fR(2), \fBmmapobj\fR(2), \fBmprotect\fR(2),
952 946 \fBmunmap\fR(2), \fBshmat\fR(2), \fBlockf\fR(3C), \fBmlockall\fR(3C),
953 947 \fBmsync\fR(3C), \fBplock\fR(3C), \fBsysconf\fR(3C), \fBattributes\fR(5),
954 948 \fBlf64\fR(5), \fBstandards\fR(5), \fBnull\fR(7D), \fBzero\fR(7D)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX