summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/patches/error-handling0001-kern-gracefully-handle-resource-shortage.patch29
-rw-r--r--debian/patches/error-handling0002-vm-gracefully-handle-resource-shortage.patch59
-rw-r--r--debian/patches/error-handling0003-kern-gracefully-handle-resource-shortage.patch143
-rw-r--r--debian/patches/series3
4 files changed, 234 insertions, 0 deletions
diff --git a/debian/patches/error-handling0001-kern-gracefully-handle-resource-shortage.patch b/debian/patches/error-handling0001-kern-gracefully-handle-resource-shortage.patch
new file mode 100644
index 0000000..45aa690
--- /dev/null
+++ b/debian/patches/error-handling0001-kern-gracefully-handle-resource-shortage.patch
@@ -0,0 +1,29 @@
+From 9cc6ec312879838cd381e77cffbe4869bc98892a Mon Sep 17 00:00:00 2001
+From: Justus Winter <4winter@informatik.uni-hamburg.de>
+Date: Sun, 26 Apr 2015 15:35:43 +0200
+Subject: [PATCH gnumach 1/3] kern: gracefully handle resource shortage
+
+* kern/task.c (task_create): Gracefully handle resource shortage.
+---
+ kern/task.c | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/kern/task.c b/kern/task.c
+index 57e7f41..dcd5371 100644
+--- a/kern/task.c
++++ b/kern/task.c
+@@ -89,9 +89,8 @@ kern_return_t task_create(
+ #endif
+
+ new_task = (task_t) kmem_cache_alloc(&task_cache);
+- if (new_task == TASK_NULL) {
+- panic("task_create: no memory for task structure");
+- }
++ if (new_task == TASK_NULL)
++ return KERN_RESOURCE_SHORTAGE;
+
+ /* one ref for just being alive; one for our caller */
+ new_task->ref_count = 2;
+--
+2.1.4
+
diff --git a/debian/patches/error-handling0002-vm-gracefully-handle-resource-shortage.patch b/debian/patches/error-handling0002-vm-gracefully-handle-resource-shortage.patch
new file mode 100644
index 0000000..1b70c48
--- /dev/null
+++ b/debian/patches/error-handling0002-vm-gracefully-handle-resource-shortage.patch
@@ -0,0 +1,59 @@
+From c896bbc9b73edadc3ed96019055540686717d21f 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: [PATCH gnumach 2/3] 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 71c0edb..8c6bbab 100644
+--- a/vm/vm_object.c
++++ b/vm/vm_object.c
+@@ -1336,16 +1336,6 @@ kern_return_t vm_object_copy_call(
+ 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);
+--
+2.1.4
+
diff --git a/debian/patches/error-handling0003-kern-gracefully-handle-resource-shortage.patch b/debian/patches/error-handling0003-kern-gracefully-handle-resource-shortage.patch
new file mode 100644
index 0000000..b2d4e5a
--- /dev/null
+++ b/debian/patches/error-handling0003-kern-gracefully-handle-resource-shortage.patch
@@ -0,0 +1,143 @@
+From a453f45b30aa90da0b1aa84787a95243b116545b 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: [PATCH gnumach 3/3] 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/sched_prim.h | 2 +-
+ kern/thread.c | 11 ++++++-----
+ kern/thread_swap.c | 17 ++++++++++++++---
+ kern/thread_swap.h | 2 +-
+ 4 files changed, 22 insertions(+), 10 deletions(-)
+
+diff --git a/kern/sched_prim.h b/kern/sched_prim.h
+index fd989b6..62698dc 100644
+--- a/kern/sched_prim.h
++++ b/kern/sched_prim.h
+@@ -150,7 +150,7 @@ extern void stack_handoff(
+ * or are defined directly by machine-dependent code.
+ */
+
+-extern void stack_alloc(
++extern kern_return_t stack_alloc(
+ thread_t thread,
+ void (*resume)(thread_t));
+ extern boolean_t stack_alloc_try(
+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;
+ }
+
+ /*
+diff --git a/kern/thread_swap.c b/kern/thread_swap.c
+index dc2924a..20ad040 100644
+--- a/kern/thread_swap.c
++++ b/kern/thread_swap.c
+@@ -123,15 +123,18 @@ void thread_swapin(thread_t thread)
+ * it on a run queue. No locks should be held on entry, as it is
+ * likely that this routine will sleep (waiting for stack allocation).
+ */
+-void thread_doswapin(thread_t thread)
++kern_return_t thread_doswapin(thread_t thread)
+ {
++ kern_return_t kr;
+ spl_t s;
+
+ /*
+ * Allocate the kernel stack.
+ */
+
+- stack_alloc(thread, thread_continue);
++ kr = stack_alloc(thread, thread_continue);
++ if (kr != KERN_SUCCESS)
++ return kr;
+
+ /*
+ * Place on run queue.
+@@ -144,6 +147,7 @@ void thread_doswapin(thread_t thread)
+ thread_setrun(thread, TRUE);
+ thread_unlock(thread);
+ (void) splx(s);
++ return KERN_SUCCESS;
+ }
+
+ /*
+@@ -163,13 +167,20 @@ void __attribute__((noreturn)) swapin_thread_continue(void)
+
+ while ((thread = (thread_t) dequeue_head(&swapin_queue))
+ != THREAD_NULL) {
++ kern_return_t kr;
+ swapper_unlock();
+ (void) splx(s);
+
+- thread_doswapin(thread); /* may block */
++ kr = thread_doswapin(thread); /* may block */
+
+ s = splsched();
+ swapper_lock();
++
++ if (kr != KERN_SUCCESS) {
++ enqueue_head(&swapin_queue,
++ (queue_entry_t) thread);
++ break;
++ }
+ }
+
+ assert_wait((event_t) &swapin_queue, FALSE);
+diff --git a/kern/thread_swap.h b/kern/thread_swap.h
+index 9d64537..d032acc 100644
+--- a/kern/thread_swap.h
++++ b/kern/thread_swap.h
+@@ -37,7 +37,7 @@
+ */
+ extern void swapper_init(void);
+ extern void thread_swapin(thread_t thread);
+-extern void thread_doswapin(thread_t thread);
++extern kern_return_t thread_doswapin(thread_t thread);
+ extern void swapin_thread(void) __attribute__((noreturn));
+
+ #endif /* _KERN_THREAD_SWAP_H_ */
+--
+2.1.4
+
diff --git a/debian/patches/series b/debian/patches/series
index 848e660..b8e88ed 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -19,3 +19,6 @@ reorder-ipc_port.patch
0009-kern-fix-comment.patch
disable-more-counters.patch
nrqs.patch
+error-handling0001-kern-gracefully-handle-resource-shortage.patch
+error-handling0002-vm-gracefully-handle-resource-shortage.patch
+error-handling0003-kern-gracefully-handle-resource-shortage.patch