summaryrefslogtreecommitdiff
path: root/src/kernel/proc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/proc.c')
-rw-r--r--src/kernel/proc.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index df20df3..94fc419 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -1,5 +1,6 @@
#include <kernel/arch/generic.h>
#include <kernel/mem/alloc.h>
+#include <kernel/mem/virt.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/util.h>
@@ -101,3 +102,30 @@ handle_t process_find_handle(struct process *proc) {
if (handle == HANDLE_MAX) handle = -1;
return handle;
}
+
+int process_try2collect(struct process *dead) {
+ struct process *parent = dead->parent;
+ int len, ret;
+ bool res;
+
+ assert(dead->state == PS_DEAD);
+
+ switch (parent->state) {
+ case PS_WAITS4CHILDDEATH:
+ dead->state = PS_DEADER;
+ parent->state = PS_RUNNING;
+
+ len = parent->death_msg.len < dead->death_msg.len
+ ? parent->death_msg.len : dead->death_msg.len;
+ res = virt_cpy(
+ parent->pages, parent->death_msg.buf,
+ dead->pages, dead->death_msg.buf, len);
+
+ ret = res ? len : 0;
+ regs_savereturn(&parent->regs, ret);
+ return ret;
+
+ default:
+ return -1;
+ }
+}