forked from espressif/esp-idf
heap: add check for usage of flash content from iram
this commits: - adds build-time test to check that no call to flash regions are done from IRAM functions - resolves problems related to IRAM function using content in flash memory - update heap_caps_alloc_failed to use a default function name in DRAM when necessary instead of creating a function name variable in DRAM for each call of heap_caps_alloc_failed. This allows to save some extra bytes in RAM.
This commit is contained in:
@@ -42,7 +42,7 @@ idf_component_register(SRCS "${srcs}"
|
|||||||
INCLUDE_DIRS ${includes}
|
INCLUDE_DIRS ${includes}
|
||||||
PRIV_INCLUDE_DIRS ${priv_includes}
|
PRIV_INCLUDE_DIRS ${priv_includes}
|
||||||
LDFRAGMENTS linker.lf
|
LDFRAGMENTS linker.lf
|
||||||
PRIV_REQUIRES soc)
|
PRIV_REQUIRES soc spi_flash)
|
||||||
|
|
||||||
if(CONFIG_HEAP_TRACING)
|
if(CONFIG_HEAP_TRACING)
|
||||||
set(WRAP_FUNCTIONS
|
set(WRAP_FUNCTIONS
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "heap_private.h"
|
#include "heap_private.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
#include "esp_private/cache_utils.h"
|
||||||
|
|
||||||
/* Forward declaration for base function, put in IRAM.
|
/* Forward declaration for base function, put in IRAM.
|
||||||
* These functions don't check for errors after trying to allocate memory. */
|
* These functions don't check for errors after trying to allocate memory. */
|
||||||
@@ -56,10 +56,16 @@ IRAM_ATTR static void *dram_alloc_to_iram_addr(void *addr, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void heap_caps_alloc_failed(size_t requested_size, uint32_t caps, const char *function_name)
|
IRAM_ATTR static void heap_caps_alloc_failed(size_t requested_size, uint32_t caps, const char *function_name)
|
||||||
{
|
{
|
||||||
|
static const DRAM_ATTR char *default_func_name = "<function_name>";
|
||||||
if (alloc_failed_callback) {
|
if (alloc_failed_callback) {
|
||||||
alloc_failed_callback(requested_size, caps, function_name);
|
if (!spi_flash_cache_enabled() && !esp_ptr_internal(function_name)) {
|
||||||
|
alloc_failed_callback(requested_size, caps, default_func_name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alloc_failed_callback(requested_size, caps, function_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS
|
#ifdef CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS
|
||||||
|
@@ -43,7 +43,7 @@ extern SLIST_HEAD(registered_heap_ll, heap_t_) registered_heaps;
|
|||||||
bool heap_caps_match(const heap_t *heap, uint32_t caps);
|
bool heap_caps_match(const heap_t *heap, uint32_t caps);
|
||||||
|
|
||||||
/* return all possible capabilities (across all priorities) for a given heap */
|
/* return all possible capabilities (across all priorities) for a given heap */
|
||||||
inline static uint32_t get_all_caps(const heap_t *heap)
|
inline static __attribute__((always_inline)) uint32_t get_all_caps(const heap_t *heap)
|
||||||
{
|
{
|
||||||
if (heap->heap == NULL) {
|
if (heap->heap == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -2,3 +2,17 @@ idf_component_register(SRC_DIRS "."
|
|||||||
PRIV_INCLUDE_DIRS "."
|
PRIV_INCLUDE_DIRS "."
|
||||||
PRIV_REQUIRES cmock test_utils heap spi_flash)
|
PRIV_REQUIRES cmock test_utils heap spi_flash)
|
||||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
||||||
|
|
||||||
|
if(CONFIG_COMPILER_DUMP_RTL_FILES)
|
||||||
|
idf_build_get_property(elf_file_name EXECUTABLE GENERATOR_EXPRESSION)
|
||||||
|
add_custom_target(check_test_app_sections ALL
|
||||||
|
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py
|
||||||
|
--rtl-dir ${CMAKE_BINARY_DIR}/esp-idf/heap/
|
||||||
|
--elf-file ${CMAKE_BINARY_DIR}/${elf_file_name}
|
||||||
|
find-refs
|
||||||
|
--from-sections=.iram0.text
|
||||||
|
--to-sections=.flash.text,.flash.rodata
|
||||||
|
--exit-code
|
||||||
|
DEPENDS ${elf_file_name}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
@@ -31,3 +31,4 @@ CONFIG_MQTT_TEST_BROKER_URI="mqtt://${EXAMPLE_MQTT_BROKER_TCP}"
|
|||||||
# See esp_spiffs_gc description for more info.
|
# See esp_spiffs_gc description for more info.
|
||||||
CONFIG_SPIFFS_GC_MAX_RUNS=132
|
CONFIG_SPIFFS_GC_MAX_RUNS=132
|
||||||
CONFIG_NVS_ASSERT_ERROR_CHECK=y
|
CONFIG_NVS_ASSERT_ERROR_CHECK=y
|
||||||
|
CONFIG_COMPILER_DUMP_RTL_FILES=y
|
||||||
|
Reference in New Issue
Block a user