Experimental process
- Select number 20th system call GETPID (get process identification code)
Querying the C language code of the GETPID function and its embedded assembly statements on the Web
C Language code:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>int main(int argc, const char *argv[]){ pid_t tt; tt = getpid(); printf("%u\n", tt); return 0;}
Embedded Assembler Statements:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h>int main (int ARGC, const char *argv[]) {pid_t TT; ASM volatile ("mov $0x14,%%eax\n\t" "" int $0x80\n\t "" mov%%eax,%0\n\t ":" =m "(TT)); printf ("%u\n", TT); return 0;}
- Go into the lab building. Open Xfce, enter the command in the CD Code directory: VI getpid.c; Create and open the Getpid.c file, and in VI, enter the function code of the implementation Getpid, which is accessed online, and then save and exit.
The function code is then compiled with GCC. By entering the directive./getpid can conclude that the current process number is: 29895
5. Modify GETPID.C, change to embedded Assembly statement, save and exit, use the following command gcc getpid-o getpid.c-m32 compile
6. Use the following command./getpid run to get the current process number 11926
Experiment Summary 1. System call three-layer skin
1.API (XYZ)
2. Interrupt vector (System_call)
3. Interrupt Service Program (SYS_XYZ)
2. Inline assembly calls system call
1. The system call number is placed in the EAX.
2. The parameters of the system call are placed in ebx, ecx, edx, ESI, EDI, and EBP, respectively, in the order
3. The return value is passed using EAX
Wang Xue Cheng
Original works reproduced please indicate the source
"Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000
Linux kernel and analysis three-layer skin (top) of the fourth-week clawed system call