From 6eb79f812ee43a4e9142de61a5821e0cc8c52bb1 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sun, 26 Apr 2015 15:47:47 +0200 Subject: kern: gracefully handle resource shortage * kern/thread.c (stack_alloc): Report resource shortage. * kern/sched_prim.h (stack_alloc): Adjust declaration accordingly. * kern/thread_swap.c (thread_doswapin): Report resource shortage. (swapin_thread_continue): If the swap-in fails, put the thread back on the queue and go back to sleep. * kern/thread_swap.h (thread_doswapin): Adjust declaration accordingly. --- kern/thread.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'kern/thread.c') diff --git a/kern/thread.c b/kern/thread.c index 009884c..f52c95b 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -171,7 +171,7 @@ boolean_t stack_alloc_try( * May block. */ -void stack_alloc( +kern_return_t stack_alloc( thread_t thread, void (*resume)(thread_t)) { @@ -195,15 +195,15 @@ void stack_alloc( (void) splx(s); if (stack == 0) { + kern_return_t kr; /* * Kernel stacks should be naturally aligned, * so that it is easy to find the starting/ending * addresses of a stack given an address in the middle. */ - - if (kmem_alloc_aligned(kmem_map, &stack, KERNEL_STACK_SIZE) - != KERN_SUCCESS) - panic("stack_alloc"); + kr = kmem_alloc_aligned(kmem_map, &stack, KERNEL_STACK_SIZE); + if (kr != KERN_SUCCESS) + return kr; #if MACH_DEBUG stack_init(stack); @@ -211,6 +211,7 @@ void stack_alloc( } stack_attach(thread, stack, resume); + return KERN_SUCCESS; } /* -- cgit v1.2.3