mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-28 13:18:22 +00:00
syscalls: killthread
This commit is contained in:
@@ -90,6 +90,7 @@ extern syscall_setegid
|
||||
extern syscall_sigsuspend
|
||||
extern syscall_sigtimedwait
|
||||
extern syscall_sigpending
|
||||
extern syscall_killthread
|
||||
syscalltab:
|
||||
dq syscall_print
|
||||
dq syscall_mmap
|
||||
@@ -182,7 +183,8 @@ dq syscall_setegid
|
||||
dq syscall_sigsuspend
|
||||
dq syscall_sigtimedwait
|
||||
dq syscall_sigpending
|
||||
syscallcount equ 91
|
||||
dq syscall_killthread
|
||||
syscallcount equ 92
|
||||
section .text
|
||||
global arch_syscall_entry
|
||||
; on entry:
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#ifdef SYSCALL_LOGGING
|
||||
|
||||
#define SYSCALL_COUNT 91
|
||||
#define SYSCALL_COUNT 92
|
||||
#define LOGSTR(x) arch_e9_puts(x)
|
||||
|
||||
static char *name[] = {
|
||||
@@ -99,7 +99,8 @@ static char *name[] = {
|
||||
"setegid",
|
||||
"sigsuspend",
|
||||
"sigtimedwait",
|
||||
"sigpending"
|
||||
"sigpending",
|
||||
"killthread"
|
||||
};
|
||||
|
||||
static char *args[] = {
|
||||
@@ -193,7 +194,8 @@ static char *args[] = {
|
||||
"egid %d", // setegid
|
||||
"sigset %p", // sigsuspend
|
||||
"sigset %p info %p, timespec %p", // sigtimedwait
|
||||
"sigset %p\n" // sigpending
|
||||
"sigset %p\n", // sigpending
|
||||
"pid %d tid %d signal %d" // killthread
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <logging.h>
|
||||
#include <kernel/jobctl.h>
|
||||
#include <kernel/auth.h>
|
||||
|
||||
syscallret_t syscall_killthread(context_t *context, int pid, int tid, int signal) {
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
if (pid < 1 || tid < 1 || signal < 0 || signal > NSIG) {
|
||||
ret.errno = EINVAL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc_t *sender = _cpu()->thread->proc;
|
||||
proc_t *target = sched_getprocfrompid(pid);
|
||||
if (target == NULL) {
|
||||
ret.errno = ESRCH;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// permission check
|
||||
if (signal != SIGCONT || jobctl_getpgid(target) != jobctl_getpgid(sender)) {
|
||||
ret.errno = auth_process_check(&sender->cred, AUTH_ACTIONS_PROCESS_SIGNAL, target);
|
||||
if (ret.errno)
|
||||
goto leave;
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
bool intstatus = spinlock_acquireirqclear(&target->threadlistlock);
|
||||
|
||||
thread_t *thread = target->threadlist;
|
||||
while (thread) {
|
||||
if (thread->tid == tid) {
|
||||
signal_signalthread(thread, signal, false);
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
|
||||
thread = thread->procnext;
|
||||
}
|
||||
|
||||
spinlock_releaseirqrestore(&target->threadlistlock, intstatus);
|
||||
|
||||
if (ok == false) {
|
||||
ret.errno = ESRCH;
|
||||
ret.ret = -1;
|
||||
} else {
|
||||
ret.errno = 0;
|
||||
ret.ret = 0;
|
||||
}
|
||||
|
||||
leave:
|
||||
PROC_RELEASE(target);
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user