summaryrefslogtreecommitdiff
path: root/src/kernel/proc.c
diff options
context:
space:
mode:
authordzwdz2022-04-14 07:51:32 +0200
committerdzwdz2022-04-14 07:51:32 +0200
commitcd096cf7aa7b96e04a68d059efe3239d77d25d78 (patch)
tree5c76b652c584c0cda2d770cbb87f25196fdf9d85 /src/kernel/proc.c
parentf1ef26f435d2eef53a718cf1c2b06387e29b2a3b (diff)
kernel: basic page allocator, `process_free`
Diffstat (limited to 'src/kernel/proc.c')
-rw-r--r--src/kernel/proc.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index ca1b2ec..2f407c3 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -60,6 +60,27 @@ struct process *process_fork(struct process *parent) {
return child;
}
+void process_free(struct process *p) {
+ assert(p->state == PS_DEADER);
+ pagedir_free(p->pages);
+ if (p->child) { // TODO
+ // panic_invalid_state();
+ return;
+ }
+ if (p->parent && p->parent->child == p) {
+ p->parent->child = p->sibling;
+ } else {
+ // this would be simpler if siblings were a doubly linked list
+ struct process *prev = p->parent->child;
+ while (prev->sibling != p) {
+ prev = prev->sibling;
+ assert(prev);
+ }
+ prev->sibling = p->sibling;
+ }
+ kfree(p);
+}
+
void process_switch(struct process *proc) {
assert(proc->state == PS_RUNNING);
process_current = proc;
@@ -143,6 +164,7 @@ handle_t process_find_handle(struct process *proc) {
}
void process_kill(struct process *proc, int ret) {
+ // TODO kill children
proc->state = PS_DEAD;
proc->death_msg = ret;
process_try2collect(proc);
@@ -161,11 +183,13 @@ int process_try2collect(struct process *dead) {
switch (parent->state) {
case PS_WAITS4CHILDDEATH:
- dead->state = PS_DEADER;
- parent->state = PS_RUNNING;
-
ret = dead->death_msg;
regs_savereturn(&parent->regs, ret);
+ parent->state = PS_RUNNING;
+
+ dead->state = PS_DEADER;
+ process_free(dead);
+
return ret;
default: