Jos - L6 notes

本文详细解析了xv6操作系统中的系统调用实现机制,包括open函数的具体流程、参数传递方式以及如何处理除零错误和未映射内存访问等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Q: xv6 Sheet 16: init.c calls open("console"). How is that implemented?

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 :

  1. 法一:利用registers儲存參數, No
    • 優:快速
    • 缺:不適用於參數多時。
      ∵register數目有限,參數不能太多
  2. 法二:將參數存在memory中的某個表格或Block,同時將此表格的起始位址存在一個register中,將此register傳給OS:
    • 優:適用於參數多時
      ∵ 可存參數較多
    • 缺:速度較慢
      ∵不限制參數的數目與長度
  3. 法三:利用system stack保存參數
    • push(保存)參數
    • OS利用POP取出參數
    • 不限制參數的數目及長度
Q:xv6 Sheet 28: in vectors.S briefly, then in alltraps. Step through to call trap,
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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值