diff --git a/components/heap/include/multi_heap.h b/components/heap/include/multi_heap.h index 6b0990c72d..e2aa6672d7 100644 --- a/components/heap/include/multi_heap.h +++ b/components/heap/include/multi_heap.h @@ -125,6 +125,8 @@ void multi_heap_dump(multi_heap_handle_t heap); * can be optionally printed to stderr. Print behaviour can be overridden at compile time by defining * MULTI_CHECK_FAIL_PRINTF in multi_heap_platform.h. * + * @note This function is not thread-safe as it sets a global variable with the value of print_errors. + * * @param heap Handle to a registered heap. * @param print_errors If true, errors will be printed to stderr. * @return true if heap is valid, false otherwise. diff --git a/components/heap/multi_heap.c b/components/heap/multi_heap.c index 1a0871f457..9431a23771 100644 --- a/components/heap/multi_heap.c +++ b/components/heap/multi_heap.c @@ -309,13 +309,46 @@ void *multi_heap_aligned_alloc_impl(multi_heap_handle_t heap, size_t size, size_ return multi_heap_aligned_alloc_impl_offs(heap, size, alignment, 0); } +#ifdef MULTI_HEAP_POISONING +/*! + * @brief Global definition of print_errors set in multi_heap_check() when + * MULTI_HEAP_POISONING is active. Allows the transfer of the value to + * multi_heap_poisoning.c without having to propagate it to the tlsf submodule + * and back. + */ +static bool g_print_errors = false; + +/*! + * @brief Definition of the weak function declared in TLSF repository. + * The call of this function execute a check for block poisoning on the memory + * chunk passed as parameter. + * + * @param start: pointer to the start of the memory region to check for corruption + * @param size: size of the memory region to check for corruption + * @param is_free: indicate if the pattern to use the fill the region should be + * an after free or after allocation pattern. + * + * @return bool: true if the the memory is not corrupted, false if the memory if corrupted. + */ +bool tlsf_check_hook(void *start, size_t size, bool is_free) +{ + return multi_heap_internal_check_block_poisoning(start, size, is_free, g_print_errors); +} +#endif // MULTI_HEAP_POISONING + bool multi_heap_check(multi_heap_handle_t heap, bool print_errors) { - (void)print_errors; bool valid = true; assert(heap != NULL); multi_heap_internal_lock(heap); + +#ifdef MULTI_HEAP_POISONING + g_print_errors = print_errors; +#else + (void) print_errors; +#endif + if(tlsf_check(heap->heap_data)) { valid = false; } diff --git a/components/heap/tlsf b/components/heap/tlsf index ff11688f24..ab17d6798d 160000 --- a/components/heap/tlsf +++ b/components/heap/tlsf @@ -1 +1 @@ -Subproject commit ff11688f242b28b3918c2cdaa20738d12d73b5f4 +Subproject commit ab17d6798d1561758827b6553d56d57f19aa4d66