HP-UX Reference (11i v2 07/12) - 2 System Calls (vol 5)
m
mmap(2) mmap(2)
RETURN VALUE
Upon successful completion, mmap() returns the address, (pa), at which the mapping was placed. Other-
wise, it returns
MAP_FAILED (defined in
<sys/mman.h> ) and sets errno to indicate the error.
ERRORS
The
mmap() function will fail if:
[EACCES] The fildes argument is not open for read, regardless of the protection specified, or
fildes is not open for write and
PROT_WRITE was specified for a MAP_SHARED type
mapping, or
PROT_EXECUTE was set for a
MAP_SHARED mapping operation and
the underlying file does not have execute permission.
[EBADF] The fildes argument is not a valid open file descriptor.
[EINVAL] The addr argument (if
MAP_FIXED was specified) or off is not a multiple of the page
size as returned by
sysconf(), or are considered invalid by the implementation.
[EINVAL] The value of flags is invalid (neither
MAP_PRIVATE nor MAP_SHARED is set).
[EINVAL] The mapping already exists in 64-bit address space, but the application performing the
current
mmap() request has been compiled as a 32-bit executable.
[EINVAL] The mapping already exists in 32-bit address space, but the application performing the
current mmap() request has been compiled as a 64-bit executable and did not specify
MAP_ADDR32 in the flags argument.
[EINVAL] The value of off+len exceeds the maximum supported offset for mapped files.
[EINVAL] The mapping request used the
MAP_IO flag and the requested range is not a valid
range of I/O memory, the requested range is already mapped as restricted to kernel
usage, or the mapping is for an address range which overlaps but is not equal to an
existing mapping.
[EMFILE] The number of mapped regions would exceed an implementation-dependent limit (per
process or per system).
[ENODEV] The fildes argument refers to a file whose type is not supported by
mmap().
[ENOMEM]
MAP_FIXED was specified, and the range [addr, addr+len] exceeds that allowed for
the address space of a process. Or,
MAP_FIXED was not specified and there is
insufficient room in the address space to effect the mapping.
[ENXIO] Addresses in the range [off, off+len] are invalid for fildes.
[EOVERFLOW]
The file is a regular file and the value of off+len exceeds the offset maximum esta-
blished in the open file description associated with fildes.
[EPERM] The mapping request used the
MAP_IO flag and the calling process does not have the
DEVOPS privilege and is not a Real Time process.
[ETXTBSY] MAP_SHARED and MAP_FILE are set, and PROT_EXECUTE is set and
PROT_WRITE is not set, and the file being mapped is currently open for writing.
DEPENDENCIES
PA-RISC Architecture
Because the PA-RISC memory architecture utilizes a globally shared virtual address space between
processes and discourages multiple virtual address translations to the same physical address, all con-
currently existing MAP_SHARED mappings of a file range must share the same virtual address offsets and
hardware translations. PA-RISC-based HP-UX systems allocate virtual address ranges for shared memory
and shared mapped files in the range 0x80000000 through 0xefffffff for those applications compiled as 32-bit
executables or for those 64-bit applications which specify MAP_SHARED and MAP_ADDR32 in the flags
argument of the mmap() function. For applications compiled as 64-bit executables which specify
MAP_SHARED and do not specify MAP_ADDR32, the shared mapped files are in the range 0x00000011
00000000 through 0x000003ff ffffffff and 0xc0000000 00000000 through 0xc00003ff ffffffff. These address
ranges are used globally for all memory objects shared between processes.
This implies the following:
• Any single range of a file cannot be mapped multiple times into different virtual address ranges.
188 Hewlett-Packard Company − 5 − HP-UX 11i Version 2: December 2007 Update