Merge branch 'bugfix/fix_tlsf_patch_esp32c2' into 'master'

TLSF: fix the patch for tlsf_check function in ROM

Closes IDFCI-1442 and IDFCI-1441

See merge request espressif/esp-idf!19839
This commit is contained in:
Zim Kalinowski
2022-09-13 18:32:40 +08:00
5 changed files with 103 additions and 23 deletions

View File

@@ -81,7 +81,7 @@ typedef struct multi_heap_info {
void* heap_data;
} heap_t;
#ifdef CONFIG_HEAP_TLSF_USE_ROM_IMPL
#if CONFIG_HEAP_TLSF_USE_ROM_IMPL
void _multi_heap_lock(void *lock)
{
@@ -103,7 +103,7 @@ void multi_heap_in_rom_init(void)
multi_heap_os_funcs_init(&multi_heap_os_funcs);
}
#else //#ifndef CONFIG_HEAP_TLSF_USE_ROM_IMPL
#else // CONFIG_HEAP_TLSF_USE_ROM_IMPL
/* Return true if this block is free. */
static inline bool is_free(const block_header_t *block)

View File

@@ -359,10 +359,10 @@ multi_heap_handle_t multi_heap_register(void *start, size_t size)
memset(start, FREE_FILL_PATTERN, size);
}
#endif
#ifdef CONFIG_HEAP_TLSF_USE_ROM_IMPL
#if CONFIG_HEAP_TLSF_USE_ROM_IMPL
tlsf_poison_fill_pfunc_set(multi_heap_internal_poison_fill_region);
tlsf_poison_check_pfunc_set(multi_heap_internal_check_block_poisoning);
#endif
#endif // CONFIG_HEAP_TLSF_USE_ROM_IMPL
return multi_heap_register_impl(start, size);
}

View File

@@ -47,15 +47,19 @@ TEST_CASE("multi_heap poisoning detection", "[heap]")
ptr[i] = CORRUPTED_VALUE;
bool is_heap_ok = heap_caps_check_integrity(MALLOC_CAP_8BIT, true);
#ifdef CONFIG_HEAP_POISONING_COMPREHENSIVE
/* fix the corruption by restoring the original value at ptr + i.
* We need to do this before the ASSERT because they may print a message.
* Using print allocates memory on the heap, so the heap has to be fixed. */
ptr[i] = original_value;
#if CONFIG_HEAP_POISONING_COMPREHENSIVE
/* check that heap_caps_check_integrity() detects the corruption */
TEST_ASSERT_FALSE(is_heap_ok);
#else
/* the comprehensive corruption is not checked in the heap_caps_check_integrity() */
TEST_ASSERT_TRUE(is_heap_ok);
#endif
/* fix the corruption by restoring the original value at ptr + i */
ptr[i] = original_value;
/* check that heap_caps_check_integrity() stops reporting the corruption */
is_heap_ok = heap_caps_check_integrity(MALLOC_CAP_8BIT, true);