1 // implement fork from user space
3 #include <inc/string.h>
6 // PTE_COW marks copy-on-write page table entries.
7 // It is one of the bits explicitly allocated to user processes (PTE_AVAIL).
11 // Custom page fault handler - if faulting page is copy-on-write,
12 // map in our own private writable copy.
15 pgfault(struct UTrapframe
*utf
)
17 void *addr
= (void *) utf
->utf_fault_va
;
18 uint32_t err
= utf
->utf_err
;
21 // Check that the faulting access was (1) a write, and (2) to a
22 // copy-on-write page. If not, panic.
24 // Use the read-only page table mappings at vpt
25 // (see <inc/memlayout.h>).
27 // LAB 4: Your code here.
29 // Allocate a new page, map it at a temporary location (PFTEMP),
30 // copy the data from the old page to the new page, then move the new
31 // page to the old page's address.
33 // You should make three system calls.
34 // No need to explicitly delete the old page's mapping.
36 // LAB 4: Your code here.
38 panic("pgfault not implemented");
42 // Map our virtual page pn (address pn*PGSIZE) into the target envid
43 // at the same virtual address. If the page is writable or copy-on-write,
44 // the new mapping must be created copy-on-write, and then our mapping must be
45 // marked copy-on-write as well. (Exercise: Why do we need to mark ours
46 // copy-on-write again if it was already copy-on-write at the beginning of
49 // Returns: 0 on success, < 0 on error.
50 // It is also OK to panic on error.
53 duppage(envid_t envid
, unsigned pn
)
57 // LAB 4: Your code here.
58 panic("duppage not implemented");
63 // User-level fork with copy-on-write.
64 // Set up our page fault handler appropriately.
66 // Copy our address space and page fault handler setup to the child.
67 // Then mark the child as runnable and return.
69 // Returns: child's envid to the parent, 0 to the child, < 0 on error.
70 // It is also OK to panic on error.
73 // Use vpd, vpt, and duppage.
74 // Remember to fix "thisenv" in the child process.
75 // Neither user exception stack should ever be marked copy-on-write,
76 // so you must allocate a new page for the child's user exception stack.
81 // LAB 4: Your code here.
82 panic("fork not implemented");
89 panic("sfork not implemented");