Cause excessively large malloc()s to fail rather than assert.
authorScott Wood <scott@thor.buserror.net>
Mon, 12 May 2008 02:11:46 +0000 (21:11 -0500)
committerScott Wood <scott@thor.buserror.net>
Mon, 12 May 2008 02:11:46 +0000 (21:11 -0500)
GCC's exception frame searching will malloc() larger than a page;
returning NULL forces it to fall back on slower, in-place searching.

Signed-off-by: Scott Wood <scott@thor.buserror.net>
kernel/lib/libc.cc

index 6518988b7b2538fe3acb510fa711f608dfabc2ed..8d9685a5a309eebc23b27d4d0c1c38cd0983df9d 100644 (file)
@@ -34,7 +34,8 @@ void bzero(void *b, size_t len)
 
 void *malloc(size_t len)
 {
-       assert(len <= Arch::page_size - sizeof(size_t));
+       if (len > Arch::page_size - sizeof(size_t))
+               return NULL;
 
        len = (len + sizeof(size_t) + Arch::page_size - 1) / Arch::page_size;
        Mem::Page *page = Mem::PageAlloc::alloc(len);