From 7ab80014e1d659f4577700021112265ccbe4e3a1 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 15 Oct 2022 18:42:53 +0200 Subject: [PATCH] More fork() work --- apps/Makefile | 1 - kernel/src/sys/exec.cpp | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/Makefile b/apps/Makefile index 97187f7e..dba694f6 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -11,7 +11,6 @@ CFLAGS := -Wall -Wextra -Werror -Os $(APPS_BIN)/%: $(APPS_SRC)/%.c @mkdir -p $(@D) $(CC) $(CFLAGS) -o $@ $^ - $(STRIP) $@ build: $(REAL_APPS) diff --git a/kernel/src/sys/exec.cpp b/kernel/src/sys/exec.cpp index ce4b621a..ddb708cf 100644 --- a/kernel/src/sys/exec.cpp +++ b/kernel/src/sys/exec.cpp @@ -32,16 +32,23 @@ void sys_fork(Context* context) // FIXME: Even though both processes's address s size_t stack_bytes = get_top_of_stack(parent->allocated_stack, TASK_PAGES_IN_STACK) - parent->regs.rsp; - child->regs.rsp -= stack_bytes; + child->regs.rsp = get_top_of_stack(child->allocated_stack, TASK_PAGES_IN_STACK) - stack_bytes; memcpy((void*)child->regs.rsp, (void*)parent->regs.rsp, stack_bytes); + child->regs.rsp += sizeof(uintptr_t) * 2; // I don't know why this is... + child->address_space = parent->address_space.clone(); child->regs.rax = 0; context->rax = child->id; - kinfoln("fork(): forked parent %d into child %d", parent->id, child->id); + child->state = child->Running; + + kinfoln("fork(): parent RIP %lx, child RIP %lx, parent RSP %lx, child RSP %lx", parent->regs.rip, child->regs.rip, + parent->regs.rsp, child->regs.rsp); + + kinfoln("fork(): forked parent %ld into child %ld", parent->id, child->id); return; }