[WasmFS] Fix absolute path access under NODERAWFS#24733
[WasmFS] Fix absolute path access under NODERAWFS#24733kleisauke wants to merge 7 commits intoemscripten-core:mainfrom
Conversation
539e100 to
4c2d596
Compare
99a1e0d to
fd7f0a9
Compare
This reverts commit 88df6ba.
|
Marking as ready for review with a few caveats:
|
This reverts commit 88df6ba.
|
The Windows CI issue was caused due to the temporary directory being located on This has been fixed in commit d364aeb, which also appears to resolve the test failure in |
system/lib/wasmfs/paths.cpp
Outdated
| if (!root->getBackend()->isVirtualized()) { | ||
| return {std::make_pair(std::move(curr), path)}; |
There was a problem hiding this comment.
The whole point of virtualization is that a virtual backend looks the same as a "real" backend. Can we get away without this part of the change?
There was a problem hiding this comment.
IIRC, this change was related to -sNODERAWFS on Windows, which doesn't have a single-root directory
I initially attempted a different fix (see e.g. the changes before commit d364aeb), but it failed when the current working directory and the absolute path to be accessed were on different drives, see comment #24733 (comment).
There was a problem hiding this comment.
I renamed this isVirtualized() check with a requiresPathTraversal() check via commit cb9bb3e.
system/lib/wasmfs/wasmfs.cpp
Outdated
| if (!rootBackend->isVirtualized()) { | ||
| return rootDirectory; | ||
| } |
There was a problem hiding this comment.
Let's use a more precise overridable hook here, e.g. shouldMountSpecialFiles, rather than checking whether the backend is virtual.
There was a problem hiding this comment.
I've just separated this change to PR #26607.
There was a problem hiding this comment.
Are all the changes here just cleanups that are not directly related to the absolute path access problem?
There was a problem hiding this comment.
Yup, I've just separated these changes into individual PRs.
src/lib/libwasmfs_node.js
Outdated
|
|
||
| addToLibrary({ | ||
| $wasmfsNodeIsWindows: !!process.platform.match(/^win/), | ||
| #if !ENVIRONMENT_MAY_BE_NODE |
There was a problem hiding this comment.
This change was to allow a single Wasm binary to run both on Node.js and on the web (if you build with -sWASMFS -sNODERAWFS the Wasm binary is restricted to Node.js only).
I reverted this (and its test case) with commit ff4bba2. A PR will be opened for this later.
There was a problem hiding this comment.
... I just opened PR #26608 for this change.
b1edba4 to
4f20a95
Compare
4f20a95 to
cb9bb3e
Compare
Split out from #24733, this fixes a test failure in `other.test_fs_dev_random_wasmfs_rawfs` from that PR.
tlively
left a comment
There was a problem hiding this comment.
Thanks for splitting this up. It's much more focused and easier to review now. Mostly LGTM, with some bikeshedding and a correctness concern.
| WASMFS_UNREACHABLE("TODO: implement NodeBackend::createSymlink"); | ||
| } | ||
|
|
||
| virtual bool requiresPathTraversal() override { |
There was a problem hiding this comment.
How about calling this usesRawPaths? (And flipping the result, of course.) I think that's slightly easier to understand than requiresPathTraversal, though it's not perfect.
There was a problem hiding this comment.
I think usesRawPaths it's too implementation-specific. How about requiresPathResolution? See commit e21bc63.
| // full path directly. In that case, skip WasmFS path parsing and pass the | ||
| // path through unchanged. | ||
| if (!root->getBackend()->requiresPathTraversal()) { | ||
| return {std::make_pair(std::move(curr), path)}; |
There was a problem hiding this comment.
Is this going to cause WasmFS to model the underlying file system as completely flat, so that there is a single mount directory directly containing every file ever opened, no matter how deep that file is in the underlying directory structure?
If so, is that going to cause problems with reading directory entries?
There was a problem hiding this comment.
Indeed, this is going to break in such situations as it implicitly assumes that the entire file system behaves like the root backend.
Commit e21bc63 changes this to curr->getBackend() instead, which allows:
$ tree / -L 2 --dirsfirst
/ (MEMFS)
├── dev
│ ├── null -> SpecialFiles::getNull()
│ ├── random -> SpecialFiles::getRandom()
│ ├── stderr -> SpecialFiles::getStderr()
│ ├── stdin -> SpecialFiles::getStdin()
│ ├── stdout -> SpecialFiles::getStdout()
│ └── urandom -> SpecialFiles::getURandom()
├── tmp
└── host (NODERAWFS)(i.e. the Node filesystem is mounted under /host, while the wasmfs_create_root_dir() hook is not overriden)
Previously, the WasmFS Node backend assumed Node.js was always available. This change allows building binaries that include Node backend stubs, so they can run in web environments. Split out from #24733.
Resolves: #24830.
Supersedes: #24833.