First, the experiment
Second, the system call Flowchart:
Third, Summary: System call Process Analysis LinuxSystem Call Procedure: User program→cLibrary (that is,API):INT 0x80→system_call→ system invoke service routine → Kernel program. We often say that the userAPIIt's actually a system-providedCLibrary.
System call is via soft interrupt instructionINT 0x80realized, and this oneINT 0x80instructions are encapsulated inCfunction in the library. The difference between soft interrupts and the hard interrupts that we often say is that soft interrupts are triggered by instructions, not by hardware peripherals. INT 0x80The execution of this instruction will cause the system to jump to a preset kernel space address, which points to the system call handler, i.e.System_callfunction. System Call HandlersSystem_callis not a system invoke service routine, the system invocation service routine is a kernel implementation function for a specific system call, and the system call handler is a boot process before the system invokes the service routine, which is forINT 0x80This instruction is intended for all system calls. Simply put, any system call is performed by invoking theCfunction in the library, there will be soft interrupts inside this function .INT 0x80statement, and then go to the Execute system call handlerSystem_call,System_callthen go to execute the specific system call service routine according to the specific system call number.
system_call function How to find the specific system call service routines? Find the system call table sys_call_table . Soft interrupt instruction int 0x80 system _call function can read eax register get and multiply it by 4 sys_call_table .
Then the system invokes the service routine. It is necessary to note that the system invoke service routine only takes parameters from the stack, so the parameters are stored in the register before System_call execution,system_call These registers are first pressed onto the stack when they are executed. after the system_call exits, the user can obtain (modified) parameters from the register.
It should be noted that the system calls the 0x80 into the kernel through the soft interrupt INT , jumps to the system call handler system_call function, and then executes the corresponding service routine. However, because it represents the user process, the execution process is not part of the interrupt context, but the process context. Therefore, during system call execution, many of the information that can be accessed by the user process can be preempted by other processes and can hibernate.
Once the system call is complete, the kernel will be dispatched once the control is handed back to the user process that initiated the call. If you find that a higher priority process or the current process has run out of time slices, you will select a higher priority process or re-select the process execution.
Linux Kernel Learning Fifth week system call