From 3c3d3614673c93bf1b1f47d612d8067455d06920 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sun, 26 Apr 2015 15:39:00 +0200 Subject: vm: gracefully handle resource shortage * vm/vm_object.c (vm_object_copy_call): Gracefully handle resource shortage by doing the allocation earlier and aborting the function if unsuccessful. --- vm/vm_object.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/vm/vm_object.c b/vm/vm_object.c index 71c0edb6..8c6bbab4 100644 --- a/vm/vm_object.c +++ b/vm/vm_object.c @@ -1335,16 +1335,6 @@ kern_return_t vm_object_copy_call( vm_object_t new_object; vm_page_t p; - /* - * Set the backing object for the new - * temporary object. - */ - - assert(src_object->ref_count > 0); - src_object->ref_count++; - vm_object_paging_begin(src_object); - vm_object_unlock(src_object); - /* * Create a memory object port to be associated * with this new vm_object. @@ -1358,10 +1348,18 @@ kern_return_t vm_object_copy_call( */ new_memory_object = ipc_port_alloc_kernel(); - if (new_memory_object == IP_NULL) { - panic("vm_object_copy_call: allocate memory object port"); - /* XXX Shouldn't panic here. */ - } + if (new_memory_object == IP_NULL) + return KERN_RESOURCE_SHORTAGE; + + /* + * Set the backing object for the new + * temporary object. + */ + + assert(src_object->ref_count > 0); + src_object->ref_count++; + vm_object_paging_begin(src_object); + vm_object_unlock(src_object); /* we hold a naked receive right for new_memory_object */ (void) ipc_port_make_send(new_memory_object); -- cgit v1.2.3