Exception
youngwiki
개요

Exception이란 특정 이벤트가 발생함에 따라 OS kernel로 Control을 이동시키는 것을 의미한다. 이때 exception이 발생하면 커널[1]에서 exception handler를 통해서 이를 처리한다.
- 예시: 0나누기 / 오버플로우 / page fault[2] / I/O request completion / Ctrl - C
또한 Exception table이란 예외 발생시 해당 예외를 처리하는 Exception Handler의 주소를 저장하는 데이터 구조를 의미한다. 각각의 Exception은 고유한 예외 코드 K를 가지고 있으며, exception handler K는 해당 예외가 발생시 Exception Table에 저장된 주소를 통해 호출된다.
종류
| Class | Cause | Async/sync | Return behavior |
|---|---|---|---|
| Interrupt | Signal from I/O Device | Async | Always returns to next instruction |
| Trap | Intentional exception | Sync | Always returns to next instruction |
| Fault | Potentially recoverable error | Sync | Might returns to current instruction |
| Abort | Non recoverable error | Sync | Never returns |
Interrupts (Asynchronous Exceptions)
Interrupts는 프로세서 외부에서 발생하는 이벤트에 의해 발생한다.[3]
CPU에는 물리적인 Interrupt Pin이 따로 존재하며, 해당 핀의 신호가 0 ->1로 바뀌면 인터럽트를 감지한다. 이를 Interrupt Handler가 처리하고 다시 next instruction으로 돌아간다.
Synchronous Exception
instruction을 실행시킴으로서 발생한 결과에 의한 이벤트에 의해서 발생하기 때문에 동기적으로 처리된다.