Mmap and munmap behavior

The Open Group standard says that munmap should be called with the address aligned on the page, but it does not seem to require any requirements for mmap to return the address aligned on the pages. Is this what you need to handle when you write portable code?

+5
source share
4 answers

mmap will only display whole pages and thus can only return the page border. This is in the short description:

mmap - map pages of memory

(emphasis mine)

+2
source
Documentation

mmap mentions this requirement, although to no avail. on my mac for example:

     [EINVAL]           The offset argument was not page-aligned based on the
                        page size as returned by getpagesize(3).

http://pubs.opengroup.org/onlinepubs/009695399/functions/mmap.html

[EINVAL] addr ( MAP_FIXED) , sysconf(), .

+1

, ( , ). , (), 1 span 1 (). (, = 4 = 2 /4 x86/64; ).

0

If I understand correctly, if MAP_FIXED is not specified, the behavior of mmap is implementation dependent. Thus, the only portable way to use mmap is with MAP_FIXED, which means you have to specify a page-aligned address. Otherwise, you will receive EINVAL.

-1
source

All Articles