mmap.2 (2010 09)

m
mmap(2) mmap(2)
MAP_IO Create a virtual mapping for a physical I/O address range.
MAP_MEM_INTERLEAVED
Physical memory will be interleaved.
MAP_MEM_LOCAL Allocate physical memory from the current locality domain.
MAP_MEM_FIRST_TOUCH
Allocate physical memory from the locality domain of the first proces-
sor to touch each address.
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 flags, 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. Mappings created using the
MAP_IO flag do not currently support usage of the
MAP_ADDR32 flag. Applications may use MAP_IO with 32-bit and 64-bit processes, but the pa returned
to a 32-bit process may differ from the pa returned to a 64-bit process.
On Itanium-based platforms, 64-bit MPAS (Mostly Private Address Space) and MGAS (Mostly Global
Address Space) processes can share between themselves without incurring the cost of aliasing by specify-
ing the
MAP_GLOBAL flag without specifying the MAP_ADDR32 flag. Such mappings are not accessible
by 32-bit processes. See the Adaptive Address Space Whitepaper for details.
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.
It is unspecified whether write references by processes that have mapped the memory region using
MAP_SHARED are visible to processes that have mapped the same portion of the file using
MAP_PRIVATE.
The
MAP_VARIABLE and MAP_FIXED flags control the placement of the region as described below.
Exactly one of these flags must be selected, unless MAP_IO is set. MAP_IO implicitly defaults to using
MAP_VARIABLE and does not support MAP_FIXED.
If
MAP_VARIABLE is set in flags , and the requested address addr is NULL, or if it is not possible for the
system to place the region at the requested address, the region is placed at an address selected by the sys-
tem. If the requested address is not a multiple of the page size returned by
sysconf(_SC_PAGE_SIZE)
, the system treats the address as if it were rounded up to the next larger
page size multiple.
When
MAP_FIXED is set in the flags argument, the implementation is informed that the value of pa must
be addr, exactly. If
MAP_FIXED is set, mmap() may return MAP_FAILED and set errno to [EINVAL].
If a MAP_FIXED request is successful, the mapping established by mmap() replaces any previous map-
pings for the process pages in the range [pa, pa+len]. If mmap() fails for reasons other than [EBADF]
or [EINVAL], some of the mappings in the address range starting at addr and continuing for len bytes
may have been unmapped.
When
MAP_FIXED is not set, the implementation uses addr in an unspecified manner to arrive at pa.
The pa so chosen will be an area of the address space which the implementation deems suitable for a
mapping of len bytes to the file. All implementations interpret an addr value of 0 as granting the imple-
mentation complete freedom in selecting pa , subject to constraints described below. A non-zero value of
addr is taken to be a suggestion of a process address near which the mapping should be placed. When
the implementation selects a value for pa , it never places a mapping at address 0, replaces any extant
mapping, or maps into dynamic memory allocation areas.
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].
2 Hewlett-Packard Company 2 HP-UX 11i Version 3: September 2010