mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
6e0e7e34ea
- Add support for esp32s2, esp32c3 and esp32c2 for the `memprot`-related tests - Preliminary support for esp32s3 has also been added, the test app will be enabled for esp32s3 later when the memprot-related issues are fixed. - Override panic handler to dump the violation intr status - Dump the `memprot` violation registers before calling the real panic handler - Handle `Illegal Instruction` exception in case of memprot permission violation * In esp32c3 with `memprot` enabled, if we try to execute arbitrary code from RTC_FAST_MEM we get an `Illegal Instruction` exception from the panic handler rather than a `Memory Protection Fault`. * This is because the Illegal Instruction interrupt occurs earlier than the memory protection interrupt due to a higher interrupt latency.
41 lines
1.6 KiB
CMake
41 lines
1.6 KiB
CMake
# The following lines of boilerplate have to be in your project's CMakeLists
|
|
# in this exact order for cmake to work correctly
|
|
cmake_minimum_required(VERSION 3.16)
|
|
|
|
set(COMPONENTS main espcoredump esp_gdbstub)
|
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
|
|
|
project(test_panic)
|
|
|
|
if(CONFIG_TEST_MEMPROT)
|
|
# TODO: IDF-6821 - Refactor this to make it easy to add any new targets
|
|
if(CONFIG_SOC_MEMPROT_SUPPORTED)
|
|
target_link_libraries(${project_elf} PRIVATE "-Wl,--wrap=esp_panic_handler")
|
|
if(CONFIG_IDF_TARGET_ESP32C3)
|
|
target_link_libraries(${project_elf} PRIVATE "-Wl,--wrap=panic_arch_fill_info")
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
if(NOT CONFIG_TEST_MEMPROT)
|
|
# Enable UBSAN checks
|
|
#
|
|
# shift-base sanitizer is disabled due to the following pattern found in register header files:
|
|
# #define SOME_FIELD 0xFFFF
|
|
# #define SOME_FIELD_M ((SOME_FIELD_V)<<(SOME_FIELD_S))
|
|
# #define SOME_FIELD_V 0xFFFF
|
|
# #define SOME_FIELD_S 16
|
|
# here SOME_FIELD_V doesn't have an unsigned (U) prefix, so the compiler flags
|
|
# SOME_FIELD_M expansion (0xFFFF << 16) as generating integer overflow.
|
|
#
|
|
set(ubsan_options "-fsanitize=undefined" "-fno-sanitize=shift-base")
|
|
|
|
# Only enable UBSAN for a few components related to the panic test,
|
|
# due to RAM size limitations.
|
|
foreach(component main espcoredump esp_system spi_flash
|
|
esp_common esp_hw_support soc hal freertos)
|
|
idf_component_get_property(lib ${component} COMPONENT_LIB)
|
|
target_compile_options(${lib} PRIVATE ${ubsan_options})
|
|
endforeach()
|
|
endif()
|