Stream: general

Topic: how to get the guest stdout on the host side


view this post on Zulip lyuxiaosu (Jun 30 2023 at 20:25):

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?

view this post on Zulip Alex Crichton (Jun 30 2023 at 20:28):

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.

As discussed in issue #4372 and respective issues about python and go bindings. Can replace wasi_config_inherit_stdout in examples/wasi/main.c:79 wasi_config_t *wasi_config = wasi_config_new(); ass...

view this post on Zulip lyuxiaosu (Jun 30 2023 at 20:55):

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?

view this post on Zulip Alex Crichton (Jun 30 2023 at 20:56):

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

view this post on Zulip lyuxiaosu (Jun 30 2023 at 21:05):

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?

view this post on Zulip Alex Crichton (Jun 30 2023 at 21:11):

Correct, yeah, just the basic wasm types i32/i64/f32/f64/v128

view this post on Zulip lyuxiaosu (Jun 30 2023 at 21:15):

Got it, Thanks @Alex Crichton

view this post on Zulip lyuxiaosu (Jul 01 2023 at 06:15):

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.

view this post on Zulip lyuxiaosu (Jul 01 2023 at 06:36):

I tested it, this API works, so great :smiley:


Last updated: Dec 23 2024 at 12:05 UTC