When there is a system call statement in the program and the program executes the system call, first use a soft interrupt instruction similar to int 80H to save the scene and the system call number, execute it in the kernel mode, and then restore the scene, each process There will always be two stacks, a kernel-mode stack and a user-mode stack. When an int interrupt is executed, the stack will be transferred from the user state to the kernel stack. Stack switching is required during system calls. Moreover, the kernel code does not trust users and requires additional checks. The return process of the system call has a lot of extra work, such as checking whether scheduling is needed, etc.
System calls generally need to save the context of the user program. When entering the kernel, the user mode registers need to be saved. The contents of these registers will be restored when the kernel mode returns to the user mode. This is a place of overhead. If you need to switch between different user programs, you will also need to update the cr3 register, which will change the address of each program's virtual memory to the physical memory mapping table, which is also a relatively high-burden operation.
When there is a system call statement in the program and the program executes the system call, first use a soft interrupt instruction similar to
int 80H
to save the scene and the system call number, execute it in the kernel mode, and then restore the scene, each process There will always be two stacks, a kernel-mode stack and a user-mode stack. When an int interrupt is executed, the stack will be transferred from the user state to the kernel stack. Stack switching is required during system calls. Moreover, the kernel code does not trust users and requires additional checks. The return process of the system call has a lot of extra work, such as checking whether scheduling is needed, etc.System calls generally need to save the context of the user program. When entering the kernel, the user mode registers need to be saved. The contents of these registers will be restored when the kernel mode returns to the user mode. This is a place of overhead. If you need to switch between different user programs, you will also need to update the cr3 register, which will change the address of each program's virtual memory to the physical memory mapping table, which is also a relatively high-burden operation.