arm64 linux 添加系统调用

一、修改内核代码

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值