operating-systems

Definition

Trap

A trap (synchronous interrupt) is an exception generated by the CPU as a direct result of the current instruction. Synchronous events occurring at deterministic points in code execution.

Causes

Error Traps

Triggered by illegal operations:

  • Division by zero
  • Invalid machine code (illegal opcode)
  • Memory access violations (segmentation faults)

Service Traps

Intentional triggers requesting OS services:

Mode Switching

Hardware-Assisted Transition

When a trap occurs, hardware automatically performs a mode switch to Kernel Mode, allowing the OS to handle the error or fulfil the service request.