Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mmap and munmap behaviour

Tags:

c

posix

mmap

The Open Group standard says that munmap should be called with a page aligned address, but there doesn't seem to be any requirement that mmap should be returning a page aligned address. Is this something you need to handle when you're writing portable code?

like image 991
onemasse Avatar asked Nov 04 '22 13:11

onemasse


2 Answers

mmap will only map whole pages, and can thus only return a page boundary. It's in the short description:

mmap - map pages of memory

(emphasis mine)

like image 70
Per Johansson Avatar answered Nov 15 '22 05:11

Per Johansson


mmap documentation does mention this requirement, although in an off-handed manner. 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 also says

[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.

like image 24
Foo Bah Avatar answered Nov 15 '22 06:11

Foo Bah