Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Jul 2003 20:17:02 +0200
From:      Steve O'Hara-Smith <steve@sohara.org>
To:        Barney Wolff <barney@databus.com>
Cc:        freebsd-stable@freebsd.org
Subject:   Re: malloc does not return null when out of memory
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>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 24 Jul 2003 12:45:22 -0400
Barney Wolff <barney@databus.com> 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/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030724201702.6667b707.steve>