Page tables

Easy

xv6 book Sect 3.6 Process address space

The vmprintmappings system call can be used to inspect a process’s page table. When executed, it prints an overview of the valid page table entries (PTEs), including address translations, privilege levels, and access permissions. It uses the following format:

{va} -> {pa}, mode={U|S}, perms={r|-}{w|-}{x|-}

where

  • va represents the virtual address of the page;
  • pa is the physical address of the corresponding frame;
  • mode indicates whether the page is a user page (U) or a supervisor (kernel) page (S);
  • perms defines the permissions for the page, combining the following flags:
    • r for readable
    • w for writable
    • x for executable
    • - indicates the absence of the corresponding permission.

The vmprintmappings system call is implemented by the function vmprintmappings.

Task

Add a call to the vmprintmappings system call in the user-space program user/hello.c from the first lab session and run the program in the QEMU emulator via the xv6 shell. Compare the output with Figure 3.4 from the xv6 book.

xv6-process-address-space

Next, modify the implementation by inserting a vmprintmappings call both before and after a call to sbrk(1). Run the updated program again, and analyze the differences between the outputs from both executions. Provide an explanation of the changes observed.

Revisiting fork and exec

After a process is forked using fork, both the parent and child processes will have the same virtual memory addresses mapped. However, the values stored at these addresses can sometimes differ.

  • Explain this based on your understanding of virtual memory.
  • Write a new user-space xv6 program vmfork that uses fork to create a child process and calls vmprintmappings in both the child and the parent. Examine the output and explain the similarities and differences between the mappings in the parent and child processes.
  • Observe the effect of exec on the mappings: create another user-space program vmprint that calls vmprintmappings. Use exec in the vmfork program to replace the memory layout of the child process with vmprint. Analyze and explain the changes in the virtual memory mappings.

This site uses Just the Docs, a documentation theme for Jekyll.