mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 13:44:32 +02:00
fix(panic_test): avoid linker check on dangerous relocations
xtensa linker throws warning dangerous relocation: windowed longcall crosses 1GB boundary; return may fail create separate function to call function by pointer to avoid warnings
This commit is contained in:
@@ -27,6 +27,11 @@ extern int _iram_text_end;
|
||||
|
||||
#define ALIGN_UP_TO_MMU_PAGE_SIZE(addr) (((addr) + (SOC_MMU_PAGE_SIZE) - 1) & ~((SOC_MMU_PAGE_SIZE) - 1))
|
||||
|
||||
__attribute__((noinline))
|
||||
static void run_function(void (*test_addr)(void)) {
|
||||
test_addr();
|
||||
}
|
||||
|
||||
/* NOTE: Naming conventions for RTC_FAST_MEM are
|
||||
* different for ESP32-C3 and other RISC-V targets
|
||||
*/
|
||||
@@ -121,10 +126,9 @@ static DRAM_ATTR uint8_t s_dram_buf[1024];
|
||||
void test_dram_reg1_execute_violation(void)
|
||||
{
|
||||
memcpy(&s_dram_buf, &foo_d, sizeof(s_dram_buf));
|
||||
void (*func_ptr)(void);
|
||||
func_ptr = (void(*)(void))&s_dram_buf;
|
||||
void *test_addr = &s_dram_buf;
|
||||
printf("DRAM: Execute operation | Address: %p\n", &s_dram_buf);
|
||||
func_ptr();
|
||||
run_function(test_addr);
|
||||
}
|
||||
|
||||
/* DRAM: Heap region */
|
||||
@@ -136,9 +140,8 @@ void test_dram_reg2_execute_violation(void)
|
||||
printf("DRAM: Execute operation | Address: %p\n", instr);
|
||||
|
||||
memcpy(instr, &foo_d, 1024);
|
||||
void (*func_ptr)(void);
|
||||
func_ptr = (void(*)(void))instr;
|
||||
func_ptr();
|
||||
void *test_addr = instr;
|
||||
run_function(test_addr);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------- RTC Violation Checks ---------------------------------------------------- */
|
||||
@@ -156,28 +159,28 @@ static RTC_IRAM_ATTR void foo_f(void)
|
||||
void test_rtc_fast_reg1_execute_violation(void)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ARCH_RISCV
|
||||
void (*test_addr)(void) = (void(*)(void))((uint32_t)&_rtc_fast_start);
|
||||
void *test_addr = &_rtc_fast_start;
|
||||
#else
|
||||
void (*test_addr)(void) = (void(*)(void))((uint32_t)&_rtc_text_start);
|
||||
void *test_addr = &_rtc_text_start;
|
||||
#endif
|
||||
printf("RTC_MEM (Fast): Execute operation | Address: %p\n", test_addr);
|
||||
test_addr();
|
||||
run_function(test_addr);
|
||||
}
|
||||
|
||||
/* RTC_FAST_MEM: .text section boundary */
|
||||
void test_rtc_fast_reg2_execute_violation(void)
|
||||
{
|
||||
void (*test_addr)(void) = (void(*)(void))((uint32_t)&_rtc_text_end - 0x04);
|
||||
void *test_addr = &_rtc_text_end - 1;
|
||||
printf("RTC_MEM (Fast): Execute operation | Address: %p\n", test_addr);
|
||||
test_addr();
|
||||
run_function(test_addr);
|
||||
}
|
||||
|
||||
/* RTC_FAST_MEM: .data section */
|
||||
void test_rtc_fast_reg3_execute_violation(void)
|
||||
{
|
||||
void (*test_addr)(void) = (void(*)(void))((uint32_t)&_rtc_force_fast_start + 0x04);
|
||||
void *test_addr = &_rtc_force_fast_start + 1;
|
||||
printf("RTC_MEM (Fast): Execute operation | Address: %p\n", test_addr);
|
||||
test_addr();
|
||||
run_function(test_addr);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -193,17 +196,17 @@ static RTC_SLOW_ATTR void foo_s(void)
|
||||
/* RTC_SLOW_MEM: Data tagged with RTC_SLOW_ATTR */
|
||||
void test_rtc_slow_reg1_execute_violation(void)
|
||||
{
|
||||
void (*test_addr)(void) = (void(*)(void))((uint32_t)&_rtc_force_slow_start);
|
||||
void *test_addr = &_rtc_force_slow_start;
|
||||
printf("RTC_MEM (Slow): Execute operation | Address: %p\n", test_addr);
|
||||
test_addr();
|
||||
run_function(test_addr);
|
||||
}
|
||||
|
||||
/* RTC_SLOW_MEM: Region start */
|
||||
void test_rtc_slow_reg2_execute_violation(void)
|
||||
{
|
||||
void (*test_addr)(void) = (void(*)(void))((uint32_t)&_rtc_data_start);
|
||||
void *test_addr = &_rtc_data_start;
|
||||
printf("RTC_MEM (Slow): Execute operation | Address: %p\n", test_addr);
|
||||
test_addr();
|
||||
run_function(test_addr);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -243,10 +246,9 @@ void test_drom_reg_write_violation(void)
|
||||
|
||||
void test_drom_reg_execute_violation(void)
|
||||
{
|
||||
printf("Flash (DROM): Execute operation | Address: %p\n", foo_buf);
|
||||
void (*func_ptr)(void);
|
||||
func_ptr = (void(*)(void))foo_buf;
|
||||
func_ptr();
|
||||
void *test_addr = (void *)foo_buf;
|
||||
printf("Flash (DROM): Execute operation | Address: %p\n", test_addr);
|
||||
run_function(test_addr);
|
||||
}
|
||||
|
||||
// Check if the memory alignment gaps added to the heap are correctly configured
|
||||
@@ -255,9 +257,9 @@ void test_spiram_xip_irom_alignment_reg_execute_violation(void)
|
||||
{
|
||||
extern int _instruction_reserved_end;
|
||||
if (ALIGN_UP_TO_MMU_PAGE_SIZE((uint32_t)(&_instruction_reserved_end)) - (uint32_t)(&_instruction_reserved_end) >= 4) {
|
||||
void (*test_addr)(void) = (void(*)(void))((uint32_t)(&_instruction_reserved_end + 0x4));
|
||||
void *test_addr = &_instruction_reserved_end + 1;
|
||||
printf("SPIRAM (IROM): Execute operation | Address: %p\n", test_addr);
|
||||
test_addr();
|
||||
run_function(test_addr);
|
||||
} else {
|
||||
printf("SPIRAM (IROM): IROM alignment gap not added into heap\n");
|
||||
}
|
||||
@@ -270,9 +272,9 @@ void test_spiram_xip_drom_alignment_reg_execute_violation(void)
|
||||
{
|
||||
extern int _rodata_reserved_end;
|
||||
if (ALIGN_UP_TO_MMU_PAGE_SIZE((uint32_t)(&_rodata_reserved_end)) - (uint32_t)(&_rodata_reserved_end) >= 4) {
|
||||
void (*test_addr)(void) = (void(*)(void))((uint32_t)(&_rodata_reserved_end + 0x4));
|
||||
void *test_addr = &_rodata_reserved_end + 0x4;
|
||||
printf("SPIRAM (DROM): Execute operation | Address: %p\n", test_addr);
|
||||
test_addr();
|
||||
run_function(test_addr);
|
||||
} else {
|
||||
printf("SPIRAM (DROM): DROM alignment gap not added into heap\n");
|
||||
}
|
||||
@@ -290,9 +292,8 @@ void test_invalid_memory_region_write_violation(void)
|
||||
|
||||
void test_invalid_memory_region_execute_violation(void)
|
||||
{
|
||||
void (*func_ptr)(void);
|
||||
func_ptr = (void(*)(void))(SOC_DRAM_HIGH + 0x40);
|
||||
printf("Execute operation | Address: %p\n", func_ptr);
|
||||
func_ptr();
|
||||
void *test_addr = (void *)(SOC_DRAM_HIGH + 0x40);
|
||||
printf("Execute operation | Address: %p\n", test_addr);
|
||||
run_function(test_addr);
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user