pub unsafe trait Backend<T> {
    type Stored: Copy;
    fn get_ptr(s: Self::Stored) -> (*mut T, Self);
    fn set_ptr(provenance: *mut T, addr: Self) -> Self::Stored;
    fn get_int(s: Self::Stored) -> Self;
}
Expand description

A backend where the stuffed pointer is stored. Must be bigger or equal to the pointer size.

The Backend is a trait to define types that store the stuffed pointer. It’s supposed to be implemented on Copy types like usize``u64, u128. Note that these integers are basically just the strategy and exchange types for addresses, but not the actual underlying storage, which always contains a pointer to keep provenance (for example (*mut T, u32) on 32 bit for u64).

This trait is just exposed for convenience and flexibility, you are usually not expected to implement it yourself, although such occasions could occur (for example to have a bigger storage than u128 or smaller storage that only works on 32-bit or 16-bit platforms.

Safety

Implementers of this trait must keep provenance of pointers, so if a valid pointer address+provenance combination is set in set_ptr, get_ptr must return the exact same values and provenance.

Associated Types

The underlying type where the data is stored. Often a tuple of a pointer (for the provenance) and some integers to fill up the bytes.

Required methods

Get the pointer from the backed. Since the crate::StuffingStrategy is able to use the full bytes to pack in the pointer address, the full address is returned in the second tuple field, as the integer. The provenance of the pointer is returned as the first tuple field, but its address should be ignored and may be invalid.

Set a new pointer address. The provenance of the new pointer is transferred in the first argument, and the address in the second. See Backend::get_ptr for more details on the separation.

Get the integer value from the backend. Note that this must not be used to create a pointer, for that use Backend::get_ptr to keep the provenance.

Implementations on Foreign Types

on 64 bit, we can just treat u64/usize interchangeably, because uintptr_t == size_t in Rust

Implementors