HP-UX Reference (11i v2 03/08) - 2 System Calls (vol 5)
m
mmap(2) mmap(2)
The off argument is constrained to be aligned and sized according to the value returned by
sysconf()
when passed _SC_PAGESIZE or _SC_PAGE_SIZE
. When MAP_FIXED is specified, the argument
addr must also meet these constraints. The implementation performs mapping operations over whole
pages. Thus, while the argument len need not meet a size or alignment constraint, the implementation
will 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 region will represent ranges of I/O memory instead of core memory. This allows 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 accesses. Successive calls to mmap() to map the same I/O range must be
identical to the first mapping. Identical mappings have the same address and size.
• The process can additionally share I/O space (mapped via
iomap) with a kernel driver. How-
ever, 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().
• Calls using
MAP_IO implicitly also use MAP_SHARED and MAP_VARIABLE as mentioned above.
Explicit use of these flags is encouraged for forward compatibility, but not required. The
required arguments 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 range to be mapped. This address will be
either 40, 44 or 64-bits and use of MAP_IO for 32-bit processes is therefore restricted to users of
mmap64().
• The
MAP_IO functionality is currently restricted to Real Time processes or superusers.
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
the mpctl (2) manual page. These flags are hints to the system. If memory of the desired type is not
available, the next most suitable memory is returned instead.
HP-UX 11i Version 2: August 2003 − 3 − Hewlett-Packard Company Section 2−−153