-
Add a new system call into the linux kernel
-
Test the new system call in user model
sudo apt-get install build-essential
see the pdf document: newsyscall2020.pdf
new customized kernel config: config1, config2
include/linux/syscalls.h
在文件(No. 1381) #endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */之前,添加一行:
asmlinkage long sys_schello(void);
kernel/sys.c 在文件SYSCALL_DEFINE0(gettid)函数之后(No. 2734),添加如下行:
SYSCALL_DEFINE0(schello) { printk("Hello new system call schello!Your ID\n"); return 0; }
针对64位OS arch/x86/entry/syscalls/syscall_64.tbl 在文件447 common memfd_secret sys_memfd_secret 行之后,添加如下行:
448 common schello sys_schello
make clean make -j5 sudo make modules_install sudo make install
重新启动:
reboot
确认新内核是否成功运行:
uname -a
编写用户态测试程序testschello.c
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <stdio.h>
#define __NR_schello 335
int main(int argc, char *argv[])
{
syscall(_NR_schello);
printf("ok! run dmesg | grep hello in terminal!\n");
return 0;
}
编译用户态测试程序testschello.c,并执行
gcc -o testsc testschello.c
./testsc
$dmesg | grep schello
[ 1648.215250] Hello new system call schello!