要求实现一个调用跟踪的 trace,其中有一个地方我一开始没理解到 mask 是干嘛的(原文: You have to modify the xv6 kernel to print out a line when each system call is about to return, if the system call’s number is set in the mask. ),卡了2天(英语不够,google来凑);
1、修改 Makefile
add $U/_trace\
2、添加 syscall
add a prototype for the system call to user/user.h, a stub to user/usys.pl, and a syscall number to kernel/syscall.h. The Makefile invokes the perl script user/usys.pl, which produces user/usys.S, the actual system call stubs, which use the RISC-V ecall instruction to transition to the kernel.
3、添加 sys_trace()函数 kernel/sysproc.c
1 2 3 4 5 6 7 8 9 10
// lab2 trace uint64 sys_trace(void){ int n; structproc *p = myproc(); if (argint(0,&n)<0) return-1; p->mask = n; return0; }
4、修改 fork 函数 kernel/proc.c
以防万一,修改的时候mask还是上锁了,mask 其实是每个 process 的 private 信息应该,但是上锁无伤大雅感觉,就放到了release前边儿
// Create a new process, copying the parent. // Sets up child kernel stack to return as if from fork() system call. int fork(void) { int i, pid; structproc *np; structproc *p = myproc();