From owner-freebsd-hackers@FreeBSD.ORG Sat Oct 31 02:38:33 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 76F0B1065670; Sat, 31 Oct 2009 02:38:33 +0000 (UTC) (envelope-from a_best01@uni-muenster.de) Received: from zivm-exrelay2.uni-muenster.de (ZIVM-EXRELAY2.UNI-MUENSTER.DE [128.176.192.15]) by mx1.freebsd.org (Postfix) with ESMTP id D0C118FC1C; Sat, 31 Oct 2009 02:38:32 +0000 (UTC) X-IronPort-AV: E=Sophos;i="4.44,657,1249250400"; d="txt'?scan'208";a="227687925" Received: from zivmaildisp1.uni-muenster.de (HELO ZIVMAILUSER03.UNI-MUENSTER.DE) ([128.176.188.85]) by zivm-relay2.uni-muenster.de with ESMTP; 31 Oct 2009 03:38:31 +0100 Received: by ZIVMAILUSER03.UNI-MUENSTER.DE (Postfix, from userid 149459) id 8383E1B0751; Sat, 31 Oct 2009 03:38:31 +0100 (CET) Date: Sat, 31 Oct 2009 03:38:24 +0100 (CET) From: Alexander Best Sender: Organization: Westfaelische Wilhelms-Universitaet Muenster To: John Baldwin , Message-ID: In-Reply-To: <200910211349.10174.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=+permail-200910310238241e86ffa800003202-a_best01+ Cc: Alexander Best Subject: Re: mmap(2) with MAP_ANON honouring offset although it shouldn't X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2009 02:38:33 -0000 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+--