arm linux 添加系统调用

一、修改内核代码

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值