summaryrefslogtreecommitdiff
path: root/kernel/sched/scheduler.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-13 21:07:02 +0200
committerAnton Kling <anton@kling.gg>2024-04-13 21:07:02 +0200
commit92f848244796881994c1f147633123c45da219b6 (patch)
tree4ad209b6ede26b8475b7f0c6afb2382336dbbac7 /kernel/sched/scheduler.c
parent008b84bf5308d2f180905130653a656bfedccf8c (diff)
Kernel: Don't hard fail if the kernel can't allocate memory.
Currently this is just a improvement of error handling but it should also try to free up memory where it is possible.
Diffstat (limited to 'kernel/sched/scheduler.c')
-rw-r--r--kernel/sched/scheduler.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/kernel/sched/scheduler.c b/kernel/sched/scheduler.c
index 45969b0..6f36a76 100644
--- a/kernel/sched/scheduler.c
+++ b/kernel/sched/scheduler.c
@@ -111,8 +111,15 @@ process_t *create_process(process_t *p, u32 esp, u32 eip) {
sizeof(current_task->program_name));
}
- r->cr3 = (p) ? clone_directory(get_active_pagedirectory())
- : get_active_pagedirectory();
+ if (p) {
+ r->cr3 = clone_directory(p->cr3);
+ if (!r->cr3) {
+ kfree(r);
+ return NULL;
+ }
+ } else {
+ r->cr3 = get_active_pagedirectory();
+ }
r->parent = p;
r->tcb = kcalloc(1, sizeof(struct TCB));
@@ -168,6 +175,7 @@ process_t *create_process(process_t *p, u32 esp, u32 eip) {
void tasking_init(void) {
current_task = ready_queue = create_process(NULL, 0, 0);
+ assert(current_task);
current_task_TCB = current_task->tcb;
current_task->tcb->CR3 = current_task->cr3->physical_address;
}
@@ -321,9 +329,14 @@ process_t *internal_fork(process_t *parent);
int fork(void) {
process_t *new_task;
new_task = internal_fork(current_task);
- if (NULL == new_task) {
+ if (0 == new_task) {
return 0;
}
+ if ((process_t *)1 == new_task) {
+ return -ENOMEM; // FIXME: This is probably the reason it failed now but is
+ // not the only reason it could fail(at least in the
+ // future).
+ }
process_t *tmp_task = (process_t *)ready_queue;
for (; tmp_task->next;) {