Linux kernel Analysis Week4 job-invoking a system call using the embedded assembly

Source: Internet
Author: User
Tags volatile

I. Embedded assembly execution of Fork

#include <stdio.h>#include<unistd.h>intMain () {pid_t pid; ASMvolatile(        "mov $0,%%ebx\n\t"        "mov $0x2,%eax\n\t"        "int 0x80\n\t"        "mov%%eax,%0\n\t"        :"=m"(TT)); if(pid==0) {printf ("Child is running. \ n"); }    Else{printf ("father is running...\n"); }}

two. System call to read (system call with parameters)    

intReadintFdCharBuf[],intLen) {     intret; ASMvolatile(         "mov%3,%%edx\n\t" //Count->edx         "mov%2,%%ecx\n\t" //buf->ecx         "mov%1,%%ebx\n\t" //FD->EBX         "mov $0x3,%%eax\n\t"         "int $0x80\n\t"         :"=m"(ret):"b"(FD),"C"(BUF),"D"(count)); returnret;}

Three. Experimental summary

through this experiment, I have a deeper understanding of how system calls are executed. When our application calls a system call, it triggers an int $0x80 interrupt, which is entered into the kernel state by the user state, and the system call number is passed by EAX, which eventually makes the kernel determine the appropriate kernel program to execute.

Linux kernel Analysis Week4 job-invoking a system call using the embedded assembly

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.