Adding a new Linux system call

Source: Internet
Author: User

The previous article explained the principles of Linux system invocation, followed by a brief introduction to how to create a new Linux system call

To add a new system call to the kernel, you need to run 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 a function to the KERNEL/SYS.C:
asmlinkage int Sysmul (int a, int b)
{
int C;
c = a*b;
return C;
}


2. Add the system call number to Arch/arm/include/asm/unistd.h: Add for example 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)

Note: On the last side, add


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: You must add the system call number in the last face to the Unistd.h


4. Compile the kernel again

Make Uimage arch=arm cross_compile=arm-linux-


5. Copy the kernel to the TFTP folder below

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.) Number of references 1, 2) the 1 and the 2 are the two sysmul of the number of references
printf ("result =", result);
}


Adding 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.