From owner-freebsd-hackers@FreeBSD.ORG Sun Jul 5 01:01:09 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 582741065677 for ; Sun, 5 Jul 2009 01:01:09 +0000 (UTC) (envelope-from neldredge@math.ucsd.edu) Received: from euclid.ucsd.edu (euclid.ucsd.edu [132.239.145.52]) by mx1.freebsd.org (Postfix) with ESMTP id 0D8088FC19 for ; Sun, 5 Jul 2009 01:01:09 +0000 (UTC) (envelope-from neldredge@math.ucsd.edu) Received: from zeno.ucsd.edu (zeno.ucsd.edu [132.239.145.22]) by euclid.ucsd.edu (8.11.7p3+Sun/8.11.7) with ESMTP id n650eKo02917; Sat, 4 Jul 2009 17:40:20 -0700 (PDT) Received: from localhost (neldredg@localhost) by zeno.ucsd.edu (8.11.7p3+Sun/8.11.7) with ESMTP id n650eJM05584; Sat, 4 Jul 2009 17:40:19 -0700 (PDT) X-Authentication-Warning: zeno.ucsd.edu: neldredg owned process doing -bs Date: Sat, 4 Jul 2009 17:40:19 -0700 (PDT) From: Nate Eldredge X-X-Sender: neldredg@zeno.ucsd.edu To: Alexander Best In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-hackers@freebsd.org Subject: Re: mmap/munmap with zero length 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: Sun, 05 Jul 2009 01:01:10 -0000 On Sun, 5 Jul 2009, Alexander Best wrote: > i'm wondering why mmap and munmap behave differently when it comes to a length > argument of zero. allocating memory with mmap for a zero length file returns a > valid pointer to the mapped region. > > munmap however isn't able to remove a mapping with no length. > > wouldn't it be better to either forbid this in mmap or to allow it in munmap? POSIX has an opinion: http://www.opengroup.org/onlinepubs/9699919799/functions/mmap.html "If len is zero, mmap() shall fail and no mapping shall be established." http://www.opengroup.org/onlinepubs/9699919799/functions/munmap.html "The munmap() function shall fail if: ... [EINVAL] The len argument is 0." -- Nate Eldredge neldredge@math.ucsd.edu