ARM 系统调用的接口是什么?它在 Linux 内核中定义在哪里?

2024-11-11 08:26:00
admin
原创
200
摘要:问题描述:我读过有关 Linux 中的系统调用的文章,到处都有关于 x86 架构(0x80中断和SYSENTER)的描述。但我无法追踪 ARM 架构中系统调用的文件和进程。有人可以帮忙吗?我发现的一些相关文件是:arch/arm/kernel/调用.Sarch/arm/kernel/entry-common....

问题描述:

我读过有关 Linux 中的系统调用的文章,到处都有关于 x86 架构(0x80中断和SYSENTER)的描述。但我无法追踪 ARM 架构中系统调用的文件和进程。有人可以帮忙吗?

我发现的一些相关文件是:

arch/arm/kernel/调用.S

arch/arm/kernel/entry-common.S(需要解释)


解决方案 1:

比您问的问题更通用的答案。

在 Linux 上,man syscall (2)了解如何在各种架构中进行系统调用是一个很好的开始。

从该手册页复制:

Architecture calling conventions
    Every architecture has its own way of invoking and passing arguments
    to the kernel.  The details for various architectures are listed in
    the two tables below.

    The first table lists the instruction used to transition to kernel
    mode (which might not be the fastest or best way to transition to the
    kernel, so you might have to refer to vdso(7)), the register used to
    indicate the system call number, the register used to return the sys‐
    tem call result, and the register used to signal an error.

    arch/ABI    instruction           syscall #  retval  error    Notes
    ────────────────────────────────────────────────────────────────────
    alpha       callsys               v0         a0      a3       [1]
    arc         trap0                 r8         r0      -
    arm/OABI    swi NR                -          a1      -        [2]
    arm/EABI    swi 0x0               r7         r0      -
    arm64       svc #0                x8         x0      -
    blackfin    excpt 0x0             P0         R0      -
    i386        int $0x80             eax        eax     -
    ia64        break 0x100000        r15        r8      r10      [1]
    m68k        trap #0               d0         d0      -
    microblaze  brki r14,8            r12        r3      -
    mips        syscall               v0         v0      a3       [1]
    nios2       trap                  r2         r2      r7
    parisc      ble 0x100(%sr2, %r0)  r20        r28     -
    powerpc     sc                    r0         r3      r0       [1]
    riscv       scall                 a7         a0      -
    s390        svc 0                 r1         r2      -        [3]
    s390x       svc 0                 r1         r2      -        [3]
    superh      trap #0x17            r3         r0      -        [4]
    sparc/32    t 0x10                g1         o0      psr/csr  [1]
    sparc/64    t 0x6d                g1         o0      psr/csr  [1]
    tile        swint1                R10        R00     R01      [1]
    x86-64      syscall               rax        rax     -        [5]
    x32         syscall               rax        rax     -        [5]
    xtensa      syscall               a2         a2      -

    Notes:

        [1] On a few architectures, a register is used as a boolean (0
            indicating no error, and -1 indicating an error) to signal
            that the system call failed.  The actual error value is still
            contained in the return register.  On sparc, the carry bit
            (csr) in the processor status register (psr) is used instead
            of a full register.

        [2] NR is the system call number.

        [3] For s390 and s390x, NR (the system call number) may be passed
            directly with svc NR if it is less than 256.

        [4] On SuperH, the trap number controls the maximum number of
            arguments passed.  A trap #0x10 can be used with only 0-argu‐
            ment system calls, a trap #0x11 can be used with 0- or
            1-argument system calls, and so on up to trap #0x17 for
            7-argument system calls.

        [5] The x32 ABI uses the same instruction as the x86-64 ABI and
            is used on the same processors.  To differentiate between
            them, the bit mask __X32_SYSCALL_BIT is bitwise-ORed into the
            system call number for system calls under the x32 ABI.  Both
            system call tables are available though, so setting the bit
            is not a hard requirement.

    The second table shows the registers used to pass the system call
    arguments.

    arch/ABI      arg1  arg2  arg3  arg4  arg5  arg6  arg7  Notes
    ──────────────────────────────────────────────────────────────
    alpha         a0    a1    a2    a3    a4    a5    -
    arc           r0    r1    r2    r3    r4    r5    -
    arm/OABI      a1    a2    a3    a4    v1    v2    v3
    arm/EABI      r0    r1    r2    r3    r4    r5    r6
    arm64         x0    x1    x2    x3    x4    x5    -
    blackfin      R0    R1    R2    R3    R4    R5    -
    i386          ebx   ecx   edx   esi   edi   ebp   -
    ia64          out0  out1  out2  out3  out4  out5  -
    m68k          d1    d2    d3    d4    d5    a0    -
    microblaze    r5    r6    r7    r8    r9    r10   -
    mips/o32      a0    a1    a2    a3    -     -     -     [1]
    mips/n32,64   a0    a1    a2    a3    a4    a5    -
    nios2         r4    r5    r6    r7    r8    r9    -
    parisc        r26   r25   r24   r23   r22   r21   -
    powerpc       r3    r4    r5    r6    r7    r8    r9
    riscv         a0    a1    a2    a3    a4    a5    -
    s390          r2    r3    r4    r5    r6    r7    -
    s390x         r2    r3    r4    r5    r6    r7    -
    superh        r4    r5    r6    r7    r0    r1    r2
    sparc/32      o0    o1    o2    o3    o4    o5    -
    sparc/64      o0    o1    o2    o3    o4    o5    -
    tile          R00   R01   R02   R03   R04   R05   -
    x86-64        rdi   rsi   rdx   r10   r8    r9    -
    x32           rdi   rsi   rdx   r10   r8    r9    -
    xtensa        a6    a3    a4    a5    a8    a9    -

    Notes:

        [1] The mips/o32 system call convention passes arguments 5
            through 8 on the user stack.

    Note that these tables don't cover the entire calling convention—some
    architectures may indiscriminately clobber other registers not listed
    here.

