Crates.io | linux-support |
lib.rs | linux-support |
version | 0.0.25 |
source | src |
created_at | 2020-04-30 17:41:26.606119 |
updated_at | 2021-05-28 12:26:30.824388 |
description | Comprehensive Linux support for namespaces, cgroups, processes, scheduling, parsing /proc, parsing /sys, signals, hyper threads, CPUS, NUMA nodes, unusual file descriptors, PCI devices and much, much more |
homepage | https://github.com/lemonrock/linux-support |
repository | https://github.com/lemonrock/linux-support.git |
max_upload_size | |
id | 235902 |
size | 6,654,898 |
linux-support is a Rust crate for comprehensive Linux support for namespaces, cgroups, processes, scheduling, parsing a vast number of files in /proc
and /sys
, signals, hyper threads, CPUS, NUMA nodes, io-uring, io scheduling priority, unusual file descriptors (including pid descriptors and userfaultfd), seccomp BPF filters (including a Rust abstraction), PCI devices, atomic file renames, and much, much more.
It is intended to be a holistic, very strongly typed and properly modelled library for working with Linux's non-POSIX features, with a particular focus on being a support library for a secure root daemon running a userspace networking stack that I'm developing. As a result, it's highly opionated; it happily makes use of unsafe code, nightly features and uninitialized()
.
File descriptors, process and vectored-io are tightly integrated.
It replaces several C and Rust libraries including:-
libnuma
.libhugetlbfs
.libcpuset
(planned).It is not intended to replace nix, but as an alternative for Linux-specific applications.
/proc
and /sys
to work out what's available
/proc/<N>/cmdline
and /proc/<N>/environ
.const
-friendly logic to get page size, ie not sysconf(_SC_PAGE_SIZE)
!at()
system calls.copy_file_range
./proc/<N>/stat
, /proc/<N>/statm
and /proc/<N>/status
.get_program_name
./proc/<N>/environ
./proc
and /sys
.Currently only Linux using the musl libc has been tested, but support should be possible with minor changes for Android, Fuschia and Emscripten.
The primary architecture of the crate is 64-bit systems, with x86-64 a first tier architecture. Support is then secondary for aarch64 and riscv64 and 'best efforts' for powerpc64, mips64 and sparc64.
No support is planned for any 32-bit system.
It uses nightly because Rust still hasn't stabilized important features after 4 years.
This is a Rust module wrapping the various kinds of file descriptors with safe abstractions, including IPv4 / IPv6 sockets, Unix domain sockets, epoll, timerfd, signalfd, eventfd, POSIX message queues, pipes, FIFOs, terminals (and serial ports), character devices, inotify, fanotify and Files.
There is a particularly extensive and safe wrapper for signals and terminals.
file
module.sendfile()
with Rust's std::file::File
supported).std::fs::File
:-
SendFile
SpliceRecipient
SpliceSender
memfd
Additionally, extensions (SendFile
, SpliceRecipient
and SpliceSender
) are implemented for Rust's File
.
The above features may not work correctly after the use of seccomp
to lock down system calls (particularly the attempt to delete a socket file path on close).
The use of splice()
, vmsplice()
and tee()
are supported for all file descriptors where possible (including Rust's std::fs::File
).
To be able to use epoll with standard in (stdin
), use pipes_and_fifos::ReceivePipeFileDescriptor::standard_in()
.
To be able to use epoll with standard out (stdout
), use pipes_and_fifos::SendPipeFileDescriptor::standard_out()
.
To be able to use epoll with standard error (stderr
), use pipes_and_fifos::SendPipeFileDescriptor::standard_error()
.
Linux zero copy send (MSG_ZEROCOPY
) and receive (SO_ZEROCOPY
), mostly because they have a horrible, hacky API.
Unix Domain Sockets using autobind
; setting of the SO_PASSCRED
socket option.
Receiving credentials over Unix Domain Sockets using recvmsg()
.
infiniband sockets.
canbus (SocketCAN sockets and can4linux http://can-wiki.info/can4linux/man/can4linux_8h_source.html character device drivers).
The license for this project is AGPL-3.0.