如何在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
.
要给出汇编代码段,这是来自writesyscall. ="noreferrer"> 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 .
您还可以检查 arch/arm64/include/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.
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屋!