From 80afbedf39b574f7a660b2387f0272e4df905ede Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Thu, 26 Dec 2024 02:23:30 +0200 Subject: [PATCH] kernel/syscalls: Implement sys_kill syscall Signed-off-by: EnderIce2 --- Kernel/syscalls/native.cpp | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/Kernel/syscalls/native.cpp b/Kernel/syscalls/native.cpp index 37187861..088ea40e 100644 --- a/Kernel/syscalls/native.cpp +++ b/Kernel/syscalls/native.cpp @@ -182,7 +182,49 @@ static int sys_execve(SysFrm *Frame, const char *pathname, char *const argv[], c static pid_t sys_getpid(SysFrm *Frame) { return -ENOSYS; } static pid_t sys_getppid(SysFrm *Frame) { return -ENOSYS; } static pid_t sys_waitpid(pid_t pid, int *wstatus, int options) { return -ENOSYS; } -static int sys_kill(SysFrm *Frame, pid_t pid, int sig) { return -ENOSYS; } + +static int sys_kill(SysFrm *Frame, pid_t pid, int sig) +{ + PCB *pcb = thisProcess->GetContext()->GetProcessByID(pid); + if (!pcb) + return -ESRCH; + + /* TODO: Check permissions */ + + if (sig == 0) + return 0; + + if (pid == 0) + { + bool found = false; + foreach (auto proc in pcb->GetContext()->GetProcessList()) + { + if (proc->Security.ProcessGroupID == thisProcess->Security.ProcessGroupID) + { + debug("Sending signal %d to %s(%d)", sig, proc->Name, proc->ID); + proc->SendSignal(sig); + found = true; + } + } + if (!found) + return -ESRCH; + return 0; + } + + if (pid == -1) + { + fixme("Sending signal %d to all processes except init", sig); + return -ENOSYS; + } + + if (pid < -1) + { + fixme("Sending signal %d to process group %d", sig, pid); + return -ENOSYS; + } + + return pcb->SendSignal(sig); +} static int sys_prctl(SysFrm *Frame, prctl_options_t option, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4) {