In the 2.6 era, the steps for writing a linux system call are as follows:
- Compile the actual operation function
- Add macro definitions in linux/include/asm-i386/unistd. h
#define __NR_myfunctioin 399
- In linux/arch/i386/kernel/entry. S, add
.long SYMBOL_NAME(myfunction)
- Compile the kernel
- Use _ syscall [1-6] (type, name, type, arg1) to call
The corresponding macro definition file cannot be found at the corresponding location of the kernel in the latest version.
Unistd. modify the H file to reference the 32-bit and 64-bit versions respectively, and placed in/arch/x86/include/uapi/asm/unistd _ [32 | 64 | x32]. h. arm is stored in/arch/arm/uapi/asm/unistd. h, the other architectures are similar.
In addition, some files are modified to the _ SYSCALL (n, call) method definition.
The sys_call_table definition in the entry. S file is also placed in the syscall. h file, and the original assembly is modified to the definition method of the C array.
_ SYSCALL is a macro.
#define __SYSCALL(n, call) [nr] = (call),#define __SYSCALL_XX(n, sym, compat)
In addition, the sys_call_table [nr_syscils] array is added.
void *sys_call_table[NR_syscalls] = { [0 ... NR_syscalls-1] = sys_ni_syscall,#include <asm/unistd.h>}
Currently, there are two ways in the kernel to define system calls: macro-defined numbers and _ SYSCALL.