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.
13 // Return 0 if the fault was not handled, 1 if it was handled.
16 pgfault(struct UTrapframe
*utf
)
18 void *addr
= (void *) utf
->utf_fault_va
;
19 uint32_t err
= utf
->utf_err
;
22 // Check that the faulting access was (1) a write, and (2) to a
23 // copy-on-write page. If not, return 0.
25 // Use the read-only page table mappings at vpt
26 // (see <inc/memlayout.h>).
28 // LAB 4: Your code here.
30 // Allocate a new page, map it at a temporary location (PFTEMP),
31 // copy the data from the old page to the new page, then move the new
32 // page to the old page's address.
34 // You should make three system calls.
35 // No need to explicitly delete the old page's mapping.
37 // LAB 4: Your code here.
39 panic("pgfault not implemented");
45 // Map our virtual page pn (address pn*PGSIZE) into the target envid
46 // at the same virtual address. If the page is writable or copy-on-write,
47 // the new mapping must be created copy-on-write, and then our mapping must be
48 // marked copy-on-write as well. (Exercise: Why do we need to mark ours
49 // copy-on-write again if it was already copy-on-write at the beginning of
52 // Returns: 0 on success, < 0 on error.
53 // It is also OK to panic on error.
56 duppage(envid_t envid
, unsigned pn
)
60 // LAB 4: Your code here.
61 panic("duppage not implemented");
66 // User-level fork with copy-on-write.
67 // Set up our page fault handler appropriately.
69 // Copy our address space and page fault handler setup to the child.
70 // Then mark the child as runnable and return.
72 // Returns: child's envid to the parent, 0 to the child, < 0 on error.
73 // It is also OK to panic on error.
76 // Use vpd, vpt, and duppage.
77 // Remember to fix "thisenv" in the child process.
78 // Neither user exception stack should ever be marked copy-on-write,
79 // so you must allocate a new page for the child's user exception stack.
84 // LAB 4: Your code here.
85 cprintf("fork not implemented, falling back to dumbfork\n");
93 panic("sfork not implemented");