Skip to content

Commit

Permalink
syscall: log when unimplemented syscall is invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
mosmeh committed Sep 4, 2024
1 parent 8c97847 commit 96d67d0
Show file tree
Hide file tree
Showing 4 changed files with 383 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/cmdline.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ The kernel command-line parameters are in the form of `key=value`, where the `=v
- `console=<device>`: The device to use as the system console `/dev/console`. The default is `tty1`.
- `nosmp`: Disables symmetric multiprocessing.
- `font=<path>`: The path to the PSF font file to use for the framebuffer console. The default is `/usr/share/fonts/default.psf`.
- `ni_syscall_log`: Log a message when an unimplemented system call is invoked.
4 changes: 2 additions & 2 deletions kernel/api/sys/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#define SYSCALL_VECTOR 0x80

// The syscall numbers are defined in the Linux kernel source code:
// arch/x86/entry/syscalls/syscall_32.tbl
// The syscall numbers are in sync with Linux:
// arch/x86/entry/syscalls/syscall_32.tbl in the Linux kernel source.
#define SYS_exit 1
#define SYS_fork 2
#define SYS_read 3
Expand Down
17 changes: 16 additions & 1 deletion kernel/syscall/syscall.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "syscall.h"
#include "unimplemented.h"
#include <kernel/api/sys/reboot.h>
#include <kernel/api/sys/syscall.h>
#include <kernel/api/unistd.h>
Expand Down Expand Up @@ -62,18 +63,32 @@ int sys_dbgprint(const char* user_str) {
return kprint(user_str);
}

#define F(num, name) \
static int sys_ni_##name(void) { \
if (cmdline_contains("ni_syscall_log")) \
kprint("syscall: " #name \
" (" STRINGIFY(num) ") is unimplemented\n"); \
return -ENOSYS; \
}
ENUMERATE_UNIMPLEMENTED_SYSCALLS(F)
#undef F

struct syscall {
uintptr_t handler;
unsigned flags;
};

static struct syscall syscalls[] = {
#define F(num, name) [num] = {(uintptr_t)sys_ni_##name, 0},
ENUMERATE_UNIMPLEMENTED_SYSCALLS(F)
#undef F

#define F(name, handler, flags) \
[SYS_##name] = { \
(uintptr_t)(handler), \
(flags), \
},
ENUMERATE_SYSCALLS(F)
ENUMERATE_SYSCALLS(F)
#undef F
};

Expand Down
Loading

0 comments on commit 96d67d0

Please sign in to comment.