wasi-sdk | WASI-enabled WebAssembly C/C++ toolchain | Compiler library
kandi X-RAY | wasi-sdk Summary
kandi X-RAY | wasi-sdk Summary
This repository contains no compiler or library code itself; it uses git submodules to pull in the upstream Clang and LLVM tree, as well as the wasi-libc tree. The libc portion of this SDK is the wasi-libc. Upstream Clang and LLVM (from 9.0 onwards) can compile for WASI out of the box, and WebAssembly support is included in them by default. So, all that's done here is to provide builds configured to set the default target and sysroot for convenience. One could also use a standard Clang installation, build a sysroot from the sources mentioned above, and compile with "--target=wasm32-wasi --sysroot=/path/to/sysroot".
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of wasi-sdk
wasi-sdk Key Features
wasi-sdk Examples and Code Snippets
Community Discussions
Trending Discussions on wasi-sdk
QUESTION
I have a re-entrant C++ function whose wasm
output is not "thread-safe" when using imported shared memory, because the function makes use of an aliased stack that lives on the shared linear memory on a hardcoded position.
I'm aware that multithreading is not fully supported yet, and if I want to use multiple instances of the same module concurrently, avoiding crashing and data races it's my responsibility, but I accept the challenge.
My X problem is: My code is not thread-safe, and I need it to be by having non-overlapping stacks.
My Y problem is: I'm trying to modify the __stack_pointer
so I can implement the stack separation, but it doesn't compile. I have tried with extern unsigned char __stack_pointer;
but it throws me the following error:
ANSWER
Answered 2021-Nov-02 at 17:46Firstly, if you are doing multi-threading with emscripten then each thread will already have its own stack and its own value for __stack_pointer
. Thats is part of what defines a thread.
If you still want to manipulate the stack yourself (perhaps to have many stacks within a single thread) then you can use the emscripten helper functions stackSave
(to get the SP of the current thread) and stackRestore
(to set the SP of the current thread).
If you are not using emscripten at all, then you are in uncharted territory (what runtime are using using? how are you starting new threads?), but the simplest way to do stack pointer manipulation would be with assembly code. See how emscripten implements these functions:
https://github.com/emscripten-core/emscripten/blob/main/system/lib/compiler-rt/stack_ops.S
So you could do something like this:
QUESTION
I'm trying to run some small C demos on the web with WebAssembly and pure JS, and I'm compiling my code using WASI-SDK/WASI-libc:
clang --target=wasm32-unknown-wasi --sysroot= -nostartfiles -O3 -flto -Wl,--no-entry -Wl,--export=malloc -Wl,--export-all -Wl,--lto-O3 src.c -o src.wasm
I'm then using this small JS library to implement the WASI functions. This works fine for printing with stdout, and I've even tested passing strings and other types into different functions. But I can't figure out how to pass an array of strings into main
as an argument.
I don't want to use Node or Emscripten, which is why I went with a minimal JS implementation.
Edit:
To add command line arguments, I removed both -nostartfiles
and -Wl,--no-entry
from my compiler call and implemented args_get
and args_sizes_get
from the WASI standard. From there, it was as simple as calling _start
from the wasm
's exported functions.
ANSWER
Answered 2021-May-12 at 07:11If you want to use WASI then the way to pass args to main is to implement the wasi_snapshot_preview1.args_get
and wasi_snapshot_preview1.args_sizes_get
syscalls which are used by WASI programs to access the argv values. In that case you would want to call _start
rather than main
.
If you want to bypass that and call main
directly you would need to somehow allocate and array of char *
pointers in the linear memory which you could then pass as your argv value. The problem that you face if you try to take this approach is that allocating memory (e.g. via malloc) before calling main is hard. My advise would be to go with the first method which is to call _start
and implement that wasi
syscall needed to access argv
. (You can call also then remove the -Wl,--no-entry
from your link command).
QUESTION
I'm trying to call a WASI function (fd_write) directly in a C program using wasi-sdk. This is the the library (lib.c):
...ANSWER
Answered 2020-Jul-25 at 07:33Found the answer in wasi-libc source code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install wasi-sdk
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page