From 30e932be1b0b47ef3b04d150ba2767f889220e35 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 23 May 2022 11:58:09 +0900 Subject: [PATCH] nuttx: Use text heap for executable memory (#1181) Based on nuttx patch "Add up_textheap_heapmember": https://github.com/apache/incubator-nuttx/pull/6306 --- core/shared/platform/nuttx/nuttx_platform.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 160147cca..60195c50c 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -6,6 +6,10 @@ #include "platform_api_extension.h" #include "platform_api_vmcore.h" +#if defined(CONFIG_ARCH_USE_TEXT_HEAP) +#include +#endif + int bh_platform_init() { @@ -37,6 +41,12 @@ os_free(void *ptr) void * os_mmap(void *hint, size_t size, int prot, int flags) { +#if defined(CONFIG_ARCH_USE_TEXT_HEAP) + if ((prot & MMAP_PROT_EXEC) != 0) { + return up_textheap_memalign(sizeof(void *), size); + } +#endif + if ((uint64)size >= UINT32_MAX) return NULL; return malloc((uint32)size); @@ -45,6 +55,12 @@ os_mmap(void *hint, size_t size, int prot, int flags) void os_munmap(void *addr, size_t size) { +#if defined(CONFIG_ARCH_USE_TEXT_HEAP) + if (up_textheap_heapmember(addr)) { + up_textheap_free(addr); + return; + } +#endif return free(addr); }