Comments (7)
Status
-
Abstracting libc primitives: After looking at how the POSIX primitives where abstracted in
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/
to supportWindows
. I think that we could do the same to supportZephyr
, with the final idea to have an implementation entirely relying on theos_
APIs.- functions:
- poll --> os_poll
- ioctl --> os_ioctl
- structs/types:
- timespec --> os_timespec
- pollfd --> os_poll_file_handle
- nfds_t --> os_nfds_t
- functions:
-
Extending
platform_api_extension.h
: The following API were added.__wasi_errno_t os_ioctl(os_file_handle *handle, int request, void *argp); // Not sure for return type __wasi_errno_t os_poll(os_poll_file_handle *pfds, os_nfds_t nfs, int timeout);
-
Changing the sandboxed system primitives to use the new types and functions.
random.c
:#elif defined(BH_PLATFORM_ZEPHYR) static void open_urandom(void) { // Not implemented } __wasi_errno_t random_buf(void *buf, size_t len) { return __WASI_ENOSYS; }
blocking.h
:__wasi_errno_t - os_poll(pollfd *pfds, os_nfds_t nfds, int timeout) + os_poll(os_poll_file_handle *pfds, os_nfds_t nfds, int timeout)
locking.h
: change everystruct timespec
tostruct os_timespec
posix.c
: change everystruct pollfd
tostruct os_poll_file_handle
-
Defining new types in
platform_internal.h
: Based on theos_file_handle
type implementation we define the following types (and flags).typedef struct zsock_pollfd os_poll_file_handle; typedef unsigned int os_nfds_t; // To use posix flags #define POLLIN ZSOCK_POLLIN #define POLLPRI ZSOCK_POLLPRI #define POLLOUT ZSOCK_POLLOUT #define POLLERR ZSOCK_POLLERR #define POLLHUP ZSOCK_POLLHUP #define POLLNVAL ZSOCK_POLLNVAL #define FIONREAD ZFD_IOCTL_FIONREAD typedef struct { time_t tv_sec; long tv_nsec; } os_timespec; #define CLOCK_REALTIME 1 #define CLOCK_MONOTONIC 4 typedef struct { struct k_mutex mtx; // Mutex for exclusive access struct k_sem sem; // Semaphore for shared access int read_count; // Number of readers } korp_rwlock;
-
Implementing the new functions in
platform_socket.c
:__wasi_errno_t os_ioctl(os_file_handle *handle, int request, void *argp) { __wasi_errno_t wasi_errno = __WASI_ESUCCESS; if(zsock_ioctl_wrapper(handle, request, argp) < 0){ wasi_errno = zephyr_to_wasi_errno(errno); } return wasi_errno; } __wasi_errno_t os_poll(os_poll_file_handle *fds, os_nfds_t nfs, int timeout) { __wasi_errno_t wasi_errno = __WASI_ESUCCESS; int rc = 0; rc = zsock_poll(fds, nfs, timeout) if(rc < 0){ wasi_errno = zephyr_to_wasi_errno(errno); } switch(rc){ case 0: wasi_errno = __WASI_ETIMEOUT; break; case -1: wasi_errno = zephyr_to_wasi_errno(errno); break; default: break; } return wasi_errno; }
-
compilation errors The compilation still fail with the same warnings as before. The unknown flags errors have disappeared. But the warning about the
struct timespec
andstruct pollfd
still persist.- Error on
locking.h
:/home/user/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h:200:12: error: variable 'ts' has initializer but incomplete type 200 | struct os_timespec ts = { | ^~~~~~~~~~~ /home/user/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h:201:10: error: 'struct os_timespec' has no member named 'tv_sec' 201 | .tv_sec = (time_t)(timeout / 1000000000), | ^~~~~~ /home/user/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h:201:19: warning: excess elements in struct initializer 201 | .tv_sec = (time_t)(timeout / 1000000000), | ^ /home/user/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h:201:19: note: (near initialization for 'ts')
- Error on
posix.c
:/home/user/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2153:61: error: invalid application of 'sizeof' to incomplete type 'struct os_poll_file_handle' 2153 | wasm_runtime_malloc((uint32)(nsubscriptions * sizeof(*pfds))); | ^ /home/user/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2177:25: error: invalid use of undefined type 'struct os_poll_file_handle' 2177 | pfds[i] = (struct os_poll_file_handle){ | ^ /home/user/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2178:26: error: 'struct os_poll_file_handle' has no member named 'fd' 2178 | .fd = fos[i]->file_handle, | ^~ /home/user/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2178:31: warning: excess elements in struct initializer 2178 | .fd = fos[i]->file_handle, |
This look like the compiler is not able to find the definition of the new types.
- I tried to include the
platform_internal.h
in thelocking.h
andposix.c
files to see if it solves the issue. But it didn't work. - I also tried to directly define the types in a new header and directly include it in the
locking.h
andposix.c
files. But the issue still persist. - I even defined the whole file System API in a
zephyr_file.c
file (just returning__WASI_ENOSYS
for now), and changedshared_platform.cmake
. But the issue still persist.
I'm still stuck on this issue. I will try to find a solution.
If anyone is familiar with the implemenation of the
sanboxed system primitives
, or the how the abstract POSIX APIs are passed tosanboxed system primitives
.Any help on this would be appreciated.
- Error on
from wasm-micro-runtime.
@lucasAbadFr could you upload the patch or create a PR and change it to draft or WIP, so that others can have a try according to your work?
from wasm-micro-runtime.
@wenyongh thanks for your reply.
A new zephyr sample called simpe-http
was added to demonstrate socket usage on zephyr. Refer to the sample readme for build purpose.
I've just opened a draft and noticed that I didn't adhere to the code guideline or other guidelines.
These changes will cause most tests to fail.
Please note that the work wasn't intended to be shared in this state.
from wasm-micro-runtime.
Hi @wenyongh,
I managed to make a simple wasi module work (by breaking a lot of things).
I would be interested to know if it work on someone else board.
I updated the readme.md
under the new sample to give a brief overview of what was done.
Also i'm open to any tips to compile a WASI module with libc (from wasi-sdk) linked.
from wasm-micro-runtime.
@lucasAbadFr I am not sure who is using zephyr but I believe there are some developers requiring libc-wasi on zephyr. I found there are many modifications in wasm_runtime_common.c
and core/iwasm/libraries/libc-wasi
and wonder whether it is necessary? It would be better to add APIs and structures in zephyr platform and leave some APIs empty (or return false), and reduce the modification on core/iwasm and make the CIs run successfully.
from wasm-micro-runtime.
Thanks for the feedback.
The CI fail due to the new struct and API defined in platform_api_extension.h
, to make it pass I could just typedef the new struct in platform_internal.h
, and declare the API in their respective folder.
As for the changes in core/iwasm/libraries/libc-wasi/sandboxed-system-primitives
, they are mostly here to abstract POSIX functions and use os_
abstraction. I think this is necessary to have at least a full abstraction.
The main changes are in core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
where I had an offset due to struct size being different on both platform.
I'm curently investigating how to solve this issue and working to maintain compatibility with POSIX platform, which is the most used/maintained one.
from wasm-micro-runtime.
OK, I read the code and added some comments, it should be OK to abstract some os_xxx
structures and functions. I think maybe you can enable the basic functionality and make CI run fine first, and then we can let others help review this PR and give suggestions, like how to abstract the APIs.
from wasm-micro-runtime.
Related Issues (20)
- BH_DEBUG not set in multi-configuration cmake (eg. visual studio)
- printf_wrapper (libc builtin) makes multiple calls to os_printf with individual characters HOT 6
- Can AOT file built on windows run directly on other platforms? HOT 5
- How to load and run another wasm in a running wasm? HOT 12
- Exception Handling Support in Fast Interpreter HOT 1
- iwasm with aot file fail with SIGSEGV HOT 4
- Exception for Assemblyscript HOT 1
- How to cross compile to riscv64 HOT 2
- Unexpected behavior on fast interpreter mode HOT 2
- A bug in validation HOT 2
- Report some typo in wamr.gitbook HOT 1
- Calling "step-over" on the last line of the function failed
- CI test-wamr-ide failed to run HOT 1
- Request to add vmlib on Android platform to align with Linux platform HOT 2
- A bug in ckecking data count section HOT 1
- [wasi-nn] add more backends into `libraries/wasi-nn`
- Enabling WAMR_BUILD_DEBUG_INTERP causes the program to run slower
- Exception: out of bounds memory access HOT 3
- How to debug wasm on the Windows platform HOT 2
- Got Crash when call Intel dcap verification lib which link with wasm from java
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasm-micro-runtime.