Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对lab4 trap的test3要求恢复a0的一点思考 #3

Open
hhzzll opened this issue Apr 13, 2024 · 1 comment
Open

对lab4 trap的test3要求恢复a0的一点思考 #3

hhzzll opened this issue Apr 13, 2024 · 1 comment

Comments

@hhzzll
Copy link

hhzzll commented Apr 13, 2024

这个alarm的实验应该是对照linux中的自定义信号处理函数(linux中的SIGALRM信号),我调试下面的代码并阅读linux内核arch/riscv/kernel/signal.c相关代码发现,linux会在用户栈保存进入信号处理函数前的trapframe,其中trapframe包含对sigreturn调用(sigreturn的调用在libc中,应该是libc在执行signal时把sigreturn传递给了内核?),这样handler执行完后就不需要手动调用sigreturn,也就是说,这个系统调用对用户来说是不可见的,handler不应该影响发生中断前的a0,用户也不关心sigreturn返回什么(测试是在x86下做的,但原理应该一样)。xv6降低了难度,在handler中手动调用sigreturn,但从实验的出发点看来应当恢复a0。
image
handler执行ret后跳转到下面的汇编代码
image
image

@sakura-ysy
Copy link
Owner

不好意思最近几个月在实习没关注 issue。刚看了眼觉得你说的蛮有道理,我写的时候也没有深入考虑这么多,感谢你的解释和订正,学到!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants