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

被折叠的 条评论
为什么被折叠?



