[−][src]Struct ma_proper::MAProper
The MAProper
memory allocator
This memory allocator is an extension around std::alloc::System
which ensures that the
allocated memory is always erased before it is deallocated.
Using MAProper
as global allocator
#[global_allocator] static MA_PROPER: MAProper = MAProper; fn main() { // This `Vec` will allocate memory through `MA_PROPER` above let mut v = Vec::new(); v.push(1); }
How it works
Allocation
To ensure that we have enough information to erase everything, we allocate slightly more memory than requested and prepend some checksummed metadata to it. So a final chunk looks like this:
Layout: [ metadata | alignment padding | requested memory ]
Length: META_LEN | dynamic | user specified
Then we increment the pointer so that it points to requested memory
and return it.
Deallocation
Once the pointer is to be deallocated, we rewind the pointer so that it points to
metadata/length info
again to read and verify it. Once we know the length, we overwrite the
entire allocated space using one of
memset_s
/SecureZeroMemory
/explicit_bzero
/explicit_memset
.
Then we deallocate it.
Important
Please note that MAProper
only erases memory that is deallocated properly. This especially
means that:
- stack items are not overwritten by this allocator – to erase stack memory, we expose
MAProper::erase_slice
andMAProper::erase_ptr<T>
so that you can erase them manually if necessary - depending on your panic-policy and your
Rc
/Arc
use (retain-cycles), the destructor (and thus the deallocator) may never be called
Trait Implementations
impl GlobalAlloc for MAProper
[src]
Auto Trait Implementations
impl Send for MAProper
impl Sync for MAProper
impl Unpin for MAProper
impl UnwindSafe for MAProper
impl RefUnwindSafe for MAProper
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,