如何在ARM64中实现系统调用? [英] How to implement system call in ARM64?
问题描述
我正在使用 arm64 汇编代码,我想使用 svc 指令实现系统调用.我在网上找不到任何可用的 arm64 系统调用实现.另外,我找不到 arm64 的系统调用列表.还解释了实现.
I am working with arm64 assembly coding and I want to implement system calls using svc instruction . I can't find any working arm64 system call implementation online.Also, I can't find the system call list for arm64. Also explain the implementation .
推荐答案
可以将x0
中的六个参数传递给x5
,返回值保存在x0
.
You can pass six arguments in x0
to x5
, return value is saved in x0
.
为了给出汇编代码片段,这是来自 Android Bionic 的 libc 实现.write
的三个参数已经在 x0-x2
中.系统调用号在 x8
中传递.
To give an assembler snippet, this is write
syscall from Android Bionic's libc implementation. write
's three arguments would already be in x0-x2
. Syscall number is passed in x8
.
/* Generated by gensyscalls.py. Do not edit. */
#include <private/bionic_asm.h>
.hidden __set_errno
ENTRY(write)
mov x8, __NR_write
svc #0
cmn x0, #(MAX_ERRNO + 1)
cneg x0, x0, hi
b.hi __set_errno
ret
END(write)
提供 AArch64 ABI 看看.
新一代架构都使用来自的数字包括/uapi/asm-generic/unistd.h.
Newer generation of architectures all use numbers from include/uapi/asm-generic/unistd.h.
你也可以查看arch/arm64/包括/asm/syscall.h 用于参数和返回值处理.
You can also check arch/arm64/include/asm/syscall.h for argument and return value handling.
如果您手头有 as
和 ld
,您可以创建一个简单的可执行文件,只需使用退出值退出即可.
If you have as
and ld
in hand, you can create a simple executable just quitting with an exit value.
这里 42
是我们的返回值,93
是 exit
系统调用.
Here 42
is our return value and 93
is exit
system call.
$cat answer.s
.global _start
_start:
mov x0, #42
mov x8, #93
svc #0
$as answer.s -o answer.o
$ld answer.o -o answer
$./answer
$echo $?
42
这篇关于如何在ARM64中实现系统调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!