mmap.2 (2010 09)

m
mmap(2) mmap(2)
NAME
mmap() - map pages of memory
SYNOPSIS
#include <sys/mman.h>
void *mmap(void *addr, size_t len, int prot, int flags,
int fildes, off_t off);
DESCRIPTION
The mmap() function establishes a mapping between a process address space and a file. The format of
the call is as follows:
pa = mmap(addr, len, prot, flags, fildes, off);
The mmap() function establishes a mapping between the process address space at an address pa for len
bytes and the file associated with the file descriptor fildes at offset off for len bytes. The value of pa is an
unspecified function of the argument addr and values of flags, further described below. A successful
mmap() call returns pa as its result. The address ranges covered by [pa, pa +len] and [off, off+len] must
be legitimate for the possible (not necessarily current) address space of the process and the file, respec-
tively.
If the size of the mapped file changes after the call to
mmap(), the effect of references to portions of the
mapped region that correspond to added or removed portions of the file is unspecified.
The
mmap() function is supported for regular files. Support for any other type of file is unspecified
except for /dev/zero, which is supported in HP-UX. See also zero(7).
The prot argument determines whether read, write, execute, or some combination of accesses are permit-
ted to the pages being mapped. The protection options are defined in
<sys/mman.h>:
PROT_READ Page can be read.
PROT_WRITE Page can be written.
PROT_EXEC Page can be executed.
PROT_NONE Page cannot be accessed.
The prot argument can be
PROT_NONE, or any combination of the bit-wise inclusive OR of the values of
PROT_READ, PROT_WRITE, and PROT_EXEC.IfPROT_NONE is not specified, the system may grant
other access permissions to the region in addition to those explicitly requested, except that write access
will not be granted unless PROT_WRITE is specified.
The following combinations of protection modes are supported:
PROT_NONE
PROT_READ
PROT_READ|PROT_EXECUTE
PROT_READ|PROT_WRITE
PROT_READ|PROT_WRITE|PROT_EXECUTE
The flags argument provides other information about the handling of the mapped pages. The options are
defined in <sys/mman.h>:
MAP_SHARED Share changes.
MAP_ADDR32 Share changes between 32-bit and 64-bit processes. Under Adaptive
Address Space, 64-bit MPAS (Mostly Private Address Space)
processes cannot specify this flag. See the Adaptive Address Space
Whitepaper for details.
MAP_PRIVATE Changes are private.
MAP_FIXED Interpret addr exactly.
MAP_FILE Create a mapped file region.
MAP_ANONYMOUS Create an unnamed memory region.
MAP_VARIABLE Place region at implementation-computed address.
MAP_NORESERVE Evaluate lazy swap space reservation.
MAP_GLOBAL Allocate physical memory from the global quadrant / octant.
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (8 pages)