CS444 User-Kernel Transitions, showing stacks

Interrupt in user code (single-threaded process)

User space                     Kernel space

User execution: IF=1, CPU mode = user   Kernel execution: IF=0, mode = kernel after interrupt cycle

Rectangular Callout: This process’s
kernel stack
 

 


                              ___________________________________

____________________________    IDT  interrupt handler  process/thread stacks

      User code         user stack        (in kernel code)    (in kernel data)

     An interrupt can happen between

      any two instructions

Note: an interrupt can happen in kernel code too.

·         While the interrupt handler executes, it uses (“borrows”) the current process’s kernel stack.

System call from user code (single-threaded process)

User space                               Kernel space

User execution: IF=1, CPU mode = user    Kernel execution: IF=1, mode = kernel after trap cycle

 

Rectangular Callout: This process’s
kernel stack
 

 


                              ___________________________________

____________________________    IDT  syscall code     process/thread stacks

      User code         user stack    (in kernel code)     (in kernel data)

 C code      C lib read
 with call   in assembler
 to read 

·         While the syscall executes in the kernel, it uses (“legitimately”) the current process’s kernel stack.

 

·         A single-threaded process has one kernel stack, for its one thread, so we can say it’s the process’s kernel stack. A multi-threaded process has multiple user thread stacks and multiple kernel stacks.

Interrupt in user code (multi-threaded process, 2 threads)

User space                     Kernel space

User execution: IF=1, CPU mode = user   Kernel execution: IF=0, mode = kernel after interrupt cycle

 

 


                              ___________________________________

____________________________    IDT  interrupt handler  thread stacks

      User code      user stacks        (in kernel code)    (in kernel data)

·         While the interrupt handler executes, it uses (“borrows”) the current thread’s kernel stack.

 

System call from user code (multi-threaded process)

User space                               Kernel space

User execution: IF=1, CPU mode = user    Kernel execution: IF=1, mode = kernel after trap cycle

User execution: IF=1, CPU mode = user   Kernel execution: IF=0, mode = kernel after interrupt cycle

 

 


                              ___________________________________

____________________________    IDT  syscall code      thread stacks

C code      C lib read
with call   in assembler
to read 

·         While the syscall executes in the kernel, it uses (“legitimately”) the current thread’s kernel stack.