Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement system call in 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 .

like image 726
in3o Avatar asked Aug 21 '14 16:08

in3o


1 Answers

You can pass six arguments in x0 to x5, return value is saved in x0.

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)

Give AArch64 ABI a look.

Newer generation of architectures all use numbers from include/uapi/asm-generic/unistd.h.

You can also check arch/arm64/include/asm/syscall.h for argument and return value handling.

Another example:

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
like image 181
auselen Avatar answered Oct 01 '22 17:10

auselen