Skip to content

Commit 685d55d

Browse files
authored
nuttx: Use larger alignment for os_mmap and comment why (#3017)
Other platforms with malloc-based os_mmap might need similar changes too, depending on their target cpu arch.
1 parent 915adc4 commit 685d55d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

core/shared/platform/nuttx/nuttx_platform.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size)
8787
void *
8888
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
8989
{
90+
void *p;
9091
#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
9192
void *i_addr, *d_addr;
9293
#endif
@@ -110,7 +111,21 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
110111
return in_ibus_ext(i_addr) ? i_addr : d_addr;
111112
}
112113
#endif
113-
return malloc((uint32)size);
114+
/* Note: aot_loader.c assumes that os_mmap provides large enough
115+
* alignment for any data sections. Some sections like rodata.cst32
116+
* actually require alignment larger than the natural alignment
117+
* provided by malloc.
118+
*
119+
* Probably it's cleaner to add an explicit alignment argument to
120+
* os_mmap. However, it only makes sense if we change our aot format
121+
* to keep the necessary alignment.
122+
*
123+
* For now, let's assume 32 byte alignment is enough.
124+
*/
125+
if (posix_memalign(&p, 32, size)) {
126+
return NULL;
127+
}
128+
return p;
114129
}
115130

116131
void

0 commit comments

Comments
 (0)