Stream: general

Topic: How does wasmtime allow --mapdir to use absoluate path


view this post on Zulip Yage Hu (Jan 17 2021 at 21:33):

WASI spec does not support absolute paths in path_open. But wasmtime allows me to use --mapdir and open a file with absolute path. My question is how is that accomplished. This doc mentions a "technique based on libpreopen."

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

view this post on Zulip bjorn3 (Jan 17 2021 at 22:12):

Every --mapdir usage will cause a file descriptor to be opened just before running the wasi program. Using a certain wasi function (i believe it is called something like fd_prestat) the wasi program can get the path it should appear as to the user code. When opening an absolute path, libpreopen will lookup the right file descriptor based on this information and then use path_open with the right relative path.

view this post on Zulip bjorn3 (Jan 17 2021 at 22:13):

@Yage Hu

view this post on Zulip Yage Hu (Jan 18 2021 at 02:07):

Gotcha. So wasmtime stores a mapping of absolute paths to directory fds and looks up the fd with the absolute path. Am I right? Is this completely handled by libpreopen?


Last updated: Oct 23 2024 at 20:03 UTC