pub struct GuardPage<I: OsBacked> { /* private fields */ }Expand description
Guard-page wrapper.
At construction, inner.protect(...) marks the first and last
page_size bytes of the inner region as PROT_NONE. The wrapper then
allocates bump-style from the strictly-interior subrange.
§Thread safety
Send when I: Send. Sync: NO — the cursor uses UnsafeCell.
Implementations§
Source§impl<I: OsBacked> GuardPage<I>
impl<I: OsBacked> GuardPage<I>
Sourcepub fn new(inner: I, page_size: usize) -> Result<Self, AllocError>
pub fn new(inner: I, page_size: usize) -> Result<Self, AllocError>
Wrap with leading + trailing guard pages of page_size bytes each.
Errors if page_size is zero / not a power of two, if inner.base_ptr()
is not page_size-aligned, or if the region is too small.
Trait Implementations§
Source§impl<I: OsBacked> Allocator for GuardPage<I>
impl<I: OsBacked> Allocator for GuardPage<I>
Source§fn allocate(&self, layout: NonZeroLayout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: NonZeroLayout) -> Result<NonNull<[u8]>, AllocError>
Allocate a block satisfying
layout. The returned slice’s length is
at least layout.size() but may be larger.Source§fn capacity_bytes(&self) -> Option<usize>
fn capacity_bytes(&self) -> Option<usize>
Total bytes this allocator can issue, if bounded.
None for unbounded
allocators like System. Used by Watermark to compute thresholds.Source§fn corruption_events(&self) -> u64
fn corruption_events(&self) -> u64
Detected freelist / metadata corruption events observed by this
allocator since construction. Read more
Source§fn allocate_zeroed(
&self,
layout: NonZeroLayout,
) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed( &self, layout: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>
Allocate a zero-initialized block.
Source§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old: NonZeroLayout,
new: NonZeroLayout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old: NonZeroLayout, new: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>
Grow an allocation in place if possible, otherwise allocate-copy-free. Read more
Source§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old: NonZeroLayout,
new: NonZeroLayout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old: NonZeroLayout, new: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>
Shrink an allocation in place if possible, otherwise allocate-copy-free. Read more
Source§fn reset(&mut self) -> Result<(), AllocError>
fn reset(&mut self) -> Result<(), AllocError>
Reclaim everything previously allocated. Default impl returns
AllocError — only arena-style allocators implement a meaningful
reset. Read moreSource§unsafe fn usable_size(
&self,
_ptr: NonNull<u8>,
_layout: NonZeroLayout,
) -> Option<usize>
unsafe fn usable_size( &self, _ptr: NonNull<u8>, _layout: NonZeroLayout, ) -> Option<usize>
Usable size of an existing allocation, if the allocator can report
it. Defaults to
None — implementors that track usable size
override. Read moreSource§impl<I: OsBacked> Deallocator for GuardPage<I>
impl<I: OsBacked> Deallocator for GuardPage<I>
Source§unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: NonZeroLayout)
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: NonZeroLayout)
Release a previously allocated block. Read more
Source§impl<I: OsBacked> FixedRange for GuardPage<I>
impl<I: OsBacked> FixedRange for GuardPage<I>
impl<I: OsBacked + Send> Send for GuardPage<I>
Auto Trait Implementations§
impl<I> !Freeze for GuardPage<I>
impl<I> !RefUnwindSafe for GuardPage<I>
impl<I> !Sync for GuardPage<I>
impl<I> Unpin for GuardPage<I>where
I: Unpin,
impl<I> UnsafeUnpin for GuardPage<I>where
I: UnsafeUnpin,
impl<I> UnwindSafe for GuardPage<I>where
I: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more