diff options
-rw-r--r-- | src/init/fs/misc.h | 5 | ||||
-rw-r--r-- | src/init/stdlib.c | 14 | ||||
-rw-r--r-- | src/init/stdlib.h | 2 | ||||
-rw-r--r-- | src/init/syscalls.c | 4 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 11 | ||||
-rw-r--r-- | src/shared/syscalls.h | 4 |
6 files changed, 38 insertions, 2 deletions
diff --git a/src/init/fs/misc.h b/src/init/fs/misc.h index e360a25..879be32 100644 --- a/src/init/fs/misc.h +++ b/src/init/fs/misc.h @@ -1,4 +1,5 @@ #pragma once +#include <init/stdlib.h> #include <stdbool.h> bool fork2_n_mount(const char *path); @@ -10,5 +11,5 @@ void fs_dir_inject(const char *path); /** Mounts something and injects its path into the fs */ // TODO path needs to have a trailing slash #define MOUNT(path, impl) \ - if (!fork2_n_mount(path)) {impl;} \ - if (!fork2_n_mount("/")) fs_dir_inject(path); + if (!fork2_n_mount(path)) {_klogf("impl %s", path); impl;} \ + if (!fork2_n_mount("/")) {_klogf("dir for %s", path); fs_dir_inject(path);} diff --git a/src/init/stdlib.c b/src/init/stdlib.c index cbaed61..d9d882d 100644 --- a/src/init/stdlib.c +++ b/src/init/stdlib.c @@ -37,6 +37,20 @@ int snprintf(char *str, size_t len, const char *fmt, ...) { return ret; } +int _klogf(const char *fmt, ...) { + // idiotic. however, this hack won't matter anyways + char buf[256]; + int ret = 0; + char *ptrs[2] = {buf, buf + sizeof buf}; + va_list argp; + va_start(argp, fmt); + ret = __printf_internal(fmt, argp, backend_buf, &ptrs); + va_end(argp); + if (ptrs[0] < ptrs[1]) *ptrs[0] = '\0'; + _syscall_debug_klog(buf, ret); + return ret; +} + int file_open(libc_file *f, const char *path, int flags) { f->pos = 0; diff --git a/src/init/stdlib.h b/src/init/stdlib.h index 03e1717..a48391c 100644 --- a/src/init/stdlib.h +++ b/src/init/stdlib.h @@ -7,6 +7,8 @@ int printf(const char *fmt, ...); int snprintf(char *str, size_t len, const char *fmt, ...); +int _klogf(const char *fmt, ...); // for kernel debugging only + typedef struct { int fd; int pos; diff --git a/src/init/syscalls.c b/src/init/syscalls.c index 5b8950b..6e4c2dc 100644 --- a/src/init/syscalls.c +++ b/src/init/syscalls.c @@ -50,3 +50,7 @@ void __user *_syscall_memflag(void __user *addr, size_t len, int flags) { return (void __user *)_syscall(_SYSCALL_MEMFLAG, (int)addr, (int)len, flags, 0); } +void _syscall_debug_klog(const void __user *buf, size_t len) { + return (void)_syscall(_SYSCALL_DEBUG_KLOG, (int)buf, (int)len, 0, 0); +} + 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 diff --git a/src/shared/syscalls.h b/src/shared/syscalls.h index 403d02c..9587e78 100644 --- a/src/shared/syscalls.h +++ b/src/shared/syscalls.h @@ -24,6 +24,8 @@ enum { _SYSCALL_FS_RESPOND, _SYSCALL_MEMFLAG, + + _SYSCALL_DEBUG_KLOG, }; int _syscall(int, int, int, int, int); @@ -78,3 +80,5 @@ int _syscall_fs_respond(char __user *buf, int ret); * @return address of the first affected page (usually == addr) */ void __user *_syscall_memflag(void __user *addr, size_t len, int flags); + +void _syscall_debug_klog(const void __user *buf, size_t len); |