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.
This commit is contained in:
YAMAMOTO Takashi 2024-01-16 10:17:58 +09:00 committed by GitHub
parent 915adc433d
commit 685d55d2e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,6 +87,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size)
void *
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
{
void *p;
#if (WASM_MEM_DUAL_BUS_MIRROR != 0)
void *i_addr, *d_addr;
#endif
@ -110,7 +111,21 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
return in_ibus_ext(i_addr) ? i_addr : d_addr;
}
#endif
return malloc((uint32)size);
/* Note: aot_loader.c assumes that os_mmap provides large enough
* alignment for any data sections. Some sections like rodata.cst32
* actually require alignment larger than the natural alignment
* provided by malloc.
*
* Probably it's cleaner to add an explicit alignment argument to
* os_mmap. However, it only makes sense if we change our aot format
* to keep the necessary alignment.
*
* For now, let's assume 32 byte alignment is enough.
*/
if (posix_memalign(&p, 32, size)) {
return NULL;
}
return p;
}
void