Pigweed
 
Loading...
Searching...
No Matches
pw::allocator::PoisonableBlock< Derived > Class Template Reference

#include <poisonable.h>

Inheritance diagram for pw::allocator::PoisonableBlock< Derived >:
pw::allocator::internal::PoisonableBase

Public Member Functions

constexpr uintptr_t GetPoisonWord () const
 Returns the value written to a block's usable space when poisoning.
 
constexpr bool IsPoisoned () const
 Returns whether this block has been poisoned.
 
constexpr void Poison ()
 

Static Public Attributes

static constexpr size_t kPoisonOffset = Derived::ReservedWhenFree()
 

Protected Member Functions

constexpr uintptr_t DoGetPoisonWord () const
 
constexpr Derived * DoSplitFirst (size_t new_inner_size)
 
constexpr Derived * DoSplitLast (size_t new_inner_size)
 
constexpr void DoMergeNext ()
 
constexpr bool DoCheckInvariants (bool strict) const
 Like IsValid, but crashes if invalid.
 
constexpr void SetFree (bool is_free)
 Clears the poisoned state if a block is not free.
 

Detailed Description

template<typename Derived>
class pw::allocator::PoisonableBlock< Derived >

Mix-in for blocks that can be poisoned.

A poisoned block's usable space contains pattern of data whose integrity can be checked later for modification.

Block mix-ins are stateless and trivially constructible. See BasicBlock for details on how mix-ins can be combined to implement blocks.

This mix-in requires its derived type also derive from ContiguousBlock and provide the following method:

  • static consextpr size_t ReservedWhenFree()
    • Indicates how many bytes should not be poisoned.
  • bool IsPoisoned() const
    • Returns whether the block is poisoned.
  • void SetPoisoned(bool)
    • Sets whether the block is poisoned.

Member Function Documentation

◆ DoCheckInvariants()

template<typename Derived >
constexpr bool pw::allocator::PoisonableBlock< Derived >::DoCheckInvariants ( bool  strict) const
constexprprotected

Like IsValid, but crashes if invalid.

◆ DoMergeNext()

template<typename Derived >
constexpr void pw::allocator::PoisonableBlock< Derived >::DoMergeNext
constexprprotected

Merges this block with next block.

This method is static in order to consume and replace the given block pointer with a pointer to the new, larger block.

Precondition
The blocks must not be in use.

◆ DoSplitFirst()

template<typename Derived >
constexpr Derived * pw::allocator::PoisonableBlock< Derived >::DoSplitFirst ( size_t  new_inner_size)
constexprprotected

Split a block into two smaller blocks.

This method splits a block into a leading block of the given new_inner_size and a trailing block, and returns the trailing space as a new block.

Precondition
The block must not be in use.
The block must have enough usable space for the requested size.
The space remaining after a split can hold a new block.

◆ DoSplitLast()

template<typename Derived >
constexpr Derived * pw::allocator::PoisonableBlock< Derived >::DoSplitLast ( size_t  new_inner_size)
constexprprotected

Split a block into two smaller blocks.

This method splits a block into a leading block and a trailing block of the given new_inner_size, and returns the trailing space is returned as a new block.

Precondition
The block must not be in use.
The block must have enough usable space for the requested size.
The space remaining after a split can hold a new block.

◆ Poison()

template<typename Derived >
constexpr void pw::allocator::PoisonableBlock< Derived >::Poison
constexpr

Poisons the block's usable space.

This method does nothing if the block is not free. The decision to poison a block is delegated to the allocator to allow for more nuanced strategies than simply all or nothing. For example, an allocator may want to balance security and performance by only poisoning every n-th free block.


The documentation for this class was generated from the following file: