stdlib std.os: Update CWD emulation to match wasi-libc behavior #11053
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Dependent on #11021 .
Some more work is needed to align our CWD treatment on WASI with wasi-libc. This is particularly important for runtimes like wasmer, which inserts a special "/" Preopen by default and also strips leading slashes from other Preopens
Here's the idea behind these changes:
[]const u8
. We lookup Preopens for every absolute or CWD-referenced file operation, based on the Preopen with the longest match (i.e. most specific path)cwd_root
parameter ofinitPreopensWasi
. cwd_root is used only for any Preopens that start with "." so that:The intention is that:
cwd_root
gives behavior similar to wasi-libcThese changes come at a performance cost, since we no longer cache any matching Preopen for the CWD, but the implementation is also much simpler and the compatibility gain from matching wasi-libc's behavior seems worth it.
Another consequence is that we no longer support
fchdir
on WASI