HP-UX Reference (11i v1 05/09) - 2 System Calls (vol 5)
m
mmap(2) mmap(2)
• addr must be a multiple of the page size returned by
sysconf(_SC_PAGE_SIZE)
.
If
MAP_NORESERVE
is set in flags:
• no swap space is initially be reserved for the private mapping. Without this flag, the creation of
a MAP_PRIVATE region reserves swap space equal to the size of the mapping. When a page in
the mapping is first modified (written into), a private page is created and the swap space which
had been reserved is used to hold the private copy of the data in the event of a page-out. An ini-
tial write into a page of a MAP_NORESERVE mapping produces results which depend on the
current availability of system swap space since the swap space reservation occurs at the time of
the first write and only for the affected page. If the swap space reservation can be made for the
page, the write succeeds and is processed as described above; if not, the write fails and a
SIGBUS signal is posted to the writing process for the effective virtual address.
madvise(...,MADV_DONTNEED)
on a MAP_NORESERVE object will release swap space
reservations for relevant pages.
If
MAP_LOCAL is set in flags:
• Memory for this region will be allocated from the current locality domain. This flag overrides the
default allocation policy of first touch. Under a first touch allocation policy, when memory needs
to be allocated, the locality domain chosen is that of the currently executing process.
If
MAP_IO is set in flags:
• As mentioned above, MAP_IO must be set in the absence of any other flags to
mmap(). The
required arguments to
mmap() with MAP_IO set are: addr is set to NULL, fildes is set to -1,
and off is a 32-bit quantity representing the page containing the I/O address desired. In order to
calculate off on a 64-bit machine, divide the I/O address by the page size returned by
sysconf(_SC_PAGE_SIZE)
and truncate the result to the lower 32-bits. For example, a
mapping for the I/O address
0xffffffffffd07000
on a machine with a page size of 4096
would pass the lower 32-bits of
0xffffffffffd07
,or0xfffffd07 as off. On a 32-bit
machine, divide the I/O address by the page size and use the result without truncation (since
truncation is redundant here).
• This region will represent and allow direct access to memory on I/O devices. I/O space is always
mapped with both read and write access rights, regardless of the actual permissions specified by
the prot argument. Multiple processes can concurrently
mmap() a single I/O memory range. It
is the responsibility of the processes to synchronize their access. Successive calls to
mmap() to
map the same I/O space must be identical to the first mapping. Identical mappings have the
same address and size.
• Note that a process can additionally share I/O space (mapped by iomap) with a kernel driver.
However, this is only possible if the driver maps in the I/O space with user read/write access
rights using the appropriate driver I/O mapping services. Any I/O space mapped by drivers with
kernel read/write access rights can not be concurrently mapped by processes using
mmap().
• This functionality is only available to Real Time processes using the HP-UX Real Time Exten-
sions.
The prot argument can be
PROT_NONE, or any combination of PROT_READ, PROT_WRITE, and
PROT_EXEC OR’ed together. If PROT_NONE is not specified, the system may grant other access permis-
sions to the region in addition to those explicitly requested, except that write access will not be granted
unless PROT_WRITE is specified.
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.
Whether modifications made to the file using write() are visible to mapped regions, and whether
modifications to a mapped region are visible with read(), is undefined except for the effect of msync().
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
HP-UX 11i Version 1: September 2005 − 2 − Hewlett-Packard Company Section 2−−157