Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Oct 2009 12:51:09 -0500
From:      Alan Cox <alan.l.cox@gmail.com>
To:        Alexander Best <alexbestms@math.uni-muenster.de>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: mmap(2) with MAP_ANON honouring offset although it shouldn't
Message-ID:  <ca3526250910211051v2fef55e7yda262a58df200751@mail.gmail.com>
In-Reply-To: <permail-200910211551041e86ffa80000182a-a_best01@message-id.uni-muenster.de>
References:  <permail-200910211551041e86ffa80000182a-a_best01@message-id.uni-muenster.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Oct 21, 2009 at 10:51 AM, Alexander Best <
alexbestms@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ca3526250910211051v2fef55e7yda262a58df200751>