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