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