From owner-freebsd-stable@FreeBSD.ORG Thu Jul 24 11:17:11 2003 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E71F137B401 for ; Thu, 24 Jul 2003 11:17:11 -0700 (PDT) Received: from smtp5.wanadoo.nl (smtp5.wanadoo.nl [194.134.35.176]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2CF8743F75 for ; Thu, 24 Jul 2003 11:17:11 -0700 (PDT) (envelope-from steve@sohara.org) Received: from ams-gw.sohara.org (rot2-p1513.dial.wanadoo.nl [62.234.203.233]) by smtp5.wanadoo.nl (Postfix) with SMTP id 4EE8B7650B; Thu, 24 Jul 2003 20:17:06 +0200 (CEST) Date: Thu, 24 Jul 2003 20:17:02 +0200 From: Steve O'Hara-Smith To: Barney Wolff Message-Id: <20030724201702.6667b707.steve@sohara.org> In-Reply-To: <20030724164522.GA39964@pit.databus.com> References: <20030723173427.GA72876@vmunix.com> <20030723173427.GA72876@vmunix.com> <5.2.0.9.0.20030723234250.052821e8@192.168.0.12> <20030724070936.GA16762@rot13.obsecurity.org> <3F1FF81F.5050701@mac.com> <20030724164522.GA39964@pit.databus.com> X-Mailer: Sylpheed version 0.9.3 (GTK+ 1.2.10; i386-portbld-freebsd4.8) X-Face: %]+HVL}K`P8>+8ZcY-WGHP6j@&mxMo9JH6_WdgIgUGH)JX/usO0%jy7T~IVgqjumD^OBqX,Kv^-GM6mlw(fI^$"QRKyZ$?xx/ Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit cc: freebsd-stable@freebsd.org Subject: Re: malloc does not return null when out of memory X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jul 2003 18:17:12 -0000 On Thu, 24 Jul 2003 12:45:22 -0400 Barney Wolff wrote: BW> On Thu, Jul 24, 2003 at 11:15:43AM -0400, Chuck Swiger wrote: BW> > BW> > +/* write a single byte per page to disable overcommit behavior */ BW> > +static int malloc_overcommit; BW> BW> Won't this merely die in malloc, not return 0? Yes - it needs to trap the SEGV as well to produce the wanted behaviour, something like: + else if (malloc_overcommit) { + ocsighandleron(); + for (stride = 0; stride <= size; stride += malloc_pagesize) { + ((char *)result)[stride] = SOME_JUNK; + if (ocsignalled) { + ocsighandleroff(); + return NULL; + } + } + ocsighandleroff(); + } Where ocsighandleron() installs a SEGV handler that sets ocsignalled when called and ocsighandleroff() installs the original one. BTW malloc_overcommit seems to be upside down, I left it that way. -- C:>WIN | Directable Mirrors The computer obeys and wins. |A Better Way To Focus The Sun You lose and Bill collects. | licenses available - see: | http://www.sohara.org/