Skip to content

Commit

Permalink
nuttx: Use text heap for executable memory (bytecodealliance#1181)
Browse files Browse the repository at this point in the history
Based on nuttx patch "Add up_textheap_heapmember":
  apache/nuttx#6306
  • Loading branch information
yamt authored May 23, 2022
1 parent 69c23aa commit 723a808
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/shared/platform/nuttx/nuttx_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "platform_api_extension.h"
#include "platform_api_vmcore.h"

#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
#include <nuttx/arch.h>
#endif

int
bh_platform_init()
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 723a808

Please sign in to comment.