Ownership, borrowing and bounds checks keep access within live storage.
Every value must satisfy its type’s rules.
let bytes = vec![0_u8, 1, 2]; let view: &[u8] = &bytes;
let view: &[u8] = &[0, 1, 2]; let byte: u8 = view[2]; // third element
Types and borrowing rules constrain the program.
Runtime checks enforce rules that depend on actual values.
The FFI lets Rust declare and call a function implemented in another language.
The ABI specifies how compiled code passes arguments and returns results.
unsafe extern "C" { fn f() -> bool; }
extern "C"
unsafe
→ bool
let byte = 1_u8; let shared: &u8 = &byte; let raw: *const u8 = shared;
Assume a four-byte value requiring four-byte alignment. Addresses 100–103 are allocated.
Illustrative example · Adapted from Figure 2
false
true
u8
bool
?bool
A library can stay inside its memory region and still return the byte 2 where Rust expects a Boolean.
Confine the library to permitted memory.
Check the storage and the value before a read.
Keep those checks valid while Rust uses the view.
A strong runtime keeps the library out of host-private memory.
Check allocation, range, and alignment. The wrapper may still hold invalid bytes.
Validation establishes that the foreign bytes represent a valid T, allowing a scoped shared borrow.
T
A second pointer can change the value after validation, making the original check unreliable.
let mut byte = 1_u8; let a = &byte; let b = &byte; assert_eq!(*a, *b); // last use of both readers let writer = &mut byte; *writer = 0;
Both shared readers finish using the byte before Rust permits an exclusive write.
After the readers’ last use, the writer can borrow the same byte. Its owner releases it later.
AllocScope
A storage wrapper can live only as long as its allocation.
AccessScope
A live validated view blocks writes through other wrappers.
The call needs both scope markers exclusively.
Decoded PNG pixels are one example of a suitable foreign buffer.
RISC-V PMP confines lower-privilege code in Tock. The runtime controls when it runs.
x86 protection keys limit page access in Linux. The prototype relies on library cooperation.
PNG decoding produces a buffer of pixels. The researchers compare three ways to access that output.
Call the decoder directly and access its output.
Check the buffer and read it in place.
Serialize and copy the pixels across a process boundary.
Sandcrust isolates a separate process. OGMPK relies on library cooperation.
The plot measures total decode time. The authors attribute the widening gap to serializing and copying pixels between processes.
A strong runtime confines the library. Validation lets Rust read foreign data in place. Scopes keep that read valid through its last use.
OGMutRef<T>
&mut T
Two checked wrappers can point to the same byte.
A successful upgrade() proves the storage is usable. Writing through either wrapper still requires exclusive access to the library’s AccessScope.
upgrade()
A write can change a checked value while its allocation stays live.
The Tock prototype can confine an adversarial library. The Linux prototype relies on its cooperation.
Copy when Rust needs to keep the result beyond the foreign allocation’s lifetime.
Copy from readable storage, then validate the copied representation before using it as a typed value.
Borrow the checked output in place. The view ends when its scope does.
Protecting Rust’s soundness still leaves the host responsible for handling failure.
Safety requires boundaries.
Questions?