fix(heap): Fix wrong config to enable MALLOC_CAP_EXEC in memory_layout.c

In esp32c2 and esp32c61 memory_layout.c files, the config used to allow
MALLOC_CAP_EXEC was CONFIG_ESP_SYSTEM_MEMPROT_FEATURE when
CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT should be used.

Closes https://github.com/espressif/esp-idf/issues/14836
This commit is contained in:
Guillaume Souchere 2024-11-21 12:05:11 +01:00
parent aa07a85df2
commit a5eb9f34e1
4 changed files with 20 additions and 14 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -32,9 +32,15 @@ enum {
SOC_MEMORY_TYPE_NUM,
};
#ifdef CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
#define ESP32C2_MEM_COMMON_CAPS (MALLOC_CAP_DEFAULT | MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT)
#else
#define ESP32C2_MEM_COMMON_CAPS (MALLOC_CAP_DEFAULT | MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT | MALLOC_CAP_EXEC)
#endif
const soc_memory_type_desc_t soc_memory_types[SOC_MEMORY_TYPE_NUM] = {
// Type 0: DRAM which has an alias on the I-port
[SOC_MEMORY_TYPE_RAM] = { "RAM", { MALLOC_CAP_DEFAULT | MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT | MALLOC_CAP_EXEC, 0, 0 }},
[SOC_MEMORY_TYPE_RAM] = { "RAM", { ESP32C2_MEM_COMMON_CAPS, 0, 0 }},
};
const size_t soc_memory_type_count = sizeof(soc_memory_types) / sizeof(soc_memory_type_desc_t);

View File

@ -15,7 +15,7 @@
#define ALLOC_SZ 1024
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
static void *malloc_block_diram(uint32_t caps)
{
void *attempts[256] = { 0 }; // Allocate up to 256 ALLOC_SZ blocks to exhaust all non-D/IRAM memory temporarily
@ -78,4 +78,4 @@ TEST_CASE("Allocate D/IRAM as IRAM", "[heap][qemu-ignore]")
free(iram);
}
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@ -18,7 +18,7 @@
#include <stdlib.h>
#include <sys/param.h>
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
TEST_CASE("Capabilities allocator test", "[heap]")
{
char *m1, *m2[10];
@ -108,7 +108,7 @@ TEST_CASE("Capabilities allocator test", "[heap]")
free(m1);
printf("Done.\n");
}
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
#ifdef CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY
TEST_CASE("IRAM_8BIT capability test", "[heap]")
@ -174,7 +174,7 @@ TEST_CASE("heap_caps metadata test", "[heap]")
/* Small function runs from IRAM to check that malloc/free/realloc
all work OK when cache is disabled...
*/
#if !CONFIG_ESP_SYSTEM_MEMPROT_FEATURE && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT) && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH
static IRAM_ATTR __attribute__((noinline)) bool iram_malloc_test(void)
{
spi_flash_guard_get()->start(); // Disables flash cache
@ -196,7 +196,7 @@ TEST_CASE("heap_caps_xxx functions work with flash cache disabled", "[heap]")
{
TEST_ASSERT( iram_malloc_test() );
}
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT) && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH
#ifdef CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS
TEST_CASE("When enabled, allocation operation failure generates an abort", "[heap][reset=abort,SW_CPU_RESET]")
@ -262,7 +262,7 @@ TEST_CASE("allocation with invalid capability should also trigger the alloc fail
* In MR 16031, the priority of RTC memory has been adjusted to the lowest.
* RTC memory will not be consumed a lot during the startup process.
*/
TEST_CASE("RTC memory shoule be lowest priority and its free size should be big enough", "[heap]")
TEST_CASE("RTC memory should be lowest priority and its free size should be big enough", "[heap]")
{
const size_t allocation_size = 1024 * 4;
void *ptr = NULL;
@ -285,7 +285,7 @@ TEST_CASE("test memory protection features", "[heap][mem_prot]")
// no memory is being allocated
uint32_t *iram_ptr = heap_caps_malloc(4, MALLOC_CAP_EXEC);
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
// System memory protection not active, check that iram_ptr is not null
// Check that iram_ptr is in IRAM
TEST_ASSERT_NOT_NULL(iram_ptr);
@ -296,5 +296,5 @@ TEST_CASE("test memory protection features", "[heap][mem_prot]")
#else
// System memory protection is active, DIRAM seen as DRAM, iram_ptr should be null
TEST_ASSERT_NULL(iram_ptr);
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
}

View File

@ -29,7 +29,7 @@ TEST_CASE("realloc shrink buffer in place", "[heap]")
#endif
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
TEST_CASE("realloc shrink buffer with EXEC CAPS", "[heap]")
{
const size_t buffer_size = 64;
@ -68,4 +68,4 @@ TEST_CASE("realloc move data to a new heap type", "[heap]")
free(c);
}
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)