1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Modified Fri Jan 31 16:38:25 1997 by Eric S. Raymond <esr@thyrsus.com>
.\"
.\" Modified Wed Jan 01 01:44:23 1997 by Martin Schulze (joey@linux.de)
.\"
.TH MMAP 2 "12 April 1996" "Linux 1.3.86" "Linux Programmer's Manual"
.SH NAME
mmap, munmap \- map or unmap files or devices into memory
.SH SYNOPSIS
.B #include <unistd.h>
.br
.B #include <sys/mman.h>
.sp
.BI "caddr_t mmap(void *" start ", size_t " length ", int " prot
.BI ", int " flags ", int " fd ", off_t " offset );
.sp
.BI "int munmap(void *" start ", size_t " length );
.SH DESCRIPTION
The
.B mmap
function asks to map
.I length
bytes starting at offset
.I offset
from the file (or other object) specified by
.I fd
into memory, preferably at address
.IR start .
This latter address is a hint only, and is usually specified as 0.
The actual place where the object is mapped is returned by
.BR mmap .
The
.I prot
argument describes the desired memory protection. It has bits
.TP 1.1i
.B PROT_EXEC
Pages may be executed.
.TP
.B PROT_READ
Pages may be read.
.TP
.B PROT_WRITE
Pages may be written.
.TP
.B PROT_NONE
Pages may not be accessed.
.LP
The
.I flags
parameter specifies the type of the mapped object, mapping options and
whether modifications made to the mapped copy of the page are private to
the process or are to be shared with other references. It has bits
.TP 1.1i
.B MAP_FIXED
Do not select a different address than the one specified.
If the specified address cannot be used,
.B mmap
will fail. If MAP_FIXED is specified,
.I start
must be a multiple of the pagesize. Use of this option is discouraged.
.TP
.B MAP_SHARED
Share this mapping with all other processes that map this object
.TP
.B MAP_PRIVATE
Create a private copy-on-write mapping.
.LP
You must specify exactly one of MAP_SHARED and MAP_PRIVATE.
.LP
The above three flags are described in POSIX.1b (formerly POSIX.4).
Linux also knows about MAP_DENYWRITE, MAP_EXECUTABLE and
MAP_ANON(YMOUS).
The
.B munmap
system call deletes the mappings for the specified address range, and
causes further references to addresses within the range to generate invalid
memory references.
.SH "RETURN VALUE"
On success,
.B mmap
returns a pointer to the mapped area.
On error, \-1 is returned, and
.I errno
is set appropriately.
On success,
.B munmap
returns 0, on failure \-1, and
.I errno
is set (probably to EINVAL).
.SH ERRORS
.TP
.B EBADF
.I fd
is not a valid file descriptor (and MAP_ANONYMOUS was not set).
.TP
.B EACCES
MAP_PRIVATE was asked, but
.I fd
is not open for reading. Or MAP_SHARED was asked and PROT_WRITE is set,
.I fd
is not open for writing.
.TP
.B EINVAL
We don't like
.I start
or
.I length
or
.IR offset .
(E.g., they are too large, or not aligned on a PAGESIZE boundary.)
.TP
.B ETXTBUSY
MAP_DENYWRITE was set but the object specified by
.I fd
is open for writing.
.TP
.B EAGAIN
The file has been locked, or too much memory has been locked.
.TP
.B ENOMEM
No memory is available.
.SH "CONFORMING TO"
SVr4, POSIX.1b (formerly POSIX.4), 4.4BSD. Svr4 documents additional
error codes ENXIO and ENODEV.
.SH "SEE ALSO"
.BR getpagesize (2),
.BR msync (2),
.BR shm_open (2),
B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128-129 and 389-391.
|