linux arm新增系统调用select_sort

这篇博客详细介绍了如何在Linux ARM架构下增加一个名为`sys_select_sort`的系统调用。主要步骤包括修改`unistd.h`头文件以增加系统调用号,更新`kernel/Makefile`以包含新系统调用的编译,更新`calls.S`以实现系统调用的汇编代码,并编写对应的C语言实现。这个系统调用实现了数组的选择排序功能。
摘要由CSDN通过智能技术生成

参考链接: 操作系统实验:Linux新增系统调用_CY_BRYANT的博客-CSDN博客_linux增加系统调用实验报告

diff --git a/arch/arm/include/asm/unistd.h b/arch/arm/include/asm/unistd.h
index 32640c43..7cba573c 100644
--- a/arch/arm/include/asm/unistd.h
+++ b/arch/arm/include/asm/unistd.h
@@ -19,7 +19,7 @@
  * This may need to be greater than __NR_last_syscall+1 in order to
  * account for the padding in the syscall table
  */
-#define __NR_syscalls  (388)
+#define __NR_syscalls  (392)   // 需要4字节对齐
 
 /*
  * *NOTE*: This is a ghost syscall private to the kernel.  Only the
diff --git a/arch/arm/include/uapi/asm/unistd.h b/arch/arm/include/uapi/asm/unistd.h
index 0c3f5a0d..12c942d3 100644
--- a/arch/arm/include/uapi/asm/unistd.h
+++ b/arch/arm/include/uapi/asm/unistd.h
@@ -414,6 +414,7 @@
 #define __NR_memfd_create              (__NR_SYSCALL_BASE+385)
 #define __NR_bpf                       (__NR_SYSCALL_BASE+386)
 #define __NR_execveat                  (__NR_SYSCALL_BASE+387)
+#define __NR_select_sort                (__NR_SYSCALL_BASE+388)
 
 /*
  * The following SWIs are ARM private.
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index bfea78f1..97c6a295 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -21,7 +21,7 @@ CFLAGS_psci.o = -O
 obj-y          := elf.o entry-common.o irq.o opcodes.o \
                   process.o ptrace.o return_address.o \
                   setup.o signal.o sigreturn_codes.o \
-                  stacktrace.o sys_arm.o time.o traps.o
+                  stacktrace.o sys_arm.o time.o traps.o select_sort.o
 
 obj-$(CONFIG_ATAGS)            += atags_parse.o
 obj-$(CONFIG_ATAGS_PROC)       += atags_proc.o
diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S
index 05745eb8..b1d8dcb6 100644
--- a/arch/arm/kernel/calls.S
+++ b/arch/arm/kernel/calls.S
@@ -397,6 +397,7 @@
 /* 385 */      CALL(sys_memfd_create)
                CALL(sys_bpf)
                CALL(sys_execveat)
+               CALL(sys_select_sort)
 #ifndef syscalls_counted
 .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
 #define syscalls_counted
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 76d1e38a..b42f3750 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -884,4 +884,6 @@ asmlinkage long sys_execveat(int dfd, const char __user *filename,
                        const char __user *const __user *argv,
                        const char __user *const __user *envp, int flags);
 
+asmlinkage int sys_select_sort(int *a,const int n);
+
 #endif

新增文件 select_sort.c

// 新增文件 select_sort.c 

#include<linux/linkage.h>
#include<linux/types.h>
asmlinkage int sys_select_sort(int *a,const int n)
{

  int temp,temp1,min,i,j;

  for(i=0;i<n-1;i++)
  {

    temp=i;
    min=*(a+i);
    for(j=i+1;j<n;j++)
    {
      if(*(a+j)<min)
      {
        temp=j;
        min=*(a+j);
      }
    }

    if(i != temp)
    {
      temp1=*(a+i);
      *(a+i)=*(a+temp);
      *(a+temp)=temp1;
    }
  }
  return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值