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