Analyzing the System_call interrupt processing process

Source: Internet
Author: User

Name: Wang Chenguang

Study No.: 20133232

Wang Chenguang "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

The idea of this experiment is relatively simple. we add the Getpid () function to the previous menuos, then break the point at Getpid and see how the system call works in detail.

First, the experimental steps

The lab environment is a lab building virtual machine environment that is configured using this course, open the command line client, CD Linuxkernel directory, use the command rm-rf menu to remove the original code, use Git clone https://github.com/mengning/ Menu.git Gets the latest menu code, then the CD menu enters the menu subfolder, uses VI test.c to open the file, copies the code from last week's experiment into TEST.C, constructs two functions, and becomes the menu's two menu items. The experiment is as follows:

Add two lines of command to the main () function

The first time you add two lines of command to the main function, the code is incorrectly entered as a result of carelessness.

Modify and enter make Rootfs compile run. The results are as follows:

You can see the current PID when you enter Getpid

Then hit the breakpoint on the sys_getpid.

In the end we found that we could not continue to follow the debug code, here System_call () is not a normal function, GDB does not stop here.

Second, analysis System_call processing process

In the Start_kernel function, the Trap_init function is the completion of the system call initialization. In the Trap_init () function, the System_call function and the 0x80 are bound by the interrupt vector. Thus, the user-state code is handled by the System_call function as long as the int 0x80 interrupt is performed. The key code that is consulted is as follows:

#ifdef config_x86_32   .    Set_system_trap_gate (Syscall_vector, &system_call);   Geneva .    Set_bit (Syscall_vector, used_vectors);   . #endif  

Consult the relevant information on the Web and video of the teacher, you can get the following flowchart to show the flow of System-call:

My understanding is: The System_call function finds the system call table through the system call number to find the specific system call service process, and before executing the system call, the kernel does a series of checks to see if there is a new interrupt.

Third, the experiment experience and summary

The idea of this experiment is very simple, but the operation is still some tips, because their carelessness always in the input command or code error, but fortunately, in reference to some information and video, the entire experiment completed, but also to System_call's work flow has a certain understanding. From the overall process, the system enters the kernel state from the user state via the int 0x80. In this process, the system first saves the interrupt environment and then executes the system call function. By associating the int 0x80 and system_call with the interrupt vector table, the System_call is also associated with each system call and a specific system invocation service routine through the system call number.

Analyzing the System_call interrupt processing process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.