The mmap() function shall 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.
EAGAIN
The mapping could not be locked in memory, if required by
mlockall(), due to a lack of resources.
EBADF
The fildes argument is not a valid open file descriptor.
EINVAL
The value of len is zero.
EINVAL
The value of flags is invalid (neither MAP_PRIVATE nor
MAP_SHARED is set).
EMFILE
The number of mapped regions would exceed an
implementation-defined 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, if MAP_FIXED was not specified and there is
insufficient room in the address space to effect the
mapping.
ENOMEM
The mapping could not be locked in memory, if required by
mlockall(), because it would require more space than the
system is able to supply.
ENOMEM
Not enough unallocated memory resources remain in the
typed memory object designated by fildes to allocate len
bytes.
ENOTSUP
MAP_FIXED or MAP_PRIVATE was specified in the flags
argument and the implementation does not support this
functionality.
The implementation does not support the combination
of accesses requested in the prot argument.
ENXIO
Addresses in the range [off,off+len) are invalid for the
object specified by fildes.
ENXIO
MAP_FIXED was specified in flags and the combination of
addr, len, and off is invalid for the object specified by
fildes.
ENXIO
The fildes argument refers to a typed memory object that
is not accessible from the calling process.
EOVERFLOW
The file is a regular file and the value of off plus len
exceeds the offset maximum established in the open file
description associated with fildes.
The mmap() function may fail if:
EINVAL
The addr argument (if MAP_FIXED was specified) or off is
not a multiple of the page size as returned by sysconf(),
or is considered invalid by the implementation.
The following sections are informative.