HP-UX Reference (11i v3 07/02) - 2 System Calls (vol 5)
m
mmap(2) mmap(2)
the mpctl(2) manual page. These flags are hints to the system. If memory of the desired type is not avail-
able, the next most suitable memory is returned instead.
mmap() cannot create a mapped file region unless the file descriptor used to map the file is open for read-
ing. For a mapped file region that is mapped with
MAP_SHARED , mmap() grants write access permission
only if the file descriptor is open for writing. If a region was mapped with either
MAP_PRIVATE or
MAP_ANONYMOUS
, mmap() grants all requested access permissions.
After the successful completion of
mmap(), fildes can be closed without effect on the mapped region or on
the contents of the mapped file. Each mapped region creates a file reference, similar to an open file
descriptor, that prevents the file data from being deallocated.
If an enforcement-mode file lock is in effect for any range of a file, a call to
mmap() to map any range of
the file with access rights that would violate the lock fails. The
msem_lock() and msem_unlock()
semaphore interfaces can be used to coordinate shared access to a region created with the
MAP_SHARED
flag. The advisory locks of the lockf()
or fcntl() interfaces have no effect on memory mapped
access, but they can be used to coordinate shared access to a
MAP_SHARED mapped file region.
After a call to
fork(), the child process inherits all mapped regions with the same data and the same
sharing and protection attributes as in the parent process. Each mapped file and anonymous memory
region created with mmap() is unmapped upon process exit, and by a successful call to any of the
exec
functions.
MAP_NORESERVE attribute is inherited across a
fork() call; at the time of the fork(), swap space for
a mapping is reserved in the child only for dirtied private pages that currently exist in the parent.
Thereafter, the child’s mapping reservation policy is as described above.
A
SIGBUS signal is delivered to a process when a write reference to a mapped file region would cause a file
system error condition, such as, exceeding quota or file system space limits.
A SIGBUS or SIGSEGV signal is delivered to a process upon a write reference to a region without
PROT_WRITE protection, or any reference to a region with PROT_NONE protection.
A call to mmap() with PROT_EXECUTE specified, but without PROT_WRITE specified for a
MAP_SHARED|MAP_FILE
mapping is treated by the system as the execution of the underlying file. This
implies that such a call fails if the file is currently open for writing or mapped with
MAP_SHARED|PROT_WRITE
options by any process, and if the call succeeds, the file cannot be opened
for writing or subsequently mapped with
MAP_SHARED|PROT_WRITE
options as long as such mappings
are present. A file’s status as an active executable file is determined only at the time of an
exec(),
exit(),ormmap() operation. mprotect() operations on a MAP_FILE|MAP_SHARED
mapping
have no effect on the underlying file’s status as an active executable file.
The implementation always zero-fills any partial page at the end of a memory region. Further, the imple-
mentation never writes out any modified portions of the last page of a file that are beyond the end of the
mapped portion of the file. If the mapping established by
mmap() extends into pages beyond the page con-
taining the last byte of the file, an application reference to any of the pages in the mapping that are beyond
the last page results in the delivery of a SIGBUS or SIGSEGV signal. The mmap() function adds an
extra reference to the file associated with the file descriptor fildes which is not removed by a subsequent
close() on that file descriptor. This reference is removed when there are no more mappings to the file.
The st_atime field of the mapped file may be marked for update at any time between the
mmap() call and
the corresponding
munmap() call. The initial read or write reference to a mapped region will cause the
file’s st_atime field to be marked for update if it has not already been marked for update.
The st_ctime , st_mtime , and st_atime fields of a file that is mapped with MAP_SHARED and
PROT_WRITE , will be marked for update at some point in the interval between a write reference to the
mapped region and the next call to msync() with MS_ASYNC or MS_SYNC for that portion of the file by
any process. If there is no such call, these fields may be marked for update at any time after a write refer-
ence if the underlying file is modified as a result.
There may be implementation-dependent limits on the number of memory regions that can be mapped (per
process or per system). If such a limit is imposed, whether the number of memory regions that can be
mapped by a process is decreased by the use of shmat() is implementation-dependent.
Security Restrictions
Some or all of the actions associated with this system call require the DEVOPS privilege. Processes owned
by the superuser have this privilege. Processes owned by other users may have this privilege, depending on
system configuration. See privileges (5) for more information about privileged access on systems that sup-
port fine-grained privileges.
HP-UX 11i Version 3: February 2007 − 4 − Hewlett-Packard Company 201