2019-2020-1 20199315 "Linux kernel principle and Analysis" in the fifth week of work

Chapter IV, "Paodingjieniu Linux kernel analysis"

Three-tier mechanism (on) system calls

User mode, kernel mode and interrupt

System calls to the operating system location diagram:

Intelx86 CPU 4 performs different levels, namely, 0,1,2,3, the smaller the number, the higher the privilege. Linux Caozuojitong employed in which only the two privilege levels 0 and 3, corresponding to the kernel mode and user mode.
Very significant distinction method for a user mode and kernel mode is CS: EIP point range, when the kernel mode, CS: value EIP may be any address, there is a process 4GB address space in a 32-bit x86 machines, kernel mode this 4GB address space can be accessed; user mode you can only access 0x00000000-0xbfffffff address space.

The system is also a call to interrupt, the interrupt handler from user mode to enter the main mode kernel mode.

Overview of system calls

Significance of system calls to interact with the operating system provides a set of interfaces for user mode processes and hardware devices. System call has the following functions and features:
1. frees users from the underlying hardware programming in
security greatly improve the system 2.
3. portability enables users to program

Laboratory building Experiment 4

1. Using the API library function triggers a system call

C language source code:


#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
int main(void)
{
    int u_id;
    u_id=getpid();
    printf("u_id=%u\n",u_id);
    return 0;
}

operation result:

2.C code embedded assembly code starting a system call

Source code is as follows:


#include<stdio.h>
#include<unistd.h>
int main(void)
{
    int u_id;
    asm volatile(
           "movl $0x14,%%eax\n\t"        /* 将系统调用号赋给eax寄存器 */
           "int  $0x80\n\t"                  /* 执行系统调用 */
           "movl %%eax, %0\n\t"             /* 将系统调用执行后的返回值赋给变量 */
           :"=m" (u_id)
           );
    printf("u_id=%u\n",u_id);
    return 0;
}

operation result:

This is my fifth week of the Linux learning content, if insufficient, please criticism and be grateful.

the above

Guess you like

Origin www.cnblogs.com/qianxiaoxu/p/11706743.html