Linux design and implementation notes-how system calls work and the process of adding system calls

Source: Internet
Author: User

Meaning of system call

In order to interact with processes on the user space, the kernel provides a set of interfaces.
The application accesses hardware and other operating system resources through this set of interfaces.
Complete control of hardware and resource access. Safe, reliable, multi-tasking, virtual must
Abstraction of the hardware device (providing the independence of the device).

exception, sink, system call: Three ways in which user space enters kernel space

Principle


Sys_write will invoke the Write method in the corresponding struct file, operations, based on the files that the system write outputs.

Procedures for adding system calls

Take kernel 2.6.11 as an example long my_syscall (int i);

    • Download Kernel 2.6 Kernel source, switch to root directory
    • In/arch/i386/kernel/entry. s in Sys_call_table last added. Long My_syscall
    • Add the system call number last in/include/asm-i386/unistd.h
      #define __NR_my_syscall 338The Nr_syscalls value +1
    • Add the implementation of the system call in the/arch/i386/kernel/sys_i386.c file (without modifying Mkefile)
      Asmlinkage long Sys_my_syscall (int i) {}
    • Writing User Programs
#include<syscall.h>#include<linux/unistd.h>#define __NR_my_syscall 338_syscall1(longint, i)Int main(){        Int a = my_syscall(5);}
    • Compile kernel, reboot

Linux design and implementation notes-how system calls work and the process of adding system calls

Related Article

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.