mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
heap: Provide definition of the tlsf_check_hook() declared in the tlsf submodule
Add the definition of tlsf_check_hook() in multi_heap if MULTI_HEAP_POISONING is set. This definition calls the multi_heap_internal_check_block_poisoning() to check the memory of a free block for corruption. If the light poisoinng is set this function returns true. If the comprehensive poisoning is set, this function will check that all byte of memory in the memory chunk passed as parameter are set to the right FILL pattern.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user