赞
踩
一、修改内核代码
Index: linux-3.10/arch/arm/include/asm/unistd.h
===================================================================
--- linux-3.10/arch/arm/include/asm/unistd.h (revision 2448)
+++ linux-3.10/arch/arm/include/asm/unistd.h (working copy)
@@ -15,7 +15,7 @@
#include <uapi/asm/unistd.h>
-#define __NR_syscalls (380)
+#define __NR_syscalls (384)
#define __ARM_NR_cmpxchg (__ARM_NR_BASE+0x00fff0)
#define __ARCH_WANT_STAT64
Index: linux-3.10/arch/arm/include/uapi/asm/unistd.h
===================================================================
--- linux-3.10/arch/arm/include/uapi/asm/unistd.h (revision 2448)
+++ linux-3.10/arch/arm/include/uapi/asm/unistd.h (working copy)
@@ -406,6 +406,8 @@
#define __NR_process_vm_writev (__NR_SYSCALL_BASE+377)
#define __NR_kcmp (__NR_SYSCALL_BASE+378)
#define __NR_finit_module (__NR_SYSCALL_BASE+379)
+#define __NR_my_test (__NR_SYSCALL_BASE+380)
+#define __NR_test_parameters (__NR_SYSCALL_BASE+381)
/*
* This may need to be greater than __NR_last_syscall+1 in order to
Index: linux-3.10/arch/arm/kernel/calls.S
===================================================================
--- linux-3.10/arch/arm/kernel/calls.S (revision 2448)
+++ linux-3.10/arch/arm/kernel/calls.S (working copy)
@@ -389,6 +389,9 @@
CALL(sys_process_vm_writev)
CALL(sys_kcmp)
CALL(sys_finit_module)
+/* 380 */ CALL(sys_my_test)
+ CALL(sys_test_parameters)
+
#ifndef syscalls_counted
.equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
#define syscalls_counted
Index: linux-3.10/include/linux/syscalls.h
===================================================================
--- linux-3.10/include/linux/syscalls.h (revision 2448)
+++ linux-3.10/include/linux/syscalls.h (working copy)
@@ -846,4 +846,6 @@
asmlinkage long sys_kcmp(pid_t pid1, pid_t pid2, int type,
unsigned long idx1, unsigned long idx2);
asmlinkage long sys_finit_module(int fd, const char __user *uargs, int flags);
+asmlinkage long sys_my_test(void);
+asmlinkage long sys_test_parameters(int a1,int b1);
#endif
Index: linux-3.10/kernel/sys.c
===================================================================
--- linux-3.10/kernel/sys.c (revision 2448)
+++ linux-3.10/kernel/sys.c (working copy)
@@ -2596,6 +2596,25 @@
return 0;
}
+SYSCALL_DEFINE0(my_test)
+{
+ printk("my_test:20220810\n");
+ return 0;
+}
+
+
+long do_test_parameters(int aa,int bb)
+{
+ return aa+bb;
+}
+
+SYSCALL_DEFINE2(test_parameters,int,a,int,b)
+{
+ printk("add two num\n");
+ return do_test_parameters(a,b);
+}
+
+
#ifdef CONFIG_COMPAT
struct compat_sysinfo {
s32 uptime;
二、编译应用代码验证系统调用
(1)sys_my_test
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
int my_test()
{
return syscall(380);
}
int main()
{
int ret;
ret = my_test();
printf("return val:%d\n",ret);
return 0;
}
(2)sys_test_parameters
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
int test_parameters(int a, int b)
{
return syscall(381,a,b);
}
int main()
{
int ret;
ret = test_parameters(5,6);
printf("return val:%d\n",ret);
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。