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:
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
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