Some key facts about virtual memory:
- All addresses manipulated by assembly instructions are virtual addresses. Assembly instructions never manipulate physical addresses.
- The translation from a virtual address to a physical address is done automatically by the MMU (Memory Management Unit) based on the information mapping stored in the page directory. The page directory can be stored anywhere in memory and its location is stored in the CR3 pointer.
- The kernel page directory maps the entire memory space so all adresses are valid and accessible. However, the user programs have a sparse page directory mapping and not all adresses are valid because not accessible (not mapped).
- A page number x in the kernel page directory might corresponds to a different page number in the user program.
Example of passing arguments:
Questions:
- Where are the command line arguments stored when they are initially passed into the program?
-
When passing command-line arguments to a program, in which order should the arguments be pushed onto the user program stack?
- Which method is responsible for setting up the stack of a user program? In other words, when and where are the pages allocated for the user program?
-
What is the (virtual) address of the beginning of the stack when the kernel thread is executing the user’s program in user mode (when running the user program for instance)?
-
What is the (virtual) address of the beginning of the stack when the kernel thread is setting/accessing that stack in kernel mode (when executing a system call for instance)?
-
Where is the page directory store for each process?
-
Which function do you use to translate a “user address” into a “kernel address”?
- When a system call is executed and a user address is passed as an argument, how do you know whether this is a valid user address?