syscall log: support for selective syscall tracing

This commit is contained in:
2025-12-29 14:25:12 +01:00
committed by Matheus
parent 91e2430d91
commit 963d29fc90
9 changed files with 155 additions and 0 deletions
+28
View File
@@ -1,3 +1,4 @@
#include <arch/cpu.h>
#include <kernel/syscalls.h>
#include <arch/msr.h>
#include <errno.h>
@@ -6,6 +7,11 @@
#define ARCH_CTL_SET_FSBASE 1
#define ARCH_CTL_GET_GSBASE 2
#define ARCH_CTL_GET_FSBASE 3
#define ARCH_CTL_SET_SYSTRACE 4
#define ARCH_CTL_SYSTRACE_OFF 0
#define ARCH_CTL_SYSTRACE_SELF 1
#define ARCH_CTL_SYSTRACE_ALL 2
static inline int copy_u64_to_user(void *ptr, uint64_t v) {
return usercopy_touser(ptr, &v, sizeof(v));
@@ -36,6 +42,28 @@ syscallret_t syscall_archctl(context_t *context, int func, void *arg) {
case ARCH_CTL_GET_FSBASE:
ret.errno = copy_u64_to_user(arg, rdmsr(MSR_FSBASE));
break;
case ARCH_CTL_SET_SYSTRACE:
#ifdef SYSCALL_LOGGING
switch ((uint64_t)arg) {
case ARCH_CTL_SYSTRACE_OFF:
current_thread()->proc->flags &= ~(PROC_FLAG_SYSTRACE | PROC_FLAG_SYSTRACE_SELF);
break;
case ARCH_CTL_SYSTRACE_SELF:
current_thread()->proc->flags |= PROC_FLAG_SYSTRACE | PROC_FLAG_SYSTRACE_SELF;
break;
case ARCH_CTL_SYSTRACE_ALL:
current_thread()->proc->flags |= PROC_FLAG_SYSTRACE;
current_thread()->proc->flags &= ~PROC_FLAG_SYSTRACE_SELF;
break;
default:
ret.errno = EINVAL;
break;
}
#else
// signal that syscall logging is not supported
ret.errno = ENOTSUP;
#endif
break;
default:
ret.errno = EINVAL;
break;