From 2be1c778a4dfe2c6ebb371b457c1e1dc9e89c98d Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 17 Jul 2024 00:24:32 -0400 Subject: kernel: exec: Save program state within thread Signed-off-by: Ian Moffett --- sys/include/sys/exec.h | 4 +++- sys/include/sys/proc.h | 4 ++-- sys/kern/exec_elf64.c | 1 + sys/kern/kern_exec.c | 4 ++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sys/include/sys/exec.h b/sys/include/sys/exec.h index 810e89e..2c85010 100644 --- a/sys/include/sys/exec.h +++ b/sys/include/sys/exec.h @@ -30,7 +30,7 @@ #ifndef _SYS_EXEC_H_ #define _SYS_EXEC_H_ -#include +#include #if defined(_KERNEL) @@ -52,6 +52,8 @@ STACK_PUSH(PTR, VAL); \ STACK_PUSH(PTR, TAG); +struct proc; + struct exec_range { paddr_t start; paddr_t end; diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h index ab13536..cf76e80 100644 --- a/sys/include/sys/proc.h +++ b/sys/include/sys/proc.h @@ -36,6 +36,7 @@ #include #include #include +#include #if defined(_KERNEL) #include #include @@ -46,10 +47,9 @@ #define PROC_STACK_PAGES 8 #define PROC_STACK_SIZE (PROC_STACK_PAGES * DEFAULT_PAGESIZE) -struct exec_prog; - struct proc { pid_t pid; + struct exec_prog exec; struct trapframe tf; struct pcb pcb; size_t priority; diff --git a/sys/kern/exec_elf64.c b/sys/kern/exec_elf64.c index b207fbb..d9a3bb9 100644 --- a/sys/kern/exec_elf64.c +++ b/sys/kern/exec_elf64.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 1466159..ceb08f6 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -36,6 +36,7 @@ #include #include #include +#include /* * Release the memory of the old stack @@ -84,6 +85,9 @@ execve(struct proc *td, const struct execve_args *args) if (td->stack_base != 0) release_stack(td); + /* Save program state */ + memcpy(&td->exec, &prog, sizeof(td->exec)); + /* Set new stack and map it to userspace */ td->stack_base = stack; vm_map(pcbp->addrsp, td->stack_base, td->stack_base, -- cgit v1.2.3