HP-UX Reference (11i v3 07/02) - 2 System Calls (vol 5)
m
mmap(2) mmap(2)
include, in any unmapping operation, any partial page specified by the range [pa, pa+len].
The
MAP_FILE and MAP_ANONYMOUS
flags control whether the region to be mapped is a mapped file
region or an anonymous shared memory region. Exactly one of these flags must be selected.
If
MAP_FILE is set in flags, a new mapped file region is created, mapping the file associated with fildes.
off specifies the file byte offset at which the mapping starts. This offset must be a multiple of the page size
returned by
sysconf(_SC_PAGE_SIZE)
. If the end of the mapped file region is beyond the end of the
file, any reference to an address in the mapped file region corresponding to an offset beyond the end of the
file results in the delivery of a
SIGBUS signal to the process, unless the address lies in the last partial page
corresponding to the range beyond the end of the file. The last partial page mapping the range beyond the
end of the file is always initialized to zeros, and any modified portions of the last page of a file which are
beyond the file’s end are not written back to the file.
If
MAP_ANONYMOUS
is set in flags, a new memory region is created and initialized to all zeros. This
memory region can be shared only with descendants of the current process. If the fildes argument is not
−1, an [EINVAL] error is generated. This is not enforced in the current release, but will be enforced in the
next release. The value of off is meaningless because there is no underlying file object for the memory
region.
If
MAP_NORESERVE is set in flags, no swap space is initially 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 to), a private page is created and the swap space
reserved is used to hold the private copy of the data in the event of a page-out. An initial 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 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.
Specifying
MAP_GLOBAL in a call to mmap() forces the allocation to happen from the global quadrant as
compared to the private quadrants. See setmemwindow(1M) for further details.
If MAP_IO is set in flags:
• The mapping will cover a range of I/O memory instead of core memory. This allows direct access
to memory on I/O devices by the process.
• Multiple processes can concurrently map the same I/O address range. It is the responsibility of the
processes to synchronize their accesses to the I/O memory. Successive calls to
mmap() to map the
same I/O address range must be identical to the first mapping. Identical mappings pass the same
off and len arguments.
• Processes can additionally share access to an I/O address range with a kernel driver. However,
this is only possible if the driver maps the I/O address range with user read/write access rights
using the appropriate driver I/O mapping services. I/O address ranges mapped by drivers with
kernel read/write access rights can not be mapped by processes.
• Read/write access rights to the I/O address range are specified by the prot argument:
PROT_READ|PROT_WRITE for read and write access, or PROT_READ for read-only access.
• Calls with MAP_IO set will implicitly default to having MAP_SHARED set. MAP_PRIVATE can
be selected in place of MAP_SHARED to map the I/O address range in the private address space of
the process. MAP_GLOBAL can be selected in addition to MAP_SHARED to map the I/O address
range in the shared global address space of the process.
• The arguments passed to mmap() with MAP_IO set are:
• addr is set to NULL,
• fildes is set to -1, and
• off is set to the starting physical address of the I/O memory to be mapped. The physical address
contains 64 bits; and use of MAP_IO by 32-bit processes is, therefore, done through mmap64().
• Use of MAP_IO functionality is currently restricted to Real Time processes or users with the
DEVOPS privilege.
Note that the flags MAP_MEM_INTERLEAVED, MAP_MEM_LOCAL, and MAP_MEM_FIRST_TOUCH
involve the placement of physical memory. This is important only on Cache Coherent Non-Uniform
Memory Architecture (ccNUMA) systems. They will have no effect otherwise. For more information, see
200 Hewlett-Packard Company − 3 − HP-UX 11i Version 3: February 2007