
我从来没想过用它写自己的项目代码,因为自己的项目就是学习、娱乐用的,所以不能让他代替我来学习和娱乐。但是我发现有什么不清楚的地方,他真能和我掰扯的挺深的。
其实我和他掰扯的东西吧,严格来说都在教材和手册里,但是自己看的时候零零散散,只有在做项目的时候才能想办法串起来,这时候 ChatGPT 真是一个好帮手。
举一个问答的例子,请大家忽略 AI 的过度鼓励:
Question: I found it interesting. The kernel land call stack is like: usertrap()->syscall()->sys_sigreturn(), and I check in sys_sigreturn that ra is 0x30 and I cannot access it from kernel, so it must be the user land ra, and this agrees with your explanation that the kernel ra lives withint the kernel's own call stack. But if this is the case, how do I get the kernal ra in sys_sigreturn()?
Answer: Love that you’re poking at this; this is exactly the right “x-ray vision” for xv6/riscv.
Short answer: in sys_sigreturn() there are two different “return addresses” in play:
the kernel’s own ra (for sys_sigreturn -> syscall), and the user’s saved ra in the trapframe (p->trapframe->ra).
You’ve accidentally grabbed (2)
Let’s untangle it cleanly.
You said:
I check in sys_sigreturn that ra is 0x30 and I cannot access it from kernel, so it must be the user land ra
If you’re literally in sys_sigreturn() and GDB shows:
(gdb) info reg ra ra 0x30 two possibilities:
You’re not actually stopped where you think you are.
More likely: you’re not looking at the CPU register for kernel ra, you’re looking at the trapframe field (p->trapframe->ra), which is the user’s ra, and 0x30 is a perfectly plausible low VA in user code.
它说的一点也没错,一下子就把我给点醒了。很多时候纠结一个问题,不是自己不知道,而是因为不熟悉,不知道朝什么地方看。
当然我这也是好几天没做出来才用 AI 的,这玩意好用是好用,但是还是有限度的用比较好。