[xv6-kernel] Lab3: Memory management

Kieun Kim·2021년 8월 3일
0

xv6-kernel

목록 보기
4/4

Part 1: changing memory layout

  • In xv6, the VM system uses a simple two-level page table
    • code
    • stack : fixed sized, one-page
    • heap : grows towards the high-end of the address space
  • We should rearrange the address space to look more like Linux
    • code
    • heap : grows towards the high-end of the address space
    • stack : At end of address space ; grows backwards
  • Q
    • Read chapter 2 in the xv6 book. Briefly explain the operation of allocuvm() and mappages() and Figure 1-2. Check how exec uses them for an idea.
    • Explain how you would given a virtual address figure out the physical address if the page is mapped otherwise return an error. In other words, how would you find the page table entry and check if its valid, and how would you use it to find the physical address.
    • Find where in the code we can figure out the location of the stack.
  • Exec : To change the memort layout, we should change the exec code for loading th program and allocating the stack in the new way that we want
    • It opens the named binary path using namei and reads ELF header
    • An ELF binary
      • struct elfhdr
      • a sequence of program section header : it must be loaded into memory
        • xv6 has only one program section header
    • Quick check that the file contains an ELF binary
      • ELF binary starts with the 4-byte "magic number" 0x7F, "E", "L", "F", or ELF_MAGIC
      • If ELF header has the right magic number, exec assumes that the binart is well-formed
    • Allocates a new page table with no user mappaings with setnpkvm
    • Allocates memory for each ELF segement with allocuvm
      • It checks that the virtulal address requested is located below KERENBASE
    • Loads each segment into memory with loaduvm
      • loaduvm uses walkpgdir to find physical address of the allocated memory at which to write each page table of the ELF segment and readi to read from the file
    • The program section header for /init
      • The first user program created with exec
    • Allocates and initializes the user stack
    • Allocates two pages at the next page boundary
      • The first page is just one stack page
      • Exec copies the argument strings to the top of the stack one at a time recording the pointers to them in ustack
      • The second page is inaccessible page just below the stack page
profile
Connecting dots

0개의 댓글