Date: Sat, 31 Oct 2009 03:38:24 +0100 (CET) From: Alexander Best <alexbestms@math.uni-muenster.de> To: John Baldwin <jhb@freebsd.org>, <freebsd-hackers@freebsd.org> Cc: Alexander Best <alexbestms@math.uni-muenster.de> Subject: Re: mmap(2) with MAP_ANON honouring offset although it shouldn't Message-ID: <permail-200910310238241e86ffa800003202-a_best01@message-id.uni-muenster.de> In-Reply-To: <200910211349.10174.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a MIME encoded multipart message.
--+permail-200910310238241e86ffa800003202-a_best01+
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
John Baldwin schrieb am 2009-10-21:
> On Wednesday 21 October 2009 11:51:04 am Alexander Best 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
> A simpler patch would be to simply set pos = 0 below the MAP_STACK
> line if
> MAP_ANON is set.
how about the following patch. problem seems to be that pos = 0 needs to be
set before pageoff is being calculated.
i've tested mmap with MAP_STACK and the offset gets discarded just as
documented in mmap(2). with the patch the offset handling with MAP_ANON and
MAP_STACK (implies MAP_ANON) are the same.
another short question:
why does the second call when doing
printf("%p\n", mmap((void*)0x1000, 0x1000, PROT_READ|PROT_WRITE,
MAP_STACK, -1, 0x0));
printf("%p\n", mmap((void*)0x1000, 0x1000, PROT_READ|PROT_WRITE,
MAP_STACK, -1, 0x0));
fail? doesn't MAP_STACK allow mapping the same region twice?
printf("%p\n", mmap((void*)0x1000, 0x1000, PROT_READ|PROT_WRITE,
MAP_STACK, -1, 0x0));
printf("%p\n", mmap((void*)0x2000, 0x1000, PROT_READ|PROT_WRITE,
MAP_STACK, -1, 0x0));
works just as expected.
cheers.
alex
--+permail-200910310238241e86ffa800003202-a_best01+
Content-Type: text/plain
Content-Transfer-Encoding: Base64
Content-Disposition: attachment; filename="vmmmap.c.patch.txt"
LS0tIC91c3Ivc3JjL3N5cy92bS92bV9tbWFwLmMJMjAwOS0xMC0yOCAyMTozNzo1My4wMDAwMDAw
MDAgKzAxMDAKKysrIC4vdm1fbW1hcC5jCTIwMDktMTAtMzEgMDM6MjI6NDQuMDAwMDAwMDAwICsw
MTAwCkBAIC0yNDEsOSArMjQxLDExIEBACiAJCSAgICAoKHByb3QgJiAoUFJPVF9SRUFEIHwgUFJP
VF9XUklURSkpICE9IChQUk9UX1JFQUQgfCBQUk9UX1dSSVRFKSkpCiAJCQlyZXR1cm4gKEVJTlZB
TCk7CiAJCWZsYWdzIHw9IE1BUF9BTk9OOwotCQlwb3MgPSAwOwogCX0KIAorCWlmIChmbGFncyAm
IE1BUF9BTk9OKQorCQlwb3MgPSAwOworCiAJLyoKIAkgKiBBbGlnbiB0aGUgZmlsZSBwb3NpdGlv
biB0byBhIHBhZ2UgYm91bmRhcnksCiAJICogYW5kIHNhdmUgaXRzIHBhZ2Ugb2Zmc2V0IGNvbXBv
bmVudC4KQEAgLTMwMCw3ICszMDIsNiBAQAogCQloYW5kbGUgPSBOVUxMOwogCQloYW5kbGVfdHlw
ZSA9IE9CSlRfREVGQVVMVDsKIAkJbWF4cHJvdCA9IFZNX1BST1RfQUxMOwotCQlwb3MgPSAwOwog
CX0gZWxzZSB7CiAJCS8qCiAJCSAqIE1hcHBpbmcgZmlsZSwgZ2V0IGZwIGZvciB2YWxpZGF0aW9u
IGFuZAo=
--+permail-200910310238241e86ffa800003202-a_best01+--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?permail-200910310238241e86ffa800003202-a_best01>
