Look aside Buffer

Student Score / 100

True/False Questions [10 pts]

  1. After handling a fault successfully, the CPU goes (when it does go back) to the instruction immediately after the faulting one
  2. Interrupts are asynchronous events
  3. Memory limit protection (within a private address space using base and bound) is implemented in the hardware instead of software
  4. Memory limit protection checks are only performed in the User mode
  5. Translation Look-aside Buffer (TLB) is a cache for popular (i.e., recently used) page table entries
  6. Divide by 0 is an example of a fault
  7. Every process has its own page table
  8. A process cannot access its own page table
  9. Trap is a type of synchronous exception
  10. Faults are unintentional but possibly recoverable

[10 pts] Which of the following are privileged operations allowed only in Kernel mode?

  1. Setting 0 to a large chunk of memory (i.e., using the memset function)
  2. Modifying the page table entries
  3. Disabling and Enabling Interrupts
  4. Using the "trap" instruction
  5. Directly accessing I/O devices
  6. Handling an Interrupt
  7. Issuing a system call
  8. Changing the processor’s execution mode to User mode
  9. Divide by zero
  10. Clearing the Interrupt Flag

Short Questions

[5 pts] Why is the process state (i.e., PC, SP, EFLAGS, general registers) kept in the Kernel Interrupt Stack before handling an Interrupt? Why could we not store it in the user memory? What is the risk?

[5 pts] Describe the attack scenario of how an interrupted process can manipulate the process state in the above question. Note that this is from the Textbook 1 – we did not discuss this in class.

[5 pts] While implementing the process state diagram, what is the problem of having only 1 queue for all blocked processes waiting for all events? What is the solution to this problem? Describe with an example.

[5 pts] What is the difference between the "New" state and the "Ready to Run" state in the process state diagram?

[5 pts] Is a transition from the "Blocked" state to directly to the "Exit" state possible in the process state diagram? How?

[5 pts] Assume that the following physical memory is full with already allocated 5 pages as shown below (i.e., it is 20KB in capacity). Describe what happens if process 2 wants to allocate and use another page. What changes in the page tables and the physical memory?

(a) [10 pts] The following are steps in a “sequential” Interrupt handling. What changes would you make in the steps below so that “nested” Interrupts can be handled?

Hardware does the following:

1. Mask further interrupts

2. Change mode to Kernel

3. Copy PC, SP, EFLAGS to the Kernel Interrupt Stack (KIS)

4. Change SP: to the KIS (above the stored PC, SP, EFLAGS)

5. Change PC: Invoke the interrupt handler by vectoring through the Interrupt Vector Table (i.e., overwrite PC with the handler PC)

Software (i.e., the handler code) does the following:

1. Stores the rest of the general-purpose registers being used by the interrupted process

2. Does the rest of interrupt handling operation?

(b) [3 pts]: Can you interchange steps 2 and 3? Why or why not?

(c) [2 pts]: Can we interchange step 1 with step 2? Why or why not?

[20 pts] (a) Write the steps in a system call to read a byte from the keyboard. Refer to page 31 of Lecture 05 as a starting point. However, note that this will require more steps because the user may not type anything in the keyboard immediately. What is the state of the process while it is waiting for the keyboard input? How does it come back to the CPU? Discuss with the help of Process State Diagram.

(b) Now repeat the above when the user presses Ctrl+C from the keyboard without providing a valid input? How does this process navigate the process state diagram?

[15 pts] What is the output of the following program? Assume that the first processes pid=x, and every subsequent process’s pid increases by 1, because that is how usually PIDs are assigned. Explain the output that you observe after running the program using a diagram.

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

{`void main (){
    for (int i=0; i<3; i++)
        fork();
        printf ("PID: %d\n" getpid());
        wait ();
    }`}