OS review---user mode and kernel mode

What is it

  • User mode : The non-privileged execution state can only complete general operations and tasks, and cannot directly access the hardware and software in the system, and its access to memory is also limited to user space. The kernel prohibits the code in this state from performing potentially dangerous operations, such as writing system configuration files, killing other user processes, and restarting the system.
  • Kernel mode : the mode in which the operating system kernel runs. Code running in this mode can access system storage and external devices without restrictions.

why

In order to limit the permissions of the user program, protect the security of the system, and ensure that the system is not damaged intentionally or unintentionally by the application program.

If the user runs some malicious programs, they may perform some dangerous operations. If the permissions of the user programs are not restricted, then these malicious programs may cause damage to the operating system.

How to convert user mode to kernel mode

System call

the reason

  • The system provides a protection mechanism to prevent applications from performing some sensitive operations to ensure system security
  • Certain functions of the application program must obtain the services provided by the operating system

System call This is a way for the user mode process 主动to switch to the kernel mode. The user mode process requests to use the service program provided by the operating system to complete the work through the system call. The core of the system call mechanism is implemented by using an interrupt that the operating system is particularly open to users, such as the int 80h interrupt of Linux.

abnormal

When the CPU is executing a program running in user mode , some unknowable exception occurs. At this time, it will trigger the switch from the current running process to the kernel-related program that handles this exception, and it will switch to the kernel mode, such as Page fault is abnormal.

Interrupt

Peripheral device interrupt: When the peripheral device completes the operation requested by the user, it will send a corresponding interrupt signal to the CPU. At this time, the CPU will suspend the execution of the next instruction to be executed and then execute the processing program corresponding to the interrupt signal. The previously executed instruction is a program in user mode, so this conversion process naturally switches from user mode to kernel mode. For example, when the hard disk read and write operations are completed, the system will switch to the interrupt handler for hard disk read and write to perform subsequent operations.

These three methods are the most important ways for the system to change from user mode to kernel mode during operation. The system call can be considered as initiated by the user process, while exceptions and peripheral device interrupts are passive .

Guess you like

Origin blog.csdn.net/why1092576787/article/details/114848154