Add a new Linux system call

Source: Internet
Author: User

The previous article explains the principles of Linux system invocation in detail, and then explains how to create a new Linux system call based on the principle of the previous article.

To add a new system call to the kernel, you need to perform 3 steps:
1. Add a new kernel function
2. Update the header file Unistd.h
3. Update the system call table calls for this new function. S


1. Add the function in KERNEL/SYS.C:
asmlinkage int Sysmul (int a, int b)
{
int C;
c = a*b;
return C;
}


2. Add the system call number in Arch/arm/include/asm/unistd.h: Add the following

#define __NR_PREADV(__nr_syscall_base+361)
#define __NR_PWRITEV (__nr_syscall_base+362)
#define __nr_rt_tgsigqueueinfo (__nr_syscall_base+363)
#define __nr_perf_event_open (__nr_syscall_base+364)
#define __NR_Sysmul(__nr_syscall_base+365)

Remarks: Add on last Side


3. In Arch/arm/kernel/calls. s to add code to the newly implemented system call function:

/* * */Call (SYS_INOTIFY_INIT1)
Call (SYS_PREADV)
Call (Sys_pwritev)
Call (Sys_rt_tgsigqueueinfo)
Call (Sys_perf_event_open)

Call (Sysmul)

Note: The system call number in the Unistd.h must be added to the last face


4. Recompile the kernel

Make Uimage arch=arm cross_compile=arm-linux-


5. Copy the kernel to the TFTP directory

CP arch/arm/boot/uimage/tftpboot/

Note: The 5th step can not be used to download to the Development Board via TFTP


6. Using System calls

#include <stdio.h>
#include <linux/unistd.h>
Main ()
{

int result;
result = Syscall (361,1, 2),//syscall procedure 1, the system calls MOV R7, #365 2, using the SVC command

Syscall (System call number, parameter 1, parameter 2) where parameter 1 and parameter 2 are two parameters of Sysmul
printf ("result =", result);
}


Add a new Linux system call

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.