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.

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
vmforkthat usesforkto create a child process and callsvmprintmappingsin 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
execon the mappings: create another user-space programvmprintthat callsvmprintmappings. Useexecin thevmforkprogram to replace the memory layout of the child process withvmprint. Analyze and explain the changes in the virtual memory mappings.