Search code examples
linuxprocessoperating-systemlinux-kernelcontext-switch

Difference between software interrupt routine and user mode function


Well, my question is in the title

As we know, an exception handler routine is responsible for switching user mode into kernel mode
This involves certain assembly instructions

And this is claimed to be done in order to prevent the application from using high-privileged instructions and memory areas with restricted access

Can't the user-mode application perform this user-kernel switch by itself ? i.e using those assembly instructions, in a usual function routine within application itself ?

If so, then I cannot understand what's the point of software interrupts and all those security considerations related to user-kernel switch

We simply implement that switch in our program and voila! we are in the kernel mode now

WTH


Solution

  • You make a mistake: the only thing the user can do is call a routine which can execute privileged instructions. This is done by the software interrupt. It is called an interrupt because the original user mode program is stopped while the call is being handled. In this way, the user mode program is completely unable to execute special privileges, but it can call interrupt routines in the kernel which can. Never is the program itself in kernel mode.