From 283d5ab4c964ab525e45fcade06d6fd7e977c43e Mon Sep 17 00:00:00 2001 From: Mole Shang <135e2@135e2.dev> Date: Thu, 18 Jan 2024 17:35:27 +0800 Subject: lab syscall: finish Conflicts: kernel/syscall.c kernel/syscall.h user/user.h user/usys.pl --- kernel/syscall.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'kernel/syscall.c') diff --git a/kernel/syscall.c b/kernel/syscall.c index beea0ef..4907f0f 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -101,6 +101,8 @@ extern uint64 sys_unlink(void); extern uint64 sys_link(void); extern uint64 sys_mkdir(void); extern uint64 sys_close(void); +extern uint64 sys_trace(void); +extern uint64 sys_sysinfo(void); #ifdef LAB_NET extern uint64 sys_connect(void); @@ -139,6 +141,35 @@ static uint64 (*syscalls[])(void) = { #ifdef LAB_PGTBL [SYS_pgaccess] sys_pgaccess, #endif +[SYS_trace] sys_trace, +[SYS_sysinfo] sys_sysinfo, +}; + +// syscall name maps for SYS_trace: +static char *syscall_names[] = { +[SYS_fork] "fork", +[SYS_exit] "exit", +[SYS_wait] "wait", +[SYS_pipe] "pipe", +[SYS_read] "read", +[SYS_kill] "kill", +[SYS_exec] "exec", +[SYS_fstat] "fstat", +[SYS_chdir] "chdir", +[SYS_dup] "dup", +[SYS_getpid] "getpid", +[SYS_sbrk] "sbrk", +[SYS_sleep] "sleep", +[SYS_uptime] "uptime", +[SYS_open] "open", +[SYS_write] "write", +[SYS_mknod] "mknod", +[SYS_unlink] "unlink", +[SYS_link] "link", +[SYS_mkdir] "mkdir", +[SYS_close] "close", +[SYS_trace] "trace", +[SYS_sysinfo] "sysinfo", }; @@ -154,6 +185,13 @@ syscall(void) // Use num to lookup the system call function for num, call it, // and store its return value in p->trapframe->a0 p->trapframe->a0 = syscalls[num](); + + // SYS_trace: match all the syscalls which number < mask asked + // p->trace_mask == 1 << SYS_xxx + if(p->trace_mask >> num) { + printf("%d: syscall %s -> %d\n", p->pid, syscall_names[num], p->trapframe->a0); + } + } else { printf("%d %s: unknown sys call %d\n", p->pid, p->name, num); -- cgit v1.2.3