ESP IDF fixes (#927)
Various fixes and beautifications coordinated with @1c3t3a, fixes 2 of the 3 all remaining issues from #892: - enable to os_mmap executable memory - fix os_malloc/os_realloc/os_free issues - implement os_thread_get_stack_boundary - add build scripts to include with esp-idf to use wamr as an ESP-IDF component - update sample and document
This commit is contained in:
committed by
GitHub
parent
2c3f284b85
commit
78414b627c
@ -14,6 +14,9 @@ os_malloc(unsigned size)
|
||||
uintptr_t *addr_field;
|
||||
|
||||
buf_origin = malloc(size + 8 + sizeof(uintptr_t));
|
||||
if (!buf_origin) {
|
||||
return NULL;
|
||||
}
|
||||
buf_fixed = buf_origin + sizeof(void *);
|
||||
if ((uintptr_t)buf_fixed & (uintptr_t)0x7) {
|
||||
buf_fixed = (void *)((uintptr_t)(buf_fixed + 8) & (~(uintptr_t)7));
|
||||
@ -34,12 +37,15 @@ os_realloc(void *ptr, unsigned size)
|
||||
uintptr_t *addr_field;
|
||||
|
||||
if (!ptr) {
|
||||
return NULL;
|
||||
return os_malloc(size);
|
||||
}
|
||||
|
||||
addr_field = ptr - sizeof(uintptr_t);
|
||||
mem_origin = (void *)(*addr_field);
|
||||
mem_new = realloc(mem_origin, size + 8 + sizeof(uintptr_t));
|
||||
if (!mem_new) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mem_origin != mem_new) {
|
||||
mem_new_fixed = mem_new + sizeof(uintptr_t);
|
||||
@ -61,7 +67,7 @@ void
|
||||
os_free(void *ptr)
|
||||
{
|
||||
void *mem_origin;
|
||||
uintptr *addr_field;
|
||||
uintptr_t *addr_field;
|
||||
|
||||
if (ptr) {
|
||||
addr_field = ptr - sizeof(uintptr_t);
|
||||
|
||||
@ -9,12 +9,34 @@
|
||||
void *
|
||||
os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
{
|
||||
return os_malloc((int)size);
|
||||
if (prot & MMAP_PROT_EXEC) {
|
||||
// Memory allocation with MALLOC_CAP_EXEC will return 4-byte aligned
|
||||
// Reserve extra 4 byte to fixup alignment and size for the pointer to
|
||||
// the originally allocated address
|
||||
void *buf_origin =
|
||||
heap_caps_malloc(size + 4 + sizeof(uintptr_t), MALLOC_CAP_EXEC);
|
||||
if (!buf_origin) {
|
||||
return NULL;
|
||||
}
|
||||
void *buf_fixed = buf_origin + sizeof(void *);
|
||||
if ((uintptr_t)buf_fixed & (uintptr_t)0x7) {
|
||||
buf_fixed = (void *)((uintptr_t)(buf_fixed + 4) & (~(uintptr_t)7));
|
||||
}
|
||||
|
||||
uintptr_t *addr_field = buf_fixed - sizeof(uintptr_t);
|
||||
*addr_field = (uintptr_t)buf_origin;
|
||||
return buf_fixed;
|
||||
}
|
||||
else {
|
||||
return os_malloc(size);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
os_munmap(void *addr, size_t size)
|
||||
{
|
||||
// We don't need special handling of the executable allocations
|
||||
// here, free() of esp-idf handles it properly
|
||||
return os_free(addr);
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,13 @@ os_time_get_boot_microsecond(void)
|
||||
uint8 *
|
||||
os_thread_get_stack_boundary(void)
|
||||
{
|
||||
#if defined(CONFIG_FREERTOS_USE_TRACE_FACILITY)
|
||||
TaskStatus_t pxTaskStatus;
|
||||
vTaskGetInfo(xTaskGetCurrentTaskHandle(), &pxTaskStatus, pdTRUE, eInvalid);
|
||||
return pxTaskStatus.pxStackBase;
|
||||
#else // !defined(CONFIG_FREERTOS_USE_TRACE_FACILITY)
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user