A: open -> STUB(open) in usys.S -> trigger a interrupt T_SYSCALL -> idt[T_SYSCALL] -> vectors[T_SYSCALL] -> vector48 in vectors.S -> alltraps in trapasm.S -> trap() in trap.c -> syscall() in syscall.c -> sys_open() in sysfile.c
Q: xv6 usys.S (not in book). (No saving of registers. Why?)
A: It's one out of following three, tracking the code, all the information are reserved in trap frame, so No.3 :
- 法一:利用registers儲存參數, No
- 優:快速
- 缺:不適用於參數多時。
∵register數目有限,參數不能太多
- 法二:將參數存在memory中的某個表格或Block,同時將此表格的起始位址存在一個register中,將此register傳給OS:
- 優:適用於參數多時
∵ 可存參數較多 - 缺:速度較慢
∵不限制參數的數目與長度
- 優:適用於參數多時
- 法三:利用system stack保存參數
- push(保存)參數
- OS利用POP取出參數
- 不限制參數的數目及長度
examine registers and stack. How will the kernel find the argument to open?
A: Stored in trap frame.
Q: (Briefly) xv6 Sheet 52: sys_open uses argstr and argint to get its arguments. How do
they work?
A: Get the arguments from the stack of trap frame.
52 // Fetch the argno'th word-sized system call argument as an integer.
53 int
54 argint(int argno, int *ip)
55 {
56 struct proc *p = curproc[cpu()];
57
58 return fetchint(p, p->tf->esp + 4 + 4*argno, ip);
59 }
Q: What happens if a user program divides by zero or accesses unmapped memory?
Exception. Same path as system call until trap.
What happens if kernel divides by zero or accesses unmapped memory?
A: That will cause kernel panic