Linux Kernel Learning four system calls

Source: Internet
Author: User

A conceptual distinction

When it comes to Linux system calls, you have to differentiate between several confusing concepts:

System call: A system call is a special interface. With this interface, the user can access the kernel space. System calls specify where the user process enters the kernel.

Application interface (Api,application programming Interface): Some predefined functions. The API provides the ability of an application and developer to access a set of routines based on a piece of software or hardware without having to access the source code or to understand the details of the internal working mechanism.

C Library: C Library implements the main Linux API, including standard C library functions and system calls. At the same time, Linux system calls are provided as part of the C library.

The relationship between three people:

Two examples of experiments:

Two related system calls, setuid and Getuid, are implemented using the Library function API and the embed assembly code in C code.

The C code is as follows: (Displays the current user ID first, modifies the user ID, and then displays)

Root Permissions Compile execution:

Normal User Rights execution:

The code for the EMBED assembly is getuid_asm.c as follows:

Root Privilege Execution:

Normal User privileges:

Three-Analysis Summary

The main analysis of the assembly code in the system calls the work process, the above assembly code in the second segment of the Assembly as an example, just beginning on the system call how to transfer parameters of interest, so in the use of system call GETUID based on the addition of setuid, see how to pass the parameters, C language is easier to implement, But I can't see the details, and the assembly can. So began the SETUID assembly implementation, mainly is two points: transmission system calls with "int 0x80" trigger system call, check table, setuid system call number is 23, that is, 0x17. The following is the pass-through parameters, because it is not clear what the return value of the setuid, not set the output, only set the input (parameters), but not to pass in, and then add the output settings, there is the parameter is to trigger the system call before or after the (that is, before and after the int 0x80)? After an experiment, it was placed behind (int 0x80) or failed to pass. Put in the int 0x80 before adding the output settings, it can be passed in, the value of the UID is changed to my pre-set value. The individual thinks that the parameter must be ready before triggering the system call .... Need to dig into ....

By: Fanglongwei

Original works reproduced please indicate the source

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

Linux Kernel Learning four system calls

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.