Operating Systems Practice Question 5: System Call Trap
Operating Systems · Test 1 · question 5 of 10
A user program calls read() to read bytes from a file. The program runs in user mode, where the CPU will not let it issue I/O instructions directly. How does the request reach the operating system?
Show answer and explanation
Answer:
CPUs provide at least two modes. In user mode a program cannot perform privileged operations such as I/O; in kernel mode the OS can. To make a system call, the library wrapper for read() places the system-call number and arguments where the kernel expects them and executes a special trap instruction. The trap simultaneously raises the privilege level and jumps into the kernel, but only to the entry points listed in the trap table the OS set up at boot, so a program cannot jump to arbitrary kernel code. When the work is done, a return-from-trap instruction drops back to user mode and resumes the program.
Option B is wrong: if user code could raise its own privileges, there would be no protection at all. Only the hardware trap mechanism changes mode, and only into OS-chosen code.
Option C is wrong: an ordinary call does not change the privilege level, so the kernel code would run in user mode and fault on the first privileged instruction. Also, user programs cannot jump to kernel addresses directly.
Option D is wrong: the timer interrupt exists so the OS can regain control and switch processes, not as a request mailbox. System calls are synchronous traps, handled immediately.
Reference: OSTEP - Mechanism: Limited Direct Execution