diff --git a/tlsf.c b/tlsf.c index 0f46a35..28929cd 100644 --- a/tlsf.c +++ b/tlsf.c @@ -456,6 +456,12 @@ static inline __attribute__((always_inline)) block_header_t* block_absorb(block_ /* Note: Leaves flags untouched. */ prev->size += block_size(block) + block_header_overhead; block_link_next(prev); + + if (block_absorb_post_hook != NULL) + { + block_absorb_post_hook(block, sizeof(block_header_t), POISONING_AFTER_FREE); + } + return prev; } diff --git a/tlsf.h b/tlsf.h index d7ca958..35adb13 100644 --- a/tlsf.h +++ b/tlsf.h @@ -8,6 +8,7 @@ #define INCLUDED_tlsf #include +#include #if defined(__cplusplus) extern "C" { @@ -52,6 +53,16 @@ void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user); int tlsf_check(tlsf_t tlsf); int tlsf_check_pool(pool_t pool); +/*! + * @brief Weak function filling the given memory with a given fill pattern. + * + * @param start: pointer to the start of the memory region to fill + * @param size: size of the memory region to fill + * @param is_free: Indicate if the pattern to use the fill the region should be + * an after free or after allocation pattern. + */ +__attribute__((weak)) void block_absorb_post_hook(void *start, size_t size, bool is_free); + #if defined(__cplusplus) }; #endif diff --git a/tlsf_common.h b/tlsf_common.h index 0f89ab6..7af2a2a 100644 --- a/tlsf_common.h +++ b/tlsf_common.h @@ -6,15 +6,19 @@ #pragma once #include - -#if defined __has_include && __has_include("tlsf_platform.h") -#include "tlsf_platform.h" -#endif +#include #if defined(__cplusplus) extern "C" { #endif +/* +** Constants definition for poisoning. +** These defines are used as 3rd argument of tlsf_poison_fill_region() for readability purposes. +*/ +#define POISONING_AFTER_FREE true +#define POISONING_AFTER_MALLOC !POISONING_AFTER_FREE + /* ** Cast and min/max macros. */