8 unstable releases (3 breaking)
0.4.0 | Nov 9, 2023 |
---|---|
0.3.4 | Jul 30, 2023 |
0.2.1 | Nov 6, 2023 |
0.2.0 | May 31, 2023 |
0.1.0 | Mar 21, 2023 |
Used in azur
120KB
3.5K
SLoC
A Rust no_std
library to use userspace Linux ABI designed to have no overhead,
but still be safe when possible by leveraging Rust's type system.
The code must be carefully organized such that someone who has not read it yet can quickly guess what a file corresponds to, or where something is implemented, and how it works: it must be hackable without reading lots of context.
An implication is that the style must remain coherent across the code base, to make the organization predictable.
Code duplication must be avoided, but only when the duplicated piece of code makes sense as a whole, and has a descriptive name that fits well enough.
lib.rs
:
A no_std
interface to the userspace Linux ABI designed to have no overhead, but still be safe
when possible by leveraging Rust's type system.
Result overhead
Although types like Result<(), i32>
are sometimes used in place of the smaller i32
which
can both represent errors and values on success, it doesn't add memory overhead or register
pressure in practice because functions are inlined.
To verify this, try to look at the assembler generated by this code when optimizations are enabled:
extern "C" {
fn fallible() -> i32;
fn test_succeeded();
fn test_failed(err: i32);
}
fn fallible_safe() -> Result<(), i32> {
let ret = unsafe { fallible() };
if ret < 0 {
return Err(ret);
}
Ok(())
}
pub fn test() {
if let Err(e) = fallible_safe() {
unsafe { test_failed(e) };
return;
}
unsafe { test_succeeded() };
}