- 
                Notifications
    You must be signed in to change notification settings 
- Fork 728
Port WAMR to ESP-IDF #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port WAMR to ESP-IDF #892
Changes from 7 commits
654afaa
              3a0269e
              96ff9a3
              f49149b
              5da3f4a
              2b4d5d7
              a17c32c
              251b2e8
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Copyright (C) 2019 Intel Corporation. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| */ | ||
|  | ||
| #include "platform_api_vmcore.h" | ||
|         
                  1c3t3a marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| #include "platform_api_extension.h" | ||
|  | ||
| void * | ||
| os_malloc(unsigned size) | ||
| { | ||
| void *buf_origin; | ||
| void *buf_fixed; | ||
| uintptr_t *addr_field; | ||
|  | ||
| buf_origin = malloc(size + 8 + sizeof(uintptr_t)); | ||
| 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)); | ||
| } | ||
|  | ||
| addr_field = buf_fixed - sizeof(uintptr_t); | ||
| *addr_field = (uintptr_t)buf_origin; | ||
|  | ||
| return buf_fixed; | ||
| } | ||
|  | ||
| void * | ||
| os_realloc(void *ptr, unsigned size) | ||
| { | ||
| void *mem_origin; | ||
| void *mem_new; | ||
| void *mem_new_fixed; | ||
| uintptr_t *addr_field; | ||
|  | ||
| if (!ptr) { | ||
| return NULL; | ||
| } | ||
|  | ||
| addr_field = ptr - sizeof(uintptr_t); | ||
| mem_origin = (void *)(*addr_field); | ||
| mem_new = realloc(mem_origin, size + 8 + sizeof(uintptr_t)); | ||
|  | ||
| if (mem_origin != mem_new) { | ||
| mem_new_fixed = mem_new + sizeof(uintptr_t); | ||
| if ((uint32)mem_new_fixed & 0x7) { | ||
| mem_new_fixed = | ||
| (void *)((uintptr_t)(mem_new + 8) & (~(uintptr_t)7)); | ||
| } | ||
|  | ||
| addr_field = mem_new_fixed - sizeof(uintptr_t); | ||
| *addr_field = (uintptr_t)mem_new; | ||
|  | ||
| return mem_new_fixed; | ||
| } | ||
|  | ||
| return ptr; | ||
| } | ||
|  | ||
| void | ||
| os_free(void *ptr) | ||
| { | ||
| void *mem_origin; | ||
| uintptr *addr_field; | ||
|  | ||
| if (ptr) { | ||
| addr_field = ptr - sizeof(uintptr_t); | ||
| mem_origin = (void *)(*addr_field); | ||
|  | ||
| free(mem_origin); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright (C) 2019 Intel Corporation. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| */ | ||
|  | ||
| #include "platform_api_vmcore.h" | ||
|         
                  1c3t3a marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| #include "platform_api_extension.h" | ||
|  | ||
| void * | ||
| os_mmap(void *hint, size_t size, int prot, int flags) | ||
| { | ||
| return os_malloc((int)size); | ||
| } | ||
|  | ||
| void | ||
| os_munmap(void *addr, size_t size) | ||
| { | ||
| return os_free(addr); | ||
| } | ||
|  | ||
| int | ||
| os_mprotect(void *addr, size_t size, int prot) | ||
| { | ||
| return 0; | ||
| } | ||
|  | ||
| void | ||
| os_dcache_flush() | ||
| {} | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -6,25 +6,15 @@ | |
| #include "platform_api_vmcore.h" | ||
| #include "platform_api_extension.h" | ||
|  | ||
| int errno = 0; | ||
|  | ||
| int | ||
| os_thread_sys_init(); | ||
|  | ||
| void | ||
| os_thread_sys_destroy(); | ||
|  | ||
| int | ||
| bh_platform_init() | ||
| { | ||
| return os_thread_sys_init(); | ||
| return 0; | ||
| } | ||
|  | ||
| void | ||
| bh_platform_destroy() | ||
| { | ||
| os_thread_sys_destroy(); | ||
| } | ||
| {} | ||
|  | ||
| int | ||
| os_printf(const char *format, ...) | ||
|  | @@ -45,76 +35,20 @@ os_vprintf(const char *format, va_list ap) | |
| return vprintf(format, ap); | ||
| } | ||
|  | ||
| void * | ||
| os_mmap(void *hint, size_t size, int prot, int flags) | ||
| uint64 | ||
| os_time_get_boot_microsecond(void) | ||
| { | ||
|  | ||
| return BH_MALLOC(size); | ||
| return (uint64)esp_timer_get_time(); | ||
| } | ||
|  | ||
| void | ||
| os_munmap(void *addr, size_t size) | ||
| uint8 * | ||
| os_thread_get_stack_boundary(void) | ||
| { | ||
| BH_FREE(addr); | ||
| return NULL; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there API to get the stack boundary? If not, runtime might not be able to check the native stack overflow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am going to look it up, but I didn't find one before. Although I am quite sure that it should exist somewhere! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, so let's merge the patch firstly, and fix it in the future. | ||
| } | ||
|  | ||
| int | ||
| os_mprotect(void *addr, size_t size, int prot) | ||
| os_usleep(uint32 usec) | ||
| { | ||
| return 0; | ||
| } | ||
|  | ||
| void | ||
| os_dcache_flush() | ||
| {} | ||
|  | ||
| int | ||
| atoi(const char *nptr) | ||
| { | ||
| bool is_negative = false; | ||
| int total = 0; | ||
| const char *p = nptr; | ||
| char temp = '0'; | ||
|  | ||
| if (NULL == p) { | ||
| os_printf("invlaid atoi input\n"); | ||
| return 0; | ||
| } | ||
|  | ||
| if (*p == '-') { | ||
| is_negative = true; | ||
| p++; | ||
| } | ||
|  | ||
| while ((temp = *p++) != '\0') { | ||
| if (temp > '9' || temp < '0') { | ||
| continue; | ||
| } | ||
|  | ||
| total = total * 10 + (int)(temp - '0'); | ||
| } | ||
|  | ||
| if (is_negative) | ||
| total = 0 - total; | ||
|  | ||
| return total; | ||
| } | ||
|  | ||
| void * | ||
| memmove(void *dest, const void *src, size_t n) | ||
| { | ||
| char *d = dest; | ||
| const char *s = src; | ||
|  | ||
| if (d < s) { | ||
| while (n--) | ||
| *d++ = *s++; | ||
| } | ||
| else { | ||
| const char *lasts = s + (n - 1); | ||
| char *lastd = d + (n - 1); | ||
| while (n--) | ||
| *lastd-- = *lasts--; | ||
| } | ||
| return dest; | ||
| return usleep(usec); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.