Experiment-using the same system call (Yeung Kwong) using the Library function API and the embed assembly code in C code two ways

Source: Internet
Author: User

Use the same system call using the Library function API and the embed assembly code in C code two ways

Writer: Yang Guangxu No.: 20135233

(* Original works reproduced please specify the source *)

(Learning course: Linux kernel Analysis MOOC course http://mooc.study.163.com/course/USTC-1000029000)

Experimental requirements:

    1. Select a system call (except for number 13th system call time), see the System invocation list HTTP://CODELAB.SHIYANLOU.COM/XREF/LINUX-3.18.6/ARCH/X86/SYSCALLS/SYSCALL_32.TBL

    2. Refer to the video in the way the Library function API and C code embedded in the assembly code two ways to use the same system call, recommended in the experimental Building Linux virtual machine environment to complete the experiment.

Experimental process:


First, select the system call to use: I chose number 20th, Getpid.

Then, go into the lab building and write the C language code.

Save and compile with GCC./Run

Run successfully, then modify YANGGUANG.C to replace the embedded Assembly statement

Save and exit, then run with GCC compilation

Summary of Knowledge points:

The user is associated with a system call through a library function.

Kernel State

At high execution level, code can execute privileged instructions to access any physical address .

User state:

The scope of control of the code is limited.

Intel x86 CPU has four privilege ratings, 0-3. Linux only takes two, 0 is the kernel, 3 is the user state
Differentiating permission levels makes the system more stable.

Meaning of the system call:

The operating system provides a set of interfaces for the user-state process to interact with the hardware device, which is called by the system.

- 远离底层硬件编程- 安全性- 可移植性
API-Application Programming interface

Differences from system calls:

- API只是一个函数定义- 系统调用是通过软中断向内核发出一个明确的请求。

In general, each system call corresponds to an encapsulation routine, and the library uses these encapsulation routines to define the user's API for user convenience.

the API does not correspond to the system call one by one :

API可以:- 直接提供用户态服务- 一个单独的API可能调用几个系统调用- 不同的API可能调用了同一个系统调用

return value:

 - 大部分封装例程返回一个整数 - -1表示失败,不能满足请求  - errno 特定出错码
3. The so-called "three-layer skin" of the "clawed system call"
    • API (XYZ)
    • Interrupt Vector (System_call)
    • Interrupt Service Program (SYS_XYZ)

API XYZ and SYS_XYZ are connected by the system call number

Experiment-using the same system call (Yeung Kwong) using the Library function API and the embed assembly code in C code two ways

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.