rustix

Memory-safe, I/O-safe Rust bindings to POSIX, Linux, and Winsock syscalls with swappable libc and raw syscall backends.

Library
Cargo
v1.1.4
2,086stars
Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
69/100Good
Development Activity64
Maintenance36
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
87/100Excellent
Architecture88
Code Quality92
Innovation87
Learning Curve80

rustix provides safe, efficient Rust bindings to POSIX-like, Unix-like, Linux, and Winsock syscall APIs. Instead of raw pointers and bare file descriptors, it exposes Rust slices, Result-based error handling, bitflags-typed constants, and I/O-safe types like OwnedFd and AsFd, so calling code gets memory safety and I/O safety all the way down to the underlying system call.

The crate ships two interchangeable backends: linux_raw, which issues raw Linux syscalls directly via inline assembly (with vDSO acceleration for functions like clock_gettime) and avoids linking libc entirely on supported architectures, and a portable libc-based backend for other Unix platforms plus Winsock on Windows. Individual API surfaces — filesystem, networking, io_uring, memory mapping, mount, process, threading, terminal I/O, and more — are gated behind Cargo features, so consumers compile only the syscalls they use, and the crate can run under #![no_std].

What You Get

  • Safe wrappers over filesystem, network, process, threading, memory-mapping, and terminal syscalls, gated behind Cargo features
  • A direct linux_raw backend that issues Linux syscalls via inline asm without linking libc, plus a portable libc/Winsock backend for everywhere else
  • I/O-safe file descriptor handling via OwnedFd/AsFd instead of raw integers, with an Arg trait that accepts any Rust string type for path arguments
  • Automatic 64-bit large-file and year-2038-safe API selection, so callers don’t have to special-case l/64-suffixed libc functions
  • A #![no_std]-compatible core with vDSO-accelerated clock_gettime on Linux

Common Use Cases

  • Low-level systems tools - building CLI utilities and system daemons that need direct syscall access without libc’s FFI overhead or ergonomics gaps
  • Portable POSIX libraries - crates that need a safe, cross-platform syscall layer to build higher-level abstractions on top of
  • io_uring-based I/O - applications wiring up Linux io_uring rings directly for high-throughput I/O
  • Sandboxing and container tooling - programs that call mount, pivot_root, or process/namespace syscalls directly

Under The Hood

Architecture rustix splits into a backend-agnostic public API (src/fs, src/net, src/process, src/thread, src/mm, src/mount, src/io_uring, src/termios, src/event, src/rand, src/pty, src/shm, src/time, src/param) and two swappable backend implementations under src/backend/linux_raw and src/backend/libc. The linux_raw backend (mod.rs, conv.rs, reg.rs, vdso.rs, vdso_wrappers.rs) issues raw syscalls through hand-written architecture registers and inline assembly, entirely bypassing libc, while src/backend/libc (c.rs, conv.rs, winsock_c.rs) wraps the libc crate and windows-sys for Winsock. build.rs picks the active backend per target at compile time, and the crate enforces #![cfg_attr(linux_raw, deny(unsafe_code))] so the public API modules stay safe even though the backend does raw pointer and register work underneath — a clean, auditable boundary between unsafe internals and a safe surface.

Tech Stack rustix is a Rust crate (MSRV 1.65, edition 2021) with a minimal core dependency on bitflags 2.4; the linux_raw path adds linux-raw-sys for raw syscall/struct definitions, while the libc path adds the libc crate, the errno crate (aliased libc_errno), and windows-sys for Winsock on Windows. Dev-dependencies include tempfile and serial_test for filesystem/process tests that must run in isolation, criterion for benchmarks, and static_assertions for compile-time invariant checks. CI (.github/workflows/main.yml, test-users.yml) exercises many target architectures and OSes via a dedicated ci/ directory of QEMU and cross-compilation configs.

Code Quality The repository carries 128 test files under tests/, organized to mirror the public module layout (tests/fs, tests/net, tests/process, tests/thread, tests/io_uring, tests/mount, tests/pty, and more), plus 10 runnable examples in examples/. #![deny(missing_docs)] is enforced crate-wide, giving every public item a documentation comment, and #![cfg_attr(linux_raw, deny(unsafe_code))] forces the safe-API modules to route all unsafety through the backend layer rather than scattering unsafe throughout feature code — a strong discipline signal for a syscall-wrapping crate. Feature combinations (--features=all-apis, --features=all-apis,use-libc) are tested explicitly per CONTRIBUTING.md.

What Makes It Unique Unlike crates that simply re-export libc syscalls with light typing, rustix’s linux_raw backend implements Linux syscalls itself using Rust’s asm! macro, avoiding libc, errno, and pthread-cancellation overhead entirely on supported architectures, and using Linux’s vDSO to accelerate clock_gettime and, on x86, other calls. Its I/O-safety guarantees (OwnedFd/AsFd throughout) and its Arg trait for accepting arbitrary string types extend memory- and type-safety guarantees further down the stack than comparable crates like nix, while still supporting a portable libc fallback for platforms the raw backend doesn’t cover.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search