From 6efdd50d5a31587598d1420dcb15559a94f3021c Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Fri, 13 Oct 2023 22:34:55 +0800 Subject: [PATCH] arch/sim: Remove executable bit from the normal heap Signed-off-by: Xiang Xiao --- arch/sim/src/sim/posix/sim_hostmemory.c | 8 ++++---- arch/sim/src/sim/sim_heap.c | 2 +- arch/sim/src/sim/sim_internal.h | 2 +- arch/sim/src/sim/sim_textheap.c | 3 ++- arch/sim/src/sim/win/sim_hostmemory.c | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/sim/src/sim/posix/sim_hostmemory.c b/arch/sim/src/sim/posix/sim_hostmemory.c index c4c0219187..0c9da4c9d3 100644 --- a/arch/sim/src/sim/posix/sim_hostmemory.c +++ b/arch/sim/src/sim/posix/sim_hostmemory.c @@ -60,18 +60,18 @@ static atomic_int g_uordblks; * ****************************************************************************/ -void *host_allocheap(size_t sz) +void *host_allocheap(size_t size, bool exec) { void *p; #if defined(CONFIG_HOST_MACOS) && defined(CONFIG_HOST_ARM64) /* see: https://developer.apple.com/forums/thread/672804 */ - p = host_uninterruptible(mmap, NULL, sz, PROT_READ | PROT_WRITE, + p = host_uninterruptible(mmap, NULL, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); #else - p = host_uninterruptible(mmap, NULL, sz, - PROT_READ | PROT_WRITE | PROT_EXEC, + p = host_uninterruptible(mmap, NULL, size, PROT_READ | PROT_WRITE | + (exec ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE, -1, 0); #endif diff --git a/arch/sim/src/sim/sim_heap.c b/arch/sim/src/sim/sim_heap.c index 969a5e8746..e0260a7656 100644 --- a/arch/sim/src/sim/sim_heap.c +++ b/arch/sim/src/sim/sim_heap.c @@ -475,7 +475,7 @@ void up_allocate_heap(void **heap_start, size_t *heap_size) * ARCH_HAVE_TEXT_HEAP mechanism can be an alternative. */ - uint8_t *sim_heap = host_allocheap(SIM_HEAP_SIZE); + uint8_t *sim_heap = host_allocheap(SIM_HEAP_SIZE, false); *heap_start = sim_heap; *heap_size = SIM_HEAP_SIZE; diff --git a/arch/sim/src/sim/sim_internal.h b/arch/sim/src/sim/sim_internal.h index 151273dc8d..50bb44219b 100644 --- a/arch/sim/src/sim/sim_internal.h +++ b/arch/sim/src/sim/sim_internal.h @@ -216,7 +216,7 @@ int host_waitpid(pid_t pid); /* sim_hostmemory.c *********************************************************/ -void *host_allocheap(size_t sz); +void *host_allocheap(size_t sz, bool exec); void host_freeheap(void *mem); void *host_allocshmem(const char *name, size_t size, int master); void host_freeshmem(void *mem); diff --git a/arch/sim/src/sim/sim_textheap.c b/arch/sim/src/sim/sim_textheap.c index bc967cdfc8..6fa233201e 100644 --- a/arch/sim/src/sim/sim_textheap.c +++ b/arch/sim/src/sim/sim_textheap.c @@ -49,7 +49,8 @@ void *up_textheap_memalign(size_t align, size_t size) { if (g_textheap == NULL) { - g_textheap = mm_initialize("textheap", host_allocheap(SIM_HEAP_SIZE), + g_textheap = mm_initialize("textheap", + host_allocheap(SIM_HEAP_SIZE, true), SIM_HEAP_SIZE); } diff --git a/arch/sim/src/sim/win/sim_hostmemory.c b/arch/sim/src/sim/win/sim_hostmemory.c index c1556fa738..a94fecb2d7 100644 --- a/arch/sim/src/sim/win/sim_hostmemory.c +++ b/arch/sim/src/sim/win/sim_hostmemory.c @@ -36,7 +36,7 @@ * ****************************************************************************/ -void *host_allocheap(size_t sz) +void *host_allocheap(size_t sz, bool exec) { return _aligned_malloc(sz, 8); }