Linux-system call

Source: Internet
Author: User
Linux-functions of system calling: System calling, interruption, and exception are one of the three methods for users to fall into kernel state too much. System calls are OS-up interfaces. generally, applications do not directly use system calls. Instead, standard Library APIs are used, because the standard library APIs are generally consistent,... linux-functions of system calling: System calling, interruption, and exception are one of the three methods for users to fall into kernel state too much. System calls are OS-up interfaces. generally, applications do not directly use system calls, but use standard Library APIs, because the APIs of standard libraries are generally consistent, however, the specific system call depends on the specific system. One of the highlights of linux is the distinction between a mechanism (what functions are provided) and a policy (how to implement the function). you are concerned with the implementation mechanism of the former www.2cto.com: int 0x80 terminal number-> System call // problem: how does this interrupt occur? How to identify system calls? 1. user programs set parameters for system calls (including system call numbers) 2. trigger soft interruptions int0x80, resulting in exceptions 3. execute abnormal events (--->) this will cause the processor to switch to the kernel state and go to a new address, execute the exception handling function (system call function) 4. find the system call to execute 5. return the user status, return the control to the user. // What should I do? ========== Www.2cto.com 1 \ the system call number is critical. once assigned, it cannot be changed. the system call number is transmitted to the kernel through eax, the returned values are also stored in eax. Other parameters can be placed in ebx. Ecx. Edx. Esi. In edi, too many parameters are placed in a memory segment of the user space, and then the address is included in the register. 2 \ system calls must check whether all parameters are valid and whether the pointer provided by the user is valid. ** for example, if the pointer provided by a process to the kernel is owned by another user, the kernel helped him copy it, right... 3 \ strict access to user process space: two functions call copy -- from -- user and copy -- to_user, which may block the return values of system calls due to page-missing interruptions, unlike normal return values (such as the number of returned results for writing files), the system uses a global errno to save the error code (related interface perror ). Errno is easy to change, so it is saved first. 5 \ system calls can only be compiled into kernel 6 \ system call table entry. H7 \ is implemented in kernel/sys. c is generally implemented by a system call, but the general module can replace the system call * 8 \ the system call context is in the process context, and the process that current triggers the system call can be obtained, in the process, the kernel can be preemptible and sleep. * *** It indicates that a new process will use the same system call. if a system call is reentrant, there cannot be static variables. * ******* Does sleep mean that most features of the kernel are available? ?? What should I do ??? The system calls and returns the result. the control is in syscall, which is responsible for returning the result to the user process. 9 \ system call to access the kernel: & (sys_call_table + num * wordsize (4 )) obtain the function address of the table item called by the system-run complete-run ret -- from -- sys check to return the task to be completed before the user space. 10 \ access users by system calls: 1. support by c Library 2. a group of macros is provided in linux, registers are set, and the call into command _ syscalln () n from 0 to 6 indicates the number of parameters. for example, if open (const char * filename, int flag int mode) is called directly, define # define NR open 5 _ syscall3 (long, open, const char *, filename, int, flag, int, mode) www.2cto.com New system call: 1. add source code: asmlinkage sys _ system call name (){...}, Kernel/sys. c2, connect to the system call (make the rest of the kernel know the existence of the system call): 1 \/usr/src/linux/include/asm-i386/unistd. h # define _ NR_callname NNN // Number of the system call (kernel I only) 2 \/usr/src/linux/arch/i386/kernel/entry. S //. added in long SYMBOL_NAME (sys_mycall) sys_call_table (user I only) to re-compile and use: _ syscall1 (int, mycall, int, ret)

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.