-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WASI support for esp-idf platform (#3348)
Add WASI support for esp-idf platform: 1. add Kconfig and cmake scripts 2. add API "openat" when using littlefs 3. add clock/rwlock/file/socket OS adapter
- Loading branch information
1 parent
0aeef69
commit 6aa7cb8
Showing
7 changed files
with
2,192 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
menu "WASM Micro Runtime" | ||
choice WAMR_BUILD_TYPE | ||
prompt "Build type" | ||
default WAMR_BUILD_RELEASE | ||
|
||
config WAMR_BUILD_RELEASE | ||
bool "Release" | ||
|
||
config WAMR_BUILD_DEBUG | ||
bool "Debug" | ||
endchoice | ||
|
||
config WAMR_ENABLE_AOT | ||
bool "AOT" | ||
default y | ||
|
||
menuconfig WAMR_ENABLE_INTERP | ||
bool "Interpreter" | ||
default y | ||
|
||
if WAMR_ENABLE_INTERP | ||
|
||
choice WAMR_INTERP_MODE | ||
prompt "Interpreter mode" | ||
default WAMR_INTERP_FAST | ||
|
||
config WAMR_INTERP_CLASSIC | ||
bool "Classic" | ||
|
||
config WAMR_INTERP_FAST | ||
bool "Fast" | ||
endchoice | ||
|
||
choice WAMR_INTERP_LOADER_MODE | ||
prompt "Loader mode" | ||
default WAMR_INTERP_LOADER_NORMAL | ||
|
||
config WAMR_INTERP_LOADER_NORMAL | ||
bool "Normal" | ||
|
||
config WAMR_INTERP_LOADER_MINI | ||
bool "Mini" | ||
endchoice | ||
endif | ||
|
||
config WAMR_ENABLE_LIB_PTHREAD | ||
bool "Lib pthread" | ||
default y | ||
|
||
config WAMR_ENABLE_LIBC_BUILTIN | ||
bool "Libc builtin" | ||
default y | ||
|
||
config WAMR_ENABLE_LIBC_WASI | ||
bool "Libc WASI" | ||
default y | ||
|
||
config WAMR_ENABLE_MEMORY_PROFILING | ||
bool "Memory profiling" | ||
default n | ||
|
||
config WAMR_ENABLE_MULTI_MODULE | ||
bool "Multi module" | ||
default n | ||
|
||
config WAMR_ENABLE_PERF_PROFILING | ||
bool "Performance profiling" | ||
default n | ||
|
||
config WAMR_ENABLE_REF_TYPES | ||
bool "Reference types" | ||
default n | ||
|
||
config WAMR_ENABLE_SHARED_MEMORY | ||
bool "Shared memory" | ||
default n | ||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2023 Amazon Inc. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
|
||
#include "libc_errno.h" | ||
#include "platform_api_extension.h" | ||
|
||
#define NANOSECONDS_PER_SECOND 1000000000ULL | ||
|
||
static __wasi_errno_t | ||
wasi_clockid_to_clockid(__wasi_clockid_t in, clockid_t *out) | ||
{ | ||
switch (in) { | ||
case __WASI_CLOCK_MONOTONIC: | ||
*out = CLOCK_MONOTONIC; | ||
return __WASI_ESUCCESS; | ||
case __WASI_CLOCK_REALTIME: | ||
*out = CLOCK_REALTIME; | ||
return __WASI_ESUCCESS; | ||
case __WASI_CLOCK_PROCESS_CPUTIME_ID: | ||
#if defined(CLOCK_PROCESS_CPUTIME_ID) | ||
*out = CLOCK_PROCESS_CPUTIME_ID; | ||
return __WASI_ESUCCESS; | ||
#else | ||
return __WASI_ENOTSUP; | ||
#endif | ||
case __WASI_CLOCK_THREAD_CPUTIME_ID: | ||
#if defined(CLOCK_THREAD_CPUTIME_ID) | ||
*out = CLOCK_THREAD_CPUTIME_ID; | ||
return __WASI_ESUCCESS; | ||
#else | ||
return __WASI_ENOTSUP; | ||
#endif | ||
default: | ||
return __WASI_EINVAL; | ||
} | ||
} | ||
|
||
static __wasi_timestamp_t | ||
timespec_to_nanoseconds(const struct timespec *ts) | ||
{ | ||
if (ts->tv_sec < 0) | ||
return 0; | ||
if ((__wasi_timestamp_t)ts->tv_sec >= UINT64_MAX / NANOSECONDS_PER_SECOND) | ||
return UINT64_MAX; | ||
return (__wasi_timestamp_t)ts->tv_sec * NANOSECONDS_PER_SECOND | ||
+ (__wasi_timestamp_t)ts->tv_nsec; | ||
} | ||
|
||
__wasi_errno_t | ||
os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution) | ||
{ | ||
clockid_t nclock_id; | ||
__wasi_errno_t error = wasi_clockid_to_clockid(clock_id, &nclock_id); | ||
|
||
if (error != __WASI_ESUCCESS) | ||
return error; | ||
|
||
struct timespec ts; | ||
if (clock_getres(nclock_id, &ts) < 0) | ||
return convert_errno(errno); | ||
|
||
*resolution = timespec_to_nanoseconds(&ts); | ||
|
||
return error; | ||
} | ||
|
||
__wasi_errno_t | ||
os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision, | ||
__wasi_timestamp_t *time) | ||
{ | ||
clockid_t nclock_id; | ||
__wasi_errno_t error = wasi_clockid_to_clockid(clock_id, &nclock_id); | ||
|
||
(void)precision; | ||
|
||
if (error != __WASI_ESUCCESS) | ||
return error; | ||
|
||
struct timespec ts; | ||
if (clock_gettime(nclock_id, &ts) < 0) | ||
return convert_errno(errno); | ||
|
||
*time = timespec_to_nanoseconds(&ts); | ||
|
||
return error; | ||
} |
Oops, something went wrong.