kernelcpu-architectureprocessorinstruction-setkernel-mode

Kernel mode for user program


I am aware that Kernel mode is a privileged such that in kernel mode all hardware capabilities and all instructions in instruction set are available. I am also aware that when we make a procedure call (say read()) it in turn makes a system call. But before that it Traps into Kernel mode. I wanted to know what use would having Kernel mode serve if every user program can run in Kernel mode as all procedure calls and system calls are available to user programs.


Solution

  • The problem about hardware, files and other safety-critical parts of OS is that they should be operated only in a correct way, otherwise the OS would be damaged (or other bad things would happen).

    Without the kernel-user separation an application itself provides a code which works with OS-critical parts. An this code could be any. Thus, a malformed application could potentially damage an OS.

    With kernel-user separation the only way for an application to touch a hardware is a system calls. This allows to run only a limited code which works with a safety-critical parts of OS. An application has no way to modify that code.

    So, having correctly written the code which handles system calls, an OS protects its critical parts from the malformed applications.