#syscalls #linux #directasm

syscall-linux-raw

Defines syscallN methods for performing raw Linux syscalls

1 unstable release

0.0.2 Mar 2, 2021
0.0.1 Jul 2, 2020

#916 in Unix APIs

Unlicense

10KB
131 lines

syscall-linux-raw

Defines syscallN methods for performing raw Linux syscalls.

What

Defines the small set of methods abstracting raw syscalls with different numbers of arguments, only available on target_os = "linux". That's it. But it works on stable and may be instructive for other syscall binary interfaces.

How

By pure magic. Jk, it defines fully assembled binary function with a proper C-abi and aliases them as callable functions with #[no_mangle], then defines a bunch of wrappers with Rust abi that should at some point be available independent of the ISA chosen in the backend.

Wtf

Indeed. Don't use in prod.

Demo?

See the example: cargo run --example simple.

Only works on x86_64-unknown-linux-* and should fail to compile on other architectures and OS's.

License

The base software: Unlicense


lib.rs:

Tables of possibly supported platforms.

Syscall and ret instructions and registers

Arch/ABI    Instruction           System# Ret1  Ret2
arm/OABI    swi NR                -       r0    -
arm/EABI    swi 0x0               r7      r0   r1
arm64       svc #0                w8      x0   x1
i386        int $0x80             eax     eax  edx
riscv       ecall                 a7      a0   a1
x86-64      syscall               rax     rax  rdx
x32         syscall               rax     rax  rdx

Argument registers

Arch/ABI      arg1  arg2  arg3  arg4  arg5  arg6  arg7  Notes
arm/OABI      r0    r1    r2    r3    r4    r5    r6
arm/EABI      r0    r1    r2    r3    r4    r5    r6
arm64         x0    x1    x2    x3    x4    x5    -
i386          ebx   ecx   edx   esi   edi   ebp   -
riscv         a0    a1    a2    a3    a4    a5    -
x86-64        rdi   rsi   rdx   r10   r8    r9    -
x32           rdi   rsi   rdx   r10   r8    r9    -

C-abi registers

Arch/ABI      a0    a1    a2    a3    a4    a5    ret1  ret2  caller
x86-64        rdi   rsi   rdx   rcx   r8    r9    rax   rdx   rbx,rsp,rbp

Dependencies

~3MB
~57K SLoC