HP-UX Reference (11i v1 05/09) - 2 System Calls (vol 5)

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
Note: This manpage contains HP-UX extensions.
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 a process and the file, respectively.
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.
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.
Implementations need not enforce all combinations of access permissions. However, writes shall only be
permitted when PROT_WRITE has been set.
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.
MAP_PRIVATE Changes are private.
MAP_FIXED Interpret addr exactly.
The MAP_PRIVATE and MAP_SHARED flags control the visibility of write references to the memory
region. Exactly one of these flags must be specified. The mapping type is retained across a fork().
If MAP_SHARED is set in ags, write references to the memory region by the calling process may change
the file and are visible in all MAP_SHARED mappings of the same portion of the file by any process of the
same executable type. That is, an application compiled as a 32-bit process will be able to share the same
mappings with other 32-bit processes, and an application compiled as a 64-bit process will be able to share
the same mappings with other 64-bit processes.
If a 64-bit and a 32-bit application want to share the same mapping, both MAP_ADDR32 and
MAP_SHARED must be set in flags by the 64-bit application. The 32-bit application does not need to set
MAP_ADDR32 in flags. When MAP_SHARED is set in flags, write references to the memory region by the
calling process may change the file. Changes are visible in all 32-bit processes which specify MAP_SHARED
and by all 64-bit processes which specify both MAP_SHARED and MAP_ADDR32 for the same portion of the
file.
If MAP_PRIVATE is set in flags, write references to the memory region by the calling process do not
change the file and are not visible to any process in other mappings of the same portion of the file.
HP-UX 11i Version 1: September 2005 1 Hewlett-Packard Company Section 2153