]> xenbits.xensource.com Git - mini-os.git/commitdiff
mini-os: let memory allocation fail if no free page available
authorJuergen Gross <jgross@suse.com>
Mon, 18 Jul 2016 14:46:11 +0000 (16:46 +0200)
committerJuergen Gross <jgross@suse.com>
Thu, 11 Aug 2016 11:03:52 +0000 (13:03 +0200)
Instead of panicing when no page can be allocated try to fail the
memory allocation by returning NULL instead.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
mm.c

diff --git a/mm.c b/mm.c
index 263a356ed01422bd672cdb0f396bf0cb9f2d8bec..8cf32106e163de2683e10e3f08be10a43379cc28 100644 (file)
--- a/mm.c
+++ b/mm.c
@@ -335,6 +335,13 @@ void *sbrk(ptrdiff_t increment)
     
     if (new_brk > heap_mapped) {
         unsigned long n = (new_brk - heap_mapped + PAGE_SIZE - 1) / PAGE_SIZE;
+
+        if ( n > nr_free_pages )
+        {
+            printk("Memory exhausted: want %ld pages, but only %ld are left\n",
+                   n, nr_free_pages);
+            return NULL;
+        }
         do_map_zero(heap_mapped, n);
         heap_mapped += n * PAGE_SIZE;
     }