From a7e6b1eaae55e3cfc93cbaf826be5091e537642c Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Thu, 27 Apr 2023 00:04:48 +0900 Subject: [PATCH] kernel: copy signal dispositions on fork; clear them on exec --- kernel/misc/elf64.c | 6 ++++++ kernel/sys/process.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/kernel/misc/elf64.c b/kernel/misc/elf64.c index 78444e43..5141a123 100644 --- a/kernel/misc/elf64.c +++ b/kernel/misc/elf64.c @@ -324,6 +324,12 @@ int elf_exec(const char * path, fs_node_t * file, int argc, const char *const ar this_core->current_process->thread.page_directory->directory = mmu_clone(NULL); mmu_set_directory(this_core->current_process->thread.page_directory->directory); process_release_directory(this_directory); + for (int i = 0; i < NUMSIGNALS; ++i) { + if (this_core->current_process->signals[i].handler != 1) { + this_core->current_process->signals[i].handler = 0; + this_core->current_process->signals[i].flags = 0; + } + } for (int i = 0; i < header.e_phnum; ++i) { Elf64_Phdr phdr; diff --git a/kernel/sys/process.c b/kernel/sys/process.c index b853eb95..bf80dc80 100644 --- a/kernel/sys/process.c +++ b/kernel/sys/process.c @@ -1299,6 +1299,9 @@ pid_t fork(void) { new_proc->thread.page_directory->directory = directory; spin_init(new_proc->thread.page_directory->lock); + memcpy(new_proc->signals, parent->signals, sizeof(struct signal_config) * (NUMSIGNALS+1)); + new_proc->blocked_signals = parent->blocked_signals; + struct regs r; memcpy(&r, parent->syscall_registers, sizeof(struct regs)); sp = new_proc->image.stack; @@ -1337,6 +1340,8 @@ pid_t clone(uintptr_t new_stack, uintptr_t thread_func, uintptr_t arg) { spin_lock(new_proc->thread.page_directory->lock); new_proc->thread.page_directory->refcount++; spin_unlock(new_proc->thread.page_directory->lock); + memcpy(new_proc->signals, parent->signals, sizeof(struct signal_config) * (NUMSIGNALS+1)); + new_proc->blocked_signals = parent->blocked_signals; struct regs r; memcpy(&r, parent->syscall_registers, sizeof(struct regs));