POSIX compliance issue with mmap(2)
Garrett Cooper
yanegomi at gmail.com
Thu Jul 29 06:47:04 UTC 2010
According to the page noted below [1], mmap(2) should fail if the
value isn't page-aligned:
[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 current code in vm/vm_mmap.c only applies the check if
MAP_FIXED is specified in flags:
/*
* Check for illegal addresses. Watch out for address wrap... Note
* that VM_*_ADDRESS are not constants due to casts (argh).
*/
if (flags & MAP_FIXED) {
/*
* The specified address must have the same remainder
* as the file offset taken modulo PAGE_SIZE, so it
* should be aligned after adjustment by pageoff.
*/
addr -= pageoff;
if (addr & PAGE_MASK)
return (EINVAL);
Our manpage states this requirement, but doesn't conform to the
POSIX requirements.
I verified this claim with the failing test [2] by changing
MAP_SHARED to MAP_FIXED. The former case failed, while the latter case
passed.
Thoughts?
-Garrett
[1] http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html
[2] http://ltp.git.sourceforge.net/git/gitweb.cgi?p=ltp/ltp-dev.git;a=blob;f=testcases/open_posix_testsuite/conformance/interfaces/mmap/11-1.c;h=ed184a17591f0dbb5611ab70218a763a8a66b2df;hb=HEAD
More information about the freebsd-standards
mailing list