移动端网站构成要素,sem网络推广是什么,用织梦做的企业网站,点子网创意网文章目录 前言其他篇章参考链接0. 前置准备1. System call tracing (moderate) 前言
好像没啥前言
其他篇章
环境搭建 Lab1:Utilities
参考链接
官网链接 xv6手册链接#xff0c;这个挺重要的#xff0c;建议做lab之前最好读一读。 xv6手册中文版#xff0c;这是几位先… 文章目录 前言其他篇章参考链接0. 前置准备1. System call tracing (moderate) 前言
好像没啥前言
其他篇章
环境搭建 Lab1:Utilities
参考链接
官网链接 xv6手册链接这个挺重要的建议做lab之前最好读一读。 xv6手册中文版这是几位先辈们的辛勤奉献来的呀再习惯英文文档阅读我还是更喜欢中文一点开源无敌 官方文档
0. 前置准备
很惭愧以前github用得少这一步折腾了老半天我再说一遍我个人的开发流程——先在windows下git一个本地仓库然后用VS编辑写完后git push上去在WSL的对应地方git pull下来然后编译运行。
前面环境配置中我为了连接到我个人的远程仓库是直接把原本的远程仓库删了的然后lab1做完做到lab2发现这个lab整体不是循序渐进的而是彼此分离的每个实验需要选择相应的分支因此就要重新弄一下 git remote add base git://g.csail.mit.edu/xv6-labs-2022git fetch basegit checkout syscallgit push --set-upstream origin syscall当然别忘了加.gitignore
1. System call tracing (moderate)
gdb教学我就不说了看看这个task。 先简单研究一下我们需求的这个trace是干什么的吧trace顾名思义tracing追踪、寻迹的意思比如ray tracing就是光线追踪这个命令接受一个传参mask内涵是一个掩码每一位对应一个系统调用的一个序号比如传入32代表 32 1SYS_read2147483647 代表追踪所有syscall具体的这些值定义在了kernel/syscall.h里我们待会也会写 初步了解之后就写实现吧这个task按照hint的步骤来很清晰 Add $U/_trace to UPROGS in Makefile 首先添加makefile司空见惯了。 Run make qemu and you will see that the compiler cannot compile user/trace.c, because the user-space stubs for the system call don’t exist yet: 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. Once you fix the compilation issues, run trace 32 grep hello README; it will fail because you haven’t implemented the system call in the kernel yet. 然后说这个时候make会找不到trace我们要在用户态user/user.h里加上trace的声明根据原文 It should take one argument, an integer “mask”, whose bits specify which system calls to trace. 可知这玩意应该接受一个int然后返回也是一个int返回值其实不影响来着 然后我们在user/usys.pl下添加这么一行这里的意思是声明了一个trace系统调用的入口实际上这一段会为我们在usys.S中生成一段汇编代码。 然后在内核syscall.h中给它注册一个number Add a sys_trace() function in kernel/sysproc.c that implements the new system call by remembering its argument in a new variable in the proc structure (see kernel/proc.h). The functions to retrieve system call arguments from user space are in kernel/syscall.c, and you can see examples of their use in kernel/sysproc.c. 然后模仿着添加原型 这里简单解释一下后面这个syscalls数组可能很多人没有看懂这首先这是个static的不用说然后这是个函数指针的数组我一向很反感那些什么数组指针指针数组混着说的直接说成装指针的数组不就一目了然了吗函数返回值为uint64参数为void显然是为上面extern的那些函数准备的东西这些都比较简单后面的是个小feature了它本身叫作指派初始化器Designated Initializers来自C99意思就是给方括号里的那一位初始化为右边的值 但是可以看到C99的指派初始化器的形式是[N] expr的中间需要一个等号连接这里没有它是来自GCC私货原文出现在介绍指定初始化器的时候An alternative syntax for this that has been obsolete since GCC 2.5 but GCC still accepts is to write ‘[index]’ before the element value, with no ‘’. 意味着大家在自己使用时加个等号是更符合standard的写法。
然后叫我们仿照着kernel/sysproc.c里的其他函数给trace写一个定义进去
uint64
sys_trace(void)
{return 0;
}使用argint从寄存器取出用户传入的参数 int mask;if (argint(0, mask) 0) // 保存用户传入的参数return -1;