Hi wasmtime team, I am working on a project with wasmtime C API. I want to get the sandbox's stdout on the host side and save it as a variable on the host side, but I don't want it inherit the host stdout or dump to a file, is there a third way I can achieve it, such as change the guest code?
Currently there isn't a C API for this, but some work has been done on this in the past and it's of interest to others as well, just hasn't landed yet.
Thanks @Alex Crichton , this is helpful, I might try it to see if it works. Another question, similar to stdout, is there a way that the host can pass a string parameter to the webassembly module? in addition to this pull request, I know host stdin and file could do this, is there other way can do this?
In theory, yes, in practice, it's complicated. For that you'll likely want the component model in the limit, in the meantime you'll need a more advanced system where the guest exposes a malloc you call to fill in and the string is passed by pointer
This api: WASM_API_EXTERN wasmtime_error_t *wasmtime_func_call(
wasmtime_context_t *store,
const wasmtime_func_t *func,
const wasmtime_val_t *args,
size_t nargs,
wasmtime_val_t *results,
size_t nresults,
wasm_trap_t **trap
);
The third and fifth parameters are only for basic types not string?
Correct, yeah, just the basic wasm types i32/i64/f32/f64/v128
Got it, Thanks @Alex Crichton
I just found this "A new wasi_config_set_stdin_bytes function is available in the C API to set the stdin of a WASI-using module from an in-memory slice." This is good, at least it can pass a memory data of the host to the webassembly module.
I tested it, this API works, so great :smiley:
Last updated: Dec 23 2024 at 12:05 UTC