CS 332 w22 — Lab 4
1 What do each of the handle_page_fault()
parameters do?
fault_addr
is the virtual address that triggered the fault
present
is 0 if there is no corresponding physical page present in memory or non-zero if there is
write
is 0 if the access was a read, and non-zero if it was a write
user
is 0 if the access occurred in the kernel, and non-zero if it occurred in user mode
2 How do we allocate more memory?
- use
pmem_alloc()
to allocate a new physical page like stack_setup()
does
3 What is the size in as_find_memregion
?
- I would recommend using the minimum size of a memory access (i.e., 1 byte)
4 What error should we return if memregion_extend()
fails?
sbrk
returns ERR_NOMEM
on failure
5 Should the program always exit then panic?
- Only if the fault is not recovereable (i.e., you can allocate a physical page for a memory access that was valid other than being to a non-present page, but other invalid accesses should exit or panic)
6 When checking if a given address is valid, is it enough to check if it is within range of the stack or the heap? Should there be other checks?
- Checking that the address is in either of those regions should be sufficient for this lab
7 Is there a certain limit on how big the heap can be? And if so, what is it?
- Only limited by the size of virtual memory (checking for overlapping regions should be sufficient)
8 What exactly is argv
in stack_setup
supposed to be? What is it used for?
- It is for setting up command-line arguments, a feature that does not currently exist in
osv
(and which you are not required to implement)
9 Are we supposed to set the permissions for a page after it's created (so that it would be "present" in the future)?
vpmap_map
takes permissions, these should be the same as the region fault_addr
is in
10 How do we check that whether the extended memory region overlaps with other regions in the address space?
- Loop over the list of regions and use the starting and ending addresses of those regions
11 In handle_page_fault
, How do we distinguish if the user is trying to extend the stack or the heap?
- Use the starting and ending addresses of those regions
12 Is fault_addr
in the page fault handler the address where we should allocate the page?
13 Are we giving the heap an entire page or are we just extending it slightly?
sbrk
can try and grow or shrink the heap by an arbitrary number of bytes, but the page fault handler should always be allocating an entire page