一、修改内核代码
Index: include/linux/syscalls.h
===================================================================
--- include/linux/syscalls.h (revision 2449)
+++ include/linux/syscalls.h (working copy)
@@ -940,5 +940,5 @@
asmlinkage long sys_pkey_free(int pkey);
asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags,
unsigned mask, struct statx __user *buffer);
-
+asmlinkage long sys_my_test(void);
#endif
Index: include/uapi/asm-generic/unistd.h
===================================================================
--- include/uapi/asm-generic/unistd.h (revision 2449)
+++ include/uapi/asm-generic/unistd.h (working copy)
@@ -732,9 +732,11 @@
__SYSCALL(__NR_pkey_free, sys_pkey_free)
#define __NR_statx 291
__SYSCALL(__NR_statx, sys_statx)
+#define __NR_my_test 292
+__SYSCALL(__NR_my_test, sys_my_test)
#undef __NR_syscalls
-#define __NR_syscalls 292
+#define __NR_syscalls 293
/*
* All syscalls below here should go away really,
Index: kernel/sys.c
===================================================================
--- kernel/sys.c (revision 2449)
+++ kernel/sys.c (working copy)
@@ -2504,6 +2504,13 @@
return 0;
}
+SYSCALL_DEFINE0(my_test)
+{
+ printk("my_test:20220810\n");
+ return 0;
+}
+
+
#ifdef CONFIG_COMPAT
struct compat_sysinfo {
s32 uptime;
二、应用验证
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
int my_test()
{
return syscall(292);
}
int main()
{
int ret;
ret = my_test();
printf("return val:%d",ret);
return 0;
}