unilink  0.4.3
A simple C++ library for unified async communication
unilink::memory::memory_validator Namespace Reference

Memory validation utilities for enhanced safety. More...

Functions

bool is_memory_accessible (const void *ptr, size_t size)
 Validate memory region accessibility. More...
 
bool is_memory_aligned (const void *ptr, size_t alignment)
 Validate memory alignment. More...
 
bool check_buffer_bounds (const void *ptr, size_t size, size_t canary_size=8)
 Check for buffer overflow/underflow patterns. More...
 
void initialize_canary_bytes (void *ptr, size_t size, size_t canary_size=8)
 Initialize canary bytes around buffer. More...
 
bool validate_canary_bytes (const void *ptr, size_t size, size_t canary_size=8)
 Validate canary bytes around buffer. More...
 
void safe_memcpy_validated (void *dest, const void *src, size_t size)
 Safe memory copy with comprehensive validation. More...
 
void safe_memmove_validated (void *dest, const void *src, size_t size)
 Safe memory move with comprehensive validation. More...
 
void safe_memset_validated (void *ptr, int value, size_t size)
 Safe memory set with comprehensive validation. More...
 
bool is_double_free (void *ptr)
 Check for double-free conditions. More...
 
bool is_use_after_free (const void *ptr)
 Check for use-after-free conditions. More...
 

Detailed Description

Memory validation utilities for enhanced safety.

Function Documentation

◆ check_buffer_bounds()

bool unilink::memory::memory_validator::check_buffer_bounds ( const void *  ptr,
size_t  size,
size_t  canary_size = 8 
)

Check for buffer overflow/underflow patterns.

Parameters
ptrPointer to buffer
sizeBuffer size
canary_sizeSize of canary bytes to check
Returns
true if no overflow detected, false if overflow found

◆ initialize_canary_bytes()

void unilink::memory::memory_validator::initialize_canary_bytes ( void *  ptr,
size_t  size,
size_t  canary_size = 8 
)

Initialize canary bytes around buffer.

Parameters
ptrPointer to buffer
sizeBuffer size
canary_sizeSize of canary bytes

◆ is_double_free()

bool unilink::memory::memory_validator::is_double_free ( void *  ptr)

Check for double-free conditions.

Parameters
ptrPointer that was freed
Returns
true if this is a potential double-free

◆ is_memory_accessible()

bool unilink::memory::memory_validator::is_memory_accessible ( const void *  ptr,
size_t  size 
)

Validate memory region accessibility.

Parameters
ptrPointer to memory region
sizeSize of memory region
Returns
true if memory is accessible, false otherwise

◆ is_memory_aligned()

bool unilink::memory::memory_validator::is_memory_aligned ( const void *  ptr,
size_t  alignment 
)

Validate memory alignment.

Parameters
ptrPointer to check
alignmentRequired alignment
Returns
true if properly aligned, false otherwise

◆ is_use_after_free()

bool unilink::memory::memory_validator::is_use_after_free ( const void *  ptr)

Check for use-after-free conditions.

Parameters
ptrPointer to check
Returns
true if pointer appears to be used after free

◆ safe_memcpy_validated()

void unilink::memory::memory_validator::safe_memcpy_validated ( void *  dest,
const void *  src,
size_t  size 
)

Safe memory copy with comprehensive validation.

Parameters
destDestination buffer
srcSource buffer
sizeNumber of bytes to copy
Exceptions
std::invalid_argumentif validation fails

◆ safe_memmove_validated()

void unilink::memory::memory_validator::safe_memmove_validated ( void *  dest,
const void *  src,
size_t  size 
)

Safe memory move with comprehensive validation.

Parameters
destDestination buffer
srcSource buffer
sizeNumber of bytes to move
Exceptions
std::invalid_argumentif validation fails

◆ safe_memset_validated()

void unilink::memory::memory_validator::safe_memset_validated ( void *  ptr,
int  value,
size_t  size 
)

Safe memory set with comprehensive validation.

Parameters
ptrPointer to buffer
valueValue to set
sizeNumber of bytes to set
Exceptions
std::invalid_argumentif validation fails

◆ validate_canary_bytes()

bool unilink::memory::memory_validator::validate_canary_bytes ( const void *  ptr,
size_t  size,
size_t  canary_size = 8 
)

Validate canary bytes around buffer.

Parameters
ptrPointer to buffer
sizeBuffer size
canary_sizeSize of canary bytes
Returns
true if canaries are intact, false if corrupted