Skip to content

Commit 0f3f44b

Browse files
SoucheSoucheESP-Marius
authored andcommitted
feat(heap): Add hidden Kconfig option to allow exec cap
1 parent da9d8a1 commit 0f3f44b

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

components/heap/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
menu "Heap memory debugging"
22

3+
config HEAP_HAS_EXEC_HEAP
4+
bool
5+
default n if ESP_SYSTEM_MEMPROT
6+
default y if !ESP_SYSTEM_MEMPROT
7+
38
choice HEAP_CORRUPTION_DETECTION
49
prompt "Heap corruption detection"
510
default HEAP_POISONING_DISABLED

components/heap/heap_caps_base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ HEAP_IRAM_ATTR NOINLINE_ATTR void *heap_caps_aligned_alloc_base(size_t alignment
116116
return NULL;
117117
}
118118

119-
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
119+
#if CONFIG_HEAP_HAS_EXEC_HEAP
120120
const bool exec_in_caps = caps & MALLOC_CAP_EXEC;
121121
if (exec_in_caps) {
122122
//MALLOC_CAP_EXEC forces an alloc from IRAM. There is a region which has both this as well as the following

components/heap/include/esp_heap_caps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C" {
2626
/**
2727
* @brief Flags to indicate the capabilities of the various memory systems
2828
*/
29-
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
29+
#if CONFIG_HEAP_HAS_EXEC_HEAP
3030
#define MALLOC_CAP_EXEC (1<<0) ///< Memory must be able to run executable code
3131
#endif
3232
#define MALLOC_CAP_32BIT (1<<1) ///< Memory must allow for aligned 32-bit data accesses

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-
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
18+
#if CONFIG_HEAP_HAS_EXEC_HEAP
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 || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
81+
#endif // CONFIG_HEAP_HAS_EXEC_HEAP

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ TEST_CASE("alloc overflows should all fail", "[heap]")
154154
/* will overflow when the size is rounded up to word align it */
155155
TEST_ASSERT_NULL(heap_caps_malloc(SIZE_MAX-1, MALLOC_CAP_32BIT));
156156

157-
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
157+
#if CONFIG_HEAP_HAS_EXEC_HEAP
158158
TEST_ASSERT_NULL(heap_caps_malloc(SIZE_MAX-1, MALLOC_CAP_EXEC));
159159
#endif
160160
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <stdlib.h>
1919
#include <sys/param.h>
2020

21-
#if !CONFIG_ESP_SYSTEM_MEMPROT && !CONFIG_HEAP_TASK_TRACKING
21+
#if CONFIG_HEAP_HAS_EXEC_HEAP && !(CONFIG_HEAP_TASK_TRACKING)
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 && !CONFIG_HEAP_TASK_TRACKING
111+
#endif // CONFIG_HEAP_HAS_EXEC_HEAP && !(CONFIG_HEAP_TASK_TRACKING)
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 && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH && !CONFIG_HEAP_TASK_TRACKING
233+
#if CONFIG_HEAP_HAS_EXEC_HEAP && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH && !CONFIG_HEAP_TASK_TRACKING
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 && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH && !CONFIG_HEAP_TASK_TRACKING
255+
#endif // CONFIG_HEAP_HAS_EXEC_HEAP && !CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH && !CONFIG_HEAP_TASK_TRACKING
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]")
@@ -336,7 +336,7 @@ TEST_CASE("RTC memory should be lowest priority and its free size should be big
336336
}
337337
#endif
338338

339-
#if !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
339+
#if CONFIG_HEAP_HAS_EXEC_HEAP
340340
TEST_CASE("test memory protection features", "[heap][mem_prot]")
341341
{
342342
// try to allocate memory in IRAM and check that if memory protection is active,
@@ -351,4 +351,4 @@ TEST_CASE("test memory protection features", "[heap][mem_prot]")
351351
// free the memory
352352
heap_caps_free(iram_ptr);
353353
}
354-
#endif // !(CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT)
354+
#endif // CONFIG_HEAP_HAS_EXEC_HEAP

tools/idf_py_actions/hints.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,4 +700,4 @@
700700

701701
-
702702
re: "error: 'MALLOC_CAP_EXEC' undeclared \\(first use in this function\\)"
703-
hint: "MALLOC_CAP_EXEC capability cannot be used if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT or CONFIG_ESP_SYSTEM_MEMPROT_FEATURE is enlabled. \nFor further information about those configurations, run 'idf.py docs -sp api-reference/kconfig-reference.html#memory-protection'"
703+
hint: "MALLOC_CAP_EXEC capability cannot be used if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT or CONFIG_ESP_SYSTEM_MEMPROT_FEATURE is enabled. \nFor further information about those configurations, run 'idf.py docs -sp api-reference/kconfig-reference.html#memory-protection'"

0 commit comments

Comments
 (0)