WIP: Add fork() #13

Closed
apio wants to merge 8 commits from fork into main
2 changed files with 9 additions and 3 deletions
Showing only changes of commit 7ab80014e1 - Show all commits

View File

@ -11,7 +11,6 @@ CFLAGS := -Wall -Wextra -Werror -Os
$(APPS_BIN)/%: $(APPS_SRC)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -o $@ $^
$(STRIP) $@
build: $(REAL_APPS)

View File

@ -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;
}