Skip to content

Commit 0f6adbf

Browse files
committed
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 espressif#14836
1 parent 4cf5535 commit 0f6adbf

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

components/heap/port/esp32c2/memory_layout.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -32,9 +32,15 @@ enum {
3232
SOC_MEMORY_TYPE_NUM,
3333
};
3434

35+
#ifdef CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
36+
#define ESP32C2_MEM_COMMON_CAPS (MALLOC_CAP_DEFAULT | MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT)
37+
#else
38+
#define ESP32C2_MEM_COMMON_CAPS (MALLOC_CAP_DEFAULT | MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT | MALLOC_CAP_EXEC)
39+
#endif
40+
3541
const soc_memory_type_desc_t soc_memory_types[SOC_MEMORY_TYPE_NUM] = {
3642
// Type 0: DRAM which has an alias on the I-port
37-
[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 }},
43+
[SOC_MEMORY_TYPE_RAM] = { "RAM", { ESP32C2_MEM_COMMON_CAPS, 0, 0 }},
3844
};
3945

4046
const size_t soc_memory_type_count = sizeof(soc_memory_types) / sizeof(soc_memory_type_desc_t);

components/heap/port/esp32c61/memory_layout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum {
3636
};
3737

3838
/* COMMON_CAPS is the set of attributes common to all types of memory on this chip */
39-
#ifdef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
39+
#ifdef CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
4040
#define ESP32C61_MEM_COMMON_CAPS (MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT | MALLOC_CAP_8BIT)
4141
#else
4242
#define ESP32C61_MEM_COMMON_CAPS (MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT | MALLOC_CAP_8BIT | MALLOC_CAP_EXEC)

components/heap/test_apps/heap_tests/main/test_diram.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#define ALLOC_SZ 1024
1717

18-
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
18+
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
1919
static void *malloc_block_diram(uint32_t caps)
2020
{
2121
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]")
7878

7979
free(iram);
8080
}
81-
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
81+
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)

components/heap/test_apps/heap_tests/main/test_malloc_caps.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -18,7 +18,7 @@
1818
#include <stdlib.h>
1919
#include <sys/param.h>
2020

21-
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
21+
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
2222
TEST_CASE("Capabilities allocator test", "[heap]")
2323
{
2424
char *m1, *m2[10];
@@ -108,7 +108,7 @@ TEST_CASE("Capabilities allocator test", "[heap]")
108108
free(m1);
109109
printf("Done.\n");
110110
}
111-
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
111+
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
112112

113113
#ifdef CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY
114114
TEST_CASE("IRAM_8BIT capability test", "[heap]")
@@ -230,7 +230,7 @@ TEST_CASE("heap caps minimum free bytes fault cases", "[heap]")
230230
/* Small function runs from IRAM to check that malloc/free/realloc
231231
all work OK when cache is disabled...
232232
*/
233-
#if !CONFIG_ESP_SYSTEM_MEMPROT_FEATURE && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH
233+
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT) && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH
234234
static IRAM_ATTR __attribute__((noinline)) bool iram_malloc_test(void)
235235
{
236236
spi_flash_guard_get()->start(); // Disables flash cache
@@ -252,7 +252,7 @@ TEST_CASE("heap_caps_xxx functions work with flash cache disabled", "[heap]")
252252
{
253253
TEST_ASSERT( iram_malloc_test() );
254254
}
255-
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
255+
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT) && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH
256256

257257
#ifdef CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS
258258
TEST_CASE("When enabled, allocation operation failure generates an abort", "[heap][reset=abort,SW_CPU_RESET]")
@@ -318,7 +318,7 @@ TEST_CASE("allocation with invalid capability should also trigger the alloc fail
318318
* In MR 16031, the priority of RTC memory has been adjusted to the lowest.
319319
* RTC memory will not be consumed a lot during the startup process.
320320
*/
321-
TEST_CASE("RTC memory shoule be lowest priority and its free size should be big enough", "[heap]")
321+
TEST_CASE("RTC memory should be lowest priority and its free size should be big enough", "[heap]")
322322
{
323323
const size_t allocation_size = 1024 * 4;
324324
void *ptr = NULL;
@@ -341,7 +341,7 @@ TEST_CASE("test memory protection features", "[heap][mem_prot]")
341341
// no memory is being allocated
342342
uint32_t *iram_ptr = heap_caps_malloc(4, MALLOC_CAP_EXEC);
343343

344-
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
344+
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
345345
// System memory protection not active, check that iram_ptr is not null
346346
// Check that iram_ptr is in IRAM
347347
TEST_ASSERT_NOT_NULL(iram_ptr);
@@ -352,5 +352,5 @@ TEST_CASE("test memory protection features", "[heap][mem_prot]")
352352
#else
353353
// System memory protection is active, DIRAM seen as DRAM, iram_ptr should be null
354354
TEST_ASSERT_NULL(iram_ptr);
355-
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
355+
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
356356
}

components/heap/test_apps/heap_tests/main/test_realloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ TEST_CASE("realloc shrink buffer in place", "[heap]")
2929

3030
#endif
3131

32-
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
32+
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
3333
TEST_CASE("realloc shrink buffer with EXEC CAPS", "[heap]")
3434
{
3535
const size_t buffer_size = 64;
@@ -68,4 +68,4 @@ TEST_CASE("realloc move data to a new heap type", "[heap]")
6868

6969
free(c);
7070
}
71-
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
71+
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)

0 commit comments

Comments
 (0)