Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262331AbVAZXWv (ORCPT ); Wed, 26 Jan 2005 18:22:51 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261599AbVAZXVy (ORCPT ); Wed, 26 Jan 2005 18:21:54 -0500 Received: from alog0168.analogic.com ([208.224.220.183]:39296 "EHLO chaos.analogic.com") by vger.kernel.org with ESMTP id S261632AbVAZSVg (ORCPT ); Wed, 26 Jan 2005 13:21:36 -0500 Date: Wed, 26 Jan 2005 13:20:53 -0500 (EST) From: linux-os Reply-To: linux-os@analogic.com To: Olivier Galibert cc: Rik van Riel , Andrew Morton , linux-kernel@vger.kernel.org, James Antill , Bryn Reeves Subject: Re: don't let mmap allocate down to zero In-Reply-To: <20050126181006.GA80759@dspnet.fr.eu.org> Message-ID: References: <20050126181006.GA80759@dspnet.fr.eu.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2675 Lines: 69 On Wed, 26 Jan 2005, Olivier Galibert wrote: > On Wed, Jan 26, 2005 at 11:38:15AM -0500, linux-os wrote: >> On Wed, 26 Jan 2005, Rik van Riel wrote: >> >>> With some programs the 2.6 kernel can end up allocating memory >>> at address zero, for a non-MAP_FIXED mmap call! This causes >>> problems with some programs and is generally rude to do. This >>> simple patch fixes the problem in my tests. >> >> Does this mean that we can't mmap the screen regen buffer at >> 0x000b8000 anymore? > > No. Missed the "non-MAP_FIXED" part? You can always map at 0, you > just have to ask for it. > Okay. > >> What 'C' standard do you refer to? > > Malloc uses mmap to get more memory. Malloc returning 0 means no > memory, not "the memory happens to be at 0". Not that easy to fix in > the glibc if you want to keep the "segfault on null pointer accesses" > debugging help too. > malloc is a runtime library. It has its own documented rules. > Given that the man page itself says that unless you're using MAP_FIXED > start is only a hint and you should use 0 if you don't care things can > get real annoying real fast. Imagine if you want to mmap a <4K file > and mmap then returns 0, i.e. NULL, as the mapping address as you > asked. It's illegal from the point of view of susv3[1] and it's real > annoying in a C/C++ program. mmap() can (will) return 0 if you use 0 as the hint and use MAP_FIXED at 0. That's the reason why one does NOT check for NULL with mmap() but for MAP_FAILED (which on this system is (void *)-1. > > OG. > > [1] > When MAP_FIXED is not set, the implementation uses addr in an > implementation-defined manner to arrive at pa. The pa so chosen > shall be an area of the address space that the implementation deems > suitable for a mapping of len bytes to the file. All implementations > interpret an addr value of 0 as granting the implementation complete > freedom in selecting pa, subject to constraints described below. A > non-zero value of addr is taken to be a suggestion of a process > address near which the mapping should be placed. When the > implementation selects a value for pa, it never places a mapping at > address 0, nor does it replace any extant mapping. > Cheers, Dick Johnson Penguin : Linux version 2.6.10 on an i686 machine (5537.79 BogoMips). Notice : All mail here is now cached for review by Dictator Bush. 98.36% of all statistics are fiction. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/