Linux kernel Analysis (fourth week)

Source: Internet
Author: User

Three layers of skin (top) of the system call

First, the user state. Kernel state. Interrupt

(The courseware has learned last week)

1, the address space is a significant sign (is the logical address, not the physical address)

2, the CPU each instruction reads is through CS:EIP these two registers, 0xc00000000 above address space can only use the kernel state to access

3, interrupt processing is the main way to enter the kernel state from the user state (System call is a special interrupt)

4, protect the user state of the register context (user stack top address, then the status word, then the value of CS:EIP)

5, interrupt the first step: Save the scene (push) The last step: Restore the Scene (pop)

II. Overview of System invocation

1, the meaning of system call

1. The operating system provides a set of interfaces for user-state processes to interact with hardware devices-system calls: releasing users from the underlying hardware programming, greatly improving the security of the system; User programs are portable

2.API and system calls

Application programming interfaces (APIs) and system calls are different: The API is just a function definition, and the system call sends a clear request to the kernel via a soft interrupt

Some of the APIs defined by the 3.LIBC library refer to the encapsulation routines, and the only purpose is to publish the system

Typically each system call corresponds to an encapsulation routine

Libraries then use these encapsulation routines to define the user's API

* Not every API corresponds to a specific system call (the API may directly provide a user-configured service), or several system calls may be invoked; Different APIs may invoke the same system call

* Return value: Most encapsulation routines return an integer (meaning dependent on the corresponding system call); 1 in most cases, the kernel cannot satisfy the request of the process; the errno variable defined by LIBC contains a specific error code

2. System call program and service routine

1. Perform system calls in Linux by executing an int $0x80

2. Parameters: The process must indicate which system call is required, which requires passing a parameter called the system call number (using the EAX register)

3. Parameter passing

1. System calls also require input and output parameters;

2.system_call is the entry point for calls to all systems in Linux, with at least one parameter per system call, which is the system call number passed with EAX

4. Kernel Code of System call

1. System call dispatch table (Dispatch table) stored in sys_call_table array

5. System call Mechanism initialization

(Learn the code)

6. Three-layer skins for system calls

XYZ ()

System_call ()

SYS_XYZ ()

7. Interrupt vector 0x80 is bound to system_call; The system call number Associates XYZ with SYSTEM_XYZ ()

Third, using the Library function API and C code embedded assembly code

Experiment:

Linux kernel Analysis (fourth week)

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.