Types for volatile access to memory.
Two of the core rules for safe rust is no data races and no aliased mutable references.
VolatileSlice, along with types that produce it which implement
VolatileMemory, allow us to sidestep that rule by wrapping pointers that absolutely have to be
accessed volatile. Some systems really do need to operate on shared memory and can’t have the
compiler reordering or eliding access because it has no visibility into what other systems are
doing with that hunk of memory.
For the purposes of maintaining safety, volatile memory has some rules of its own:
- No references or slices to volatile memory (
- Access should always been done with a volatile read or write. The First rule is because having references of any kind to memory considered volatile would violate pointer aliasing. The second is because unvolatile accesses are inherently undefined if done concurrently without synchronization. With volatile access we know that the compiler has not reordered or elided the access.
- A slice of raw memory that supports volatile access. Like
std::io::IoSliceMut, this type is guaranteed to be ABI-compatible with
IoSliceMut, it doesn’t automatically deref to
- Trait for types that support raw volatile access to their data.
- Check whether every byte is zero.
- Result 🔒