HP-UX Reference (11i v1 00/12) - 2 System Calls (vol 5)
__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man2/!!!intro.2
________________________________________________________________
___ ___
m
mmap(2) mmap(2)
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 .
It is also unspecified whether write references to a memory region mapped with MAP_SHARED are visible
to processes reading the file and whether writes to a file are visible to processes that have mapped the
modified portion of that file, except for the effect of msync().
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].
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 implementation
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 implementa-
tion selects a value for pa, it never places a mapping at address 0, nor does it replace any extant mapping,
nor map 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].
The implementation always zero-fills any partial page at the end of a memory region. Further, the imple-
mentation never writes out any modified portions of the last page of a file that are beyond the end of the
mapped portion of the file. If the mapping established by
mmap() extends into pages beyond the page con-
taining the last byte of the file, an application reference to any of the pages in the mapping that are beyond
the last page results in the delivery of a SIGBUS or SIGSEGV signal. The mmap() function adds an
extra reference to the file associated with the file descriptor fildes which is not removed by a subsequent
close() on that file descriptor. This reference is removed when there are no more mappings to the file.
The st_atime field of the mapped file may be marked for update at any time between the
mmap() call and
the corresponding
munmap() call. The initial read or write reference to a mapped region will cause the
file’s st_atime field to be marked for update if it has not already been marked for update.
The st_ctime and st_mtime fields of a file that is mapped with
MAP_SHARED and PROT_WRITE, will be
marked for update at some point in the interval between a write reference to the mapped region and the
next call to
msync() with MS_ASYNC or MS_SYNC for that portion of the file by any process. If there is
no such call, these fields may be marked for update at any time after a write reference if the underlying file
is modified as a result.
There may be implementation-dependent limits on the number of memory regions that can be mapped (per
process or per system). If such a limit is imposed, whether the number of memory regions that can be
mapped by a process is decreased by the use of shmat() is implementation-dependent.
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:
[EBADF] The fildes argument is not a valid open file descriptor.
[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.
[ENXIO] Addresses in the range [off, off+len] are invalid for fildes.
[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).
Section 2−−150 − 2 − HP-UX Release 11i: December 2000
___
___