[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [PATCH 6/9] mini-os: let memory allocation fail if no free page available



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@xxxxxxxx>
---
 mm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm.c b/mm.c
index 263a356..185a8a5 100644
--- a/mm.c
+++ b/mm.c
@@ -335,6 +335,11 @@ 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;
     }
-- 
2.6.6


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/cgi-bin/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.