mmap(2) with MAP_ANON honouring offset although it shouldn't

Alan Cox alan.l.cox at gmail.com
Wed Oct 21 17:51:10 UTC 2009


On Wed, Oct 21, 2009 at 10:51 AM, Alexander Best <
alexbestms at math.uni-muenster.de> wrote:

> although the mmap(2) manual states in section MAP_ANON:
>
> "The offset argument is ignored."
>
> this doesn't seem to be true. running
>
> printf("%p\n", mmap((void*)0x1000, 0x1000, PROT_NONE, MAP_ANON, -1,
> 0x12345678));
>
> and
>
> printf("%p\n", mmap((void*)0x1000, 0x1000, PROT_NONE, MAP_ANON, -1, 0));
>
> produces different outputs. i've attached a patch to solve the problem. the
> patch is similar to the one proposed in this PR, but should apply cleanly
> to
> CURRENT: http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/71258
>

The standards for mmap(2) actually disallow values of "off" that are not a
multiple of the page size.

See http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html for
the following:
[EINVAL]The *addr* argument (if MAP_FIXED was specified) or *off* is not a
multiple of the page size as returned by
*sysconf*()<http://www.opengroup.org/onlinepubs/000095399/functions/sysconf.html>,
or is considered invalid by the implementation.Both Solaris and Linux
enforce this restriction.

I'm not convinced that the ability to specify a value for "off" that is not
a multiple of the page size is a useful differentiating feature of FreeBSD
versus Solaris or Linux.  Does anyone have a compelling argument (or use
case) to motivate us being different in this respect?

If you disallow values for "off" that are not a multiple of the page size,
then you are effectively ignoring "off" for MAP_ANON.

Regards,
Alan


More information about the freebsd-hackers mailing list