syscall_linux_raw/
lib.rs

1//! # Tables of possibly supported platforms.
2//!
3//! ## Syscall and ret instructions and registers 
4//!
5//! ```
6//! Arch/ABI    Instruction           System# Ret1  Ret2
7//! arm/OABI    swi NR                -       r0    -
8//! arm/EABI    swi 0x0               r7      r0   r1
9//! arm64       svc #0                w8      x0   x1
10//! i386        int $0x80             eax     eax  edx
11//! riscv       ecall                 a7      a0   a1
12//! x86-64      syscall               rax     rax  rdx
13//! x32         syscall               rax     rax  rdx
14//! ```
15//!
16//! ## Argument registers
17//!
18//! ```
19//! Arch/ABI      arg1  arg2  arg3  arg4  arg5  arg6  arg7  Notes
20//! arm/OABI      r0    r1    r2    r3    r4    r5    r6
21//! arm/EABI      r0    r1    r2    r3    r4    r5    r6
22//! arm64         x0    x1    x2    x3    x4    x5    -
23//! i386          ebx   ecx   edx   esi   edi   ebp   -
24//! riscv         a0    a1    a2    a3    a4    a5    -
25//! x86-64        rdi   rsi   rdx   r10   r8    r9    -
26//! x32           rdi   rsi   rdx   r10   r8    r9    -
27//! ```
28//!
29//! ## C-abi registers
30//!
31//! ```
32//! Arch/ABI      a0    a1    a2    a3    a4    a5    ret1  ret2  caller
33//! x86-64        rdi   rsi   rdx   rcx   r8    r9    rax   rdx   rbx,rsp,rbp
34//! ```
35// Prepare for the future, we might want to justify our inner translation.
36#![allow(unused_unsafe)]
37#![no_std]
38
39#[cfg(target_arch = "x86_64")]
40#[path = "x86_64.rs"]
41mod impl_;
42
43/* These are not yet supported by the assembler. Compiling them would yield invalid
44 * instructions on their platforms.
45#[cfg(target_arch = "x86")]
46#[path = "x86.rs"]
47mod impl_;
48
49#[cfg(target_arch = "aarch64")]
50#[path = "aarch64.rs"]
51mod impl_;
52*/
53
54
55/// A helper to distinguish the syscall number from other parameters.
56///
57/// We can't really help you with others but this one is somewhat important. Furthermore it's a
58/// great help internally where it ensure we've placed the parameter at the right location. The
59/// type is a transparent wrapper.
60///
61/// This further enables a namespaced access to constants and call numbers that are conditionally
62/// available per system ABI.
63#[repr(transparent)]
64pub struct SysNr(pub isize);
65
66#[cfg(target_os = "linux")]
67pub unsafe fn syscall0(nr: SysNr) -> isize {
68    // Translate to the inner abi
69    unsafe { impl_::call0(nr) }
70}
71
72#[cfg(target_os = "linux")]
73pub unsafe fn syscall1(nr: SysNr, a: isize) -> isize {
74    // Translate to the inner abi
75    unsafe { impl_::call1(a, nr) }
76}
77
78#[cfg(target_os = "linux")]
79pub unsafe fn syscall2(nr: SysNr, a: isize, b: isize) -> isize {
80    // Translate to the inner abi
81    unsafe { impl_::call2(a, b, nr) }
82}
83
84#[cfg(target_os = "linux")]
85pub unsafe fn syscall3(nr: SysNr, a: isize, b: isize, c: isize) -> isize {
86    // Translate to the inner abi
87    unsafe { impl_::call3(a, b, c, nr) }
88}
89
90#[cfg(target_os = "linux")]
91pub unsafe fn syscall4(nr: SysNr, a: isize, b: isize, c: isize, d: isize) -> isize {
92    // Translate to the inner abi
93    unsafe { impl_::call4(a, b, c, d, nr) }
94}
95
96#[cfg(target_os = "linux")]
97pub unsafe fn syscall5(nr: SysNr, a: isize, b: isize, c: isize, d: isize, e: isize) -> isize {
98    // Translate to the inner abi
99    unsafe { impl_::call5(a, b, c, d, e, nr) }
100}