8 breaking releases

0.9.0 Feb 21, 2023
0.7.0 Feb 13, 2023

#750 in Unix APIs

Download history 11/week @ 2024-02-26 2/week @ 2024-03-04 10/week @ 2024-03-11 29/week @ 2024-04-01 1/week @ 2024-04-08 16/week @ 2024-04-15 12/week @ 2024-04-22

58 downloads per month
Used in 2 crates

MIT license

65KB
1.5K SLoC

A low-level, unsafe Rust interface to Linux system calls.

The [raw] module provides functions wrapping platform-specific assembly language stubs for making arbitrary system calls by providing a system call number and arbitrary number of arguments.

This crate currently supports the following architectures:

  • x86_64
  • x86 (32-bit)
  • arm
  • riscv64

For this initial release, x86_64 has seen some limited testing and the other platforms have been barely tested at all. Over time I intend to support all architectures that Linux supports that are also supported by Rust inline assembly, but we'll see how it goes.

The functions in the root of the crate then wrap those stubs with thin wrappers that just lightly convert their arguments to what the kernel expects for a particular system call and then delegate to one of the system call stubs in [raw].

This crate also includes a number of types and type aliases representing the memory layout of objects the kernel will interpret. For those which are aliases, calling code must always use the aliases rather than their underlying types because their exact definitions may vary on different platforms and in future versions of this crate.

Where possible the wrapping functions and types are portable across architectures, as long as callers use the argument types and type aliases defined in this crate. The raw system call interface has considerable overlap between platforms but is ultimately architecture-specific and this crate does not attempt to hide differences at that layer.

Be careful mixing with std

The Rust std crate has lots of functionality that wraps the target's libc functions. On Linux systems libc is a wrapper around the same system call interface this crate is exposing, but also adds other state and abstractions such as buffers and error codes. Making direct system calls may violate the assumptions being made by libc.

To avoid strange problems, avoid interacting with the same system resources through both the standard library and though direct system calls.

Dependencies

~43KB