Linux kernel and analysis three-layer skin (top) of the fourth-week clawed system call

Source: Internet
Author: User

Experimental process
  1. Select number 20th system call GETPID (get process identification code)
  2. 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;}  
  3. 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.
  4. 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

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.