Exceptions
Control Flow
- we currently use a state-based control flow that is completely dependent on the instructions that happens before
- we need to have some sort of reactivity, that could be accomplished either through polling (slow) or exceptional control flow
Exceptional Control Flow
- change the control flow in the system in response to a system event → throw exceptions
- exceptions —> process context switches (OS/Hardware) and send signals (OS)
- Process context switch
- Implemented by OS software and hardware timer
- Signals (messages from operating system)
- Implemented by OS software
How do Exceptions Work
- an exception is a transfer of control to the OS kernel in response to some event
- for instance, lets say we run into a divide by 0 segfault, exception is thrown out and the OS will handle the instruction that is best fit
- exception tables will give us a handle over the different exceptions and will give us different approaches to solving the problems
- Basically think of a list of numbers that lead to different code for each of the issues that might arise
What is the Kernel Responsible For?
- Context Switch
- Enabling VM abstraction (also hardware)
Types of Exceptions
- asynchronous exceptions are caused by external processes to the processor (handler returns to next instruction once done)
- consider a timer that is done and pauses other processes and takes over
- consider copy paste that takes data from the network and pastes it
- synchronous exceptions → caused by executing an instruction
- traps are special intentional instructions that returns control to the next instruction
- consider a system call (breakpoints)
- registers contain the sycall number and other registers hold the arguments (return RAX) - negative return means fail
- faults are unintentional exceptions that can either redo the instruction or move on
- think of deviding by 0
- page fault → allocates memory if it has not been allocated already
- abort unintentional and unrecoverable which aborts the current program
System Calls