Linux Kernel Analysis-experiment five Analysis system_call interrupt processing process

Source: Internet
Author: User

Zheng Bin + Original works reproduced please specify the source + "Linux kernel analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

Experimental requirements:

    • Using GDB trace to parse a system call kernel function (the one you selected last week), the system invocation list see http://codelab.shiyanlou.com/xref/linux-3.18.6/arch/x86/syscalls/ SYSCALL_32.TBL, it is recommended to complete the experiment in the lab Building Linux virtual Machine environment.
    • According to this week's knowledge analysis system call process, from System_call start to iret end of the entire process, and draw a brief and accurate flowchart, write a signed blog, and in the blog post "real name (and the name of the final application certificate must be consistent) + Original works reproduced please specify the source + "Linux kernel analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000 ", the specific requirements of the blog content are as follows:
    • The topic is self-prepared, and the content revolves around the process of system call System_call;
    • The blog content needs to carefully analyze the System_call corresponding assembly code work process, pay special attention to the system call return Iret before the process scheduling time.
    • The summary part needs to clarify the understanding of "system call process", and further generalize to the general interrupt processing process.

Lab Environment:

This experiment is conducted in the Lab Building Linux virtual Machine environment.

Experimental content:

1. Follow the video tutorial to add last week's system call Function Getpid () and Getpid_asm () to the kernel.

The process is as follows:

Open the TEST.c file in the menu and add the following code

1int Getpid (int argc,char *Argv[])2{3Intpid4 pid=Getpid ();5 printf ("pid=%d\n", PID);6Return0;7}89int Getpidasm (int argc,char *Argv[])10{11IntpidasmVolatile(13"MOV $0,%%ebx\n\t"14"MOV $0x14,%%eax\n\t"15"int $0x80\n\t"16"mov%%eax,%0\n\t"17:"=m"(PID)18 19 printf (" pid =%d\n" ,pid "20 return 0 ;21}            

and add it in the main function.

After re-make. You can see that Menuos has a getpid command that returns the identity of the current process.

Through the experiment, we can see that the function call function has been added successfully in the system.

The following is a debug analysis of the program to understand the process of system calls.

Some of these commands are:

Qemu-kernel LINUX.3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD rootfs.img-s-S Debug.

The file Linux-3.18.6/vmlinux loads the debug kernel symbol table.

B Set Breakpoint N stepping

We were in Start_kernel, Systemy_call, sys_getpid. Add a breakpoint and perform the observation, and the list looks at the code nearby.

(>﹏<) My level is limited, I really have very hard to see AH, analysis Ah, but still do not understand AH (╯^╰)

Next we analyze the call between System_call and Iret during the system call.

This part of the MENUOS also can not use GDB debugging, mainly for reference teacher lecture content, as well as/LINUX-3.18.6/ARCH/X86/KERNEL/ENTRY_32.S, and some online information.

Where the above syscall_exit_work can be analyzed to see the execution of the workpend process, there may be new userspace.

I understand that other higher-priority interrupts may occur during system calls, and the CPU first executes the new higher-priority interrupt execution and then comes back to perform the current system call.

Therefore, nested calls are generated. In particular, the process, because of my time and ability to analyze the limited, there are not the great gods to advise.

When the execution returns, it will resotre_all the site, relevant parameters and so on.

Experiment Summary:

The system call is generated through the int $0x80, and the specific system invoker is executed according to the system call number parameter.

This experiment mainly studied the internal execution mechanism of Sys_call in the system call process, although the analysis is very simple, but it is good to help improve the understanding of this part of the Linux kernel mechanism operation.

The experiment began to add their own written system calls to Menuos for a long time, is too careless to write code, to calm down the heart to seriously ah.

Linux Kernel Analysis-experiment five Analysis system_call interrupt processing process

Related Article

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.