Jos-lab5 (下)

本文详细介绍了如何在操作系统层面实现内存页的共享映射,包括通过修改页表条目来复制内存映射,以及如何处理键盘和串口的中断请求。通过具体的代码示例,展示了如何在子进程中复制父进程的共享页面,并实现了特定中断的处理。

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

Exercise 4. Change duppage in lib/fork.c to follow the new convention. If the page table entry has thePTE_SHARE bit set, just copy the mapping directly. (You should use PTE_SYSCALL, not 0xfff, to mask out the relevant bits from the page table entry.0xfff picks up the accessed and dirty bits as well.)

Likewise, implement copy_shared_pages inlib/spawn.c. It should loop through all page tableentries in the current process (just likeforkdid), copying any page mappings that have thePTE_SHARE bit set into the child process.

@@ -69,7 +69,11 @@ duppage(envid_t envid, unsigned pn)
        void *addr = (void *)(pn * PGSIZE);
        pte_t pte = uvpt[PGNUM(addr)];
 
-       if ((pte & PTE_W) > 0 || (pte & PTE_COW) > 0) {
+       // LAB 5: Jacky 140223
+       if ((pte & PTE_SHARE) > 0) {
+               if ((r = sys_page_map(0, addr, envid, addr, (pte & PTE_SYSCALL))) < 0)
+                       panic("%s,%d failed: %e\n",__func__,__LINE__,r);
+       } else if ((pte & PTE_W) > 0 || (pte & PTE_COW) > 0) {

 copy_shared_pages(envid_t child)
 {
        // LAB 5: Your code here.
+       struct Env *env;
+       int r, i;
+//     if ((r = envid2env(child, &env, 1)) < 0)
+//             panic("%s() %d failed: %e\n",__func__,__LINE__,r);
+       for (i = 0; i < UTOP; i += PGSIZE) {
+               if ((uvpd[PDX(i)] & PTE_P) && (uvpt[PGNUM(i)] & PTE_P) && ((uvpt[PGNUM(i)
+                       if ((r = sys_page_map(0, (void *)i, child, (void *)i, (uvpt[PGNUM
+                               return r;
+               }
+       }

Exercise 5. In your kern/trap.c, call kbd_intr to handle trap IRQ_OFFSET+IRQ_KBD and serial_intr to handle trapIRQ_OFFSET+IRQ_SERIAL.

+       // Handle keyboard and serial interrupts.
+       // LAB 5: Your code here.
+               case IRQ_OFFSET + IRQ_KBD:
+                       kbd_intr();
+                       return;
+               case IRQ_OFFSET + IRQ_SERIAL:
+                       serial_intr();
+                       return;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值