3 stable releases

1.2.0 May 6, 2025
1.1.0 Mar 11, 2025
1.0.0 Sep 10, 2022

#263 in Unix APIs

Download history 104/week @ 2025-08-18 119/week @ 2025-08-25 250/week @ 2025-09-01 197/week @ 2025-09-08 219/week @ 2025-09-15 409/week @ 2025-09-22 199/week @ 2025-09-29 151/week @ 2025-10-06 417/week @ 2025-10-13 676/week @ 2025-10-20 303/week @ 2025-10-27 712/week @ 2025-11-03 871/week @ 2025-11-10 633/week @ 2025-11-17 253/week @ 2025-11-24 247/week @ 2025-12-01

2,025 downloads per month

0BSD license

145KB
3.5K SLoC

This library defines syscall numbers and a syscall! macro for directly invoking Linux system calls.

The arch modules document available syscall numbers for all supported architectures, and the top-level module re-exports syscall numbers for the current target platform.

Syscall results may be inspected with the Result* traits.

Example

let stdout: i32 = 1;
let hello = "Hello, world!\n\0";
let rc = unsafe {
	syscall!(SYS_write, stdout, hello.as_ptr(), hello.len())
};
rc.check()?;

Safety

Very unsafe.

Linux syscalls are low-level primitives that operate without any notion of borrow checking or type safety. It is the caller's responsibility to ensure parameters have types, values, and lifetimes appropriate to the syscall being invoked.

  • The kernel cannot distinguish *const T and *mut T.
  • Many syscalls accept complex parameters as pointers to a struct. The caller must ensure such parameters have appropriate layout and alignment.
  • Syscalls vary between architectures. The same syscall name may have a completely different signature even on similar targets, for example SYS_mmap on x86 and x86_64.

Linux syscall macros for Rust

This library defines syscall numbers and a syscall! macro for directly invoking Linux system calls.

The arch modules document available syscall numbers for all supported architectures, and the top-level module re-exports syscall numbers for the current target platform.

Supported architectures:

  • aarch64
  • arm
  • loongarch64
  • riscv64
  • s390x
  • x86
  • x86_64

To be supported by this library, an architecture must:

Dependencies