第1部分:System cakk tracing
主要任务是在进行系统调用时,打印出系统调用的名字和返回值。
当你实现后,启动时输出如下(执行sh.c):
...
fork -> 2
exec -> 0
open -> 3
close -> 0
$write -> 1
write -> 1
实现思路:
系统调用函数在syscall.c中,主要是在syscall函数内添加printf语句。
//系统调用对应名字数组
static char syscalls_name[][10] = {
[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_date] "date",
};
void
syscall(void)
{
int num;
num = proc->tf->eax; //获取系统调用号
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {