#linux #syscall #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

#225 in Unix APIs

Download history 170/week @ 2022-03-09 179/week @ 2022-03-16 160/week @ 2022-03-23 145/week @ 2022-03-30 210/week @ 2022-04-06 151/week @ 2022-04-13 140/week @ 2022-04-20 222/week @ 2022-04-27 192/week @ 2022-05-04 197/week @ 2022-05-11 186/week @ 2022-05-18 92/week @ 2022-05-25 129/week @ 2022-06-01 252/week @ 2022-06-08 232/week @ 2022-06-15 101/week @ 2022-06-22

730 downloads per month

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

~0.5–1MB
~22K SLoC