alignment and granularity of mmap

Posted by OwnWaterloo on Stack Overflow See other posts from Stack Overflow or by OwnWaterloo
Published on 2010-05-01T11:22:46Z Indexed on 2010/05/01 11:27 UTC
Read the original article Hit count: 320

Filed under:
|
|
|
|

I am confused by the specification of mmap.

Let pa be the return address of mmap (the same as the specification)

pa = mmap(addr, len, prot, flags, fildes, off);

In my opinion after the function call succeed the following range is valid

[ pa, pa+len )

My question is whether the range of the following is still valid?

[ round_down(pa, pagesize) , round_up(pa+len, pagesize) )
[ base, base + size ] for short

That is to say:

  1. is the base always aligned on the page boundary?
  2. is the size always a multiple of pagesize (the granularity is pagesize in other words)

Thanks for your help.

I think it is implied in this paragraph :

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 application shall ensure that the argument addr also meets 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 shall include, in any mapping operation, any partial page specified by the range [pa,pa+len).

But I'm not sure and I do not have much experience on POSIX.

  • Please show me some more explicit and more definitive evidence
  • Or show me at least one system which supports POSIX and has different behavior

Thanks agian.

© Stack Overflow or respective owner

Related posts about mmap

Related posts about posix