From 58c44c9a8feb8c258dcd85209149c16342995ec7 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 1 Jul 2022 20:36:59 +0200 Subject: kernel: add the debug_klog syscall for tracking down process ids --- src/kernel/syscalls.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/kernel/syscalls.c') diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 7040f6b..3cfc0ef 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -289,6 +289,14 @@ ret: // the macro is too stupid to handle returning pointers return addr; } +void _syscall_debug_klog(const void __user *buf, size_t len) { + static char kbuf[256]; + if (len >= sizeof(kbuf)) len = sizeof(kbuf) - 1; + virt_cpy_from(process_current->pages, kbuf, buf, len); + kbuf[len] = '\0'; + kprintf("[klog] %x\t%s\n", process_current->id, kbuf); +} + int _syscall(int num, int a, int b, int c, int d) { switch (num) { case _SYSCALL_EXIT: @@ -324,6 +332,9 @@ int _syscall(int num, int a, int b, int c, int d) { case _SYSCALL_MEMFLAG: _syscall_memflag((userptr_t)a, b, c); break; + case _SYSCALL_DEBUG_KLOG: + _syscall_debug_klog((userptr_t)a, b); + break; default: kprintf("unknown syscall "); panic_unimplemented(); // TODO fail gracefully -- cgit v1.2.3