所以这取决于系统是否使用 OABI 还是 EABI。

因此在 EABI 中您使用r7传递系统调用号,使用r0-r6传递参数,使用SWI 0进行系统调用,并期望得到结果r0

SWI <number>在 OABI 中,除了进行系统调用之外,一切都是相同的。

解决方案 2:

在 ARM 世界中,您可以software interrupt通过(以前称为 SWI)执行(向内核发出信号的机制)supervisor call / svc

ARM 汇编(UAL)语法如下:

SVC{<c>}{<q>} {#}<imm>

(在 Linux 中你需要传递 #0)

您应该从其他项目(例如bionic或uClibc)中借鉴。

解决方案 3:

如果您正在寻找 Linux 系统中的系统调用号,请查看
w3challs。

该网站可帮助您找出用于传递参数的系统调用号和寄存器。它支持以下列出的许多体系结构:

  • Linux x86

  • Linux x86_64

  • Linux 操作系统

  • Linux ARM(拇指模式)

  • Linux IA64(安腾)

  • Linux Mips o32

  • Linux Mips n32

  • Linux Mips n64

  • Linux Sparc(32 位)

  • Linux Sparc64

  • Linux PowerPC(32 位)

  • Linux的PowerPC64

  • Windows x86

  • Windows x86_64

  • 操作系统 BSD


编辑:提交https://w3challs.com/forum/general/dev/bugs#04来跟踪错误的错误。

解决方案 4:

n900 中的 hello world 的反汇编显示svc #0

http://brnz.org/hbr/?m=201102

解决方案 5:

arm 系统调用号

v4.19 在以下位置定义它们arch/arm/tools/syscall.tbl:https://github.com/torvalds/linux/blob/v4.19/arch/arm/tools/syscall.tbl

摘抄:

0   common  restart_syscall     sys_restart_syscall
1   common  exit            sys_exit
2   common  fork            sys_fork
3   common  read            sys_read
4   common  write           sys_write
5   common  open            sys_open
6   common  close           sys_close

我已经测试过exit,并且在 QEMU 用户模式下的这个 Linux 程序集 hello worldwrite上得到了这些精确的数字。

arm64 系统调用号

aarch64 使用了一种新的机制,参见:https ://reverseengineering.stackexchange.com/questions/16917/arm64-syscalls-table/18834#18834

解决方案 6:

Linux 系统调用号在 C 包含文件中定义:/usr/include/asm-generic/unistd.h

在此文件中,有如下定义语句:

/* fs/read_write.c */
#define __NR_write 64

/* kernel/exit.c */
#define __NR_exit 93

这定义了符号__NR_write来表示写入 Linux 系统调用的魔幻数字 64 和退出的魔幻数字 93。


摘录自《使用 64 位 ARM 汇编语言进行编程:针对 Raspberry Pi 和移动设备的单板计算机开发》 | 第 7 章:Linux 操作系统服务 - 调用约定 - Linux 系统调用号码

相关推荐
  政府信创国产化的10大政策解读一、信创国产化的背景与意义信创国产化,即信息技术应用创新国产化,是当前中国信息技术领域的一个重要发展方向。其核心在于通过自主研发和创新,实现信息技术应用的自主可控,减少对外部技术的依赖,并规避潜在的技术制裁和风险。随着全球信息技术竞争的加剧,以及某些国家对中国在科技领域的打压,信创国产化显...
工程项目管理   1565  
  为什么项目管理通常仍然耗时且低效?您是否还在反复更新电子表格、淹没在便利贴中并参加每周更新会议?这确实是耗费时间和精力。借助软件工具的帮助,您可以一目了然地全面了解您的项目。如今,国内外有足够多优秀的项目管理软件可以帮助您掌控每个项目。什么是项目管理软件?项目管理软件是广泛行业用于项目规划、资源分配和调度的软件。它使项...
项目管理软件   1354  
  信创国产芯片作为信息技术创新的核心领域,对于推动国家自主可控生态建设具有至关重要的意义。在全球科技竞争日益激烈的背景下,实现信息技术的自主可控,摆脱对国外技术的依赖,已成为保障国家信息安全和产业可持续发展的关键。国产芯片作为信创产业的基石,其发展水平直接影响着整个信创生态的构建与完善。通过不断提升国产芯片的技术实力、产...
国产信创系统   21  
  信创生态建设旨在实现信息技术领域的自主创新和安全可控,涵盖了从硬件到软件的全产业链。随着数字化转型的加速,信创生态建设的重要性日益凸显,它不仅关乎国家的信息安全,更是推动产业升级和经济高质量发展的关键力量。然而,在推进信创生态建设的过程中,面临着诸多复杂且严峻的挑战,需要深入剖析并寻找切实可行的解决方案。技术创新难题技...
信创操作系统   27  
  信创产业作为国家信息技术创新发展的重要领域,对于保障国家信息安全、推动产业升级具有关键意义。而国产芯片作为信创产业的核心基石,其研发进展备受关注。在信创国产芯片的研发征程中,面临着诸多复杂且艰巨的难点,这些难点犹如一道道关卡,阻碍着国产芯片的快速发展。然而,科研人员和相关企业并未退缩,积极探索并提出了一系列切实可行的解...
国产化替代产品目录   28  
热门文章
项目管理软件有哪些?
云禅道AD
禅道项目管理软件

云端的项目管理软件

尊享禅道项目软件收费版功能

无需维护,随时随地协同办公

内置subversion和git源码管理

每天备份,随时转为私有部署

免费试用