Skip to content

[FS] Make fstat work on file descriptors with no name in node rawfs - #23364

Merged
hoodmane merged 11 commits into
emscripten-core:mainfrom
hoodmane:anonymous-file-descriptors-rawfs
Jan 22, 2025
Merged

hoodmane merged 11 commits into
emscripten-core:mainfrom
hoodmane:anonymous-file-descriptors-rawfs

Conversation

@hoodmane

Copy link
Copy Markdown
Collaborator

This fixes fstat on "anonymous" file descriptors in node rawfs. It is split off from #23058.

@hoodmane hoodmane changed the title Make fstat work on file descriptors with no name in node rawfs [FS] Make fstat work on file descriptors with no name in node rawfs Jan 12, 2025
@hoodmane

Copy link
Copy Markdown
Collaborator Author

@sbc100 could you review this when you have a chance?

@hoodmane
hoodmane requested a review from sbc100 January 13, 2025 11:38
@hoodmane

Copy link
Copy Markdown
Collaborator Author

@sbc100 I'd still appreciate review on this when you have a chance, it's only 10 lines of source changes.

This is an automatic change generated by tools/maint/rebaseline_tests.py.

The following (13) test expectation files were updated by
running the tests with `--rebaseline`:

```
other/codesize/test_codesize_cxx_ctors1.size: 129211 => 129218 [+7 bytes / +0.01%]
other/codesize/test_codesize_cxx_ctors2.size: 128623 => 128630 [+7 bytes / +0.01%]
other/codesize/test_codesize_cxx_except.size: 170879 => 170886 [+7 bytes / +0.00%]
other/codesize/test_codesize_cxx_except_wasm.size: 142162 => 142169 [+7 bytes / +0.00%]
other/codesize/test_codesize_cxx_except_wasm_exnref.size: 144708 => 144715 [+7 bytes / +0.00%]
other/codesize/test_codesize_cxx_mangle.size: 232724 => 232731 [+7 bytes / +0.00%]
other/codesize/test_codesize_cxx_noexcept.size: 131774 => 131781 [+7 bytes / +0.01%]
other/codesize/test_codesize_cxx_wasmfs.size: 169181 => 169188 [+7 bytes / +0.00%]
other/codesize/test_codesize_hello_O0.size: 15101 => 15113 [+12 bytes / +0.08%]
other/codesize/test_codesize_minimal_pthreads.size: 19394 => 19405 [+11 bytes / +0.06%]
other/test_unoptimized_code_size.wasm.size: 15101 => 15113 [+12 bytes / +0.08%]
other/test_unoptimized_code_size_no_asserts.wasm.size: 12182 => 12194 [+12 bytes / +0.10%]
other/test_unoptimized_code_size_strict.wasm.size: 15101 => 15113 [+12 bytes / +0.08%]

Average change: +0.03% (+0.00% - +0.10%)
```
Comment thread test/test_core.py Outdated

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm % question

This is an automatic change generated by tools/maint/rebaseline_tests.py.

The following (10) test expectation files were updated by
running the tests with `--rebaseline`:

```
other/codesize/test_codesize_cxx_ctors1.size: 129211 => 129218 [+7 bytes / +0.01%]
other/codesize/test_codesize_cxx_ctors2.size: 128623 => 128630 [+7 bytes / +0.01%]
other/codesize/test_codesize_cxx_except.size: 170879 => 170886 [+7 bytes / +0.00%]
other/codesize/test_codesize_cxx_except_wasm.size: 144708 => 144715 [+7 bytes / +0.00%]
other/codesize/test_codesize_cxx_except_wasm_legacy.size: 142162 => 142169 [+7 bytes / +0.00%]
other/codesize/test_codesize_cxx_mangle.size: 232724 => 232731 [+7 bytes / +0.00%]
other/codesize/test_codesize_cxx_noexcept.size: 131774 => 131781 [+7 bytes / +0.01%]
other/codesize/test_codesize_cxx_wasmfs.size: 169181 => 169188 [+7 bytes / +0.00%]
other/codesize/test_codesize_hello_O0.size: 15101 => 15113 [+12 bytes / +0.08%]
other/codesize/test_codesize_minimal_pthreads.size: 19394 => 19405 [+11 bytes / +0.06%]

Average change: +0.02% (+0.00% - +0.08%)
```
@hoodmane
hoodmane enabled auto-merge (squash) January 22, 2025 12:24
@hoodmane
hoodmane merged commit 9d4abe8 into emscripten-core:main Jan 22, 2025
@hoodmane
hoodmane deleted the anonymous-file-descriptors-rawfs branch January 22, 2025 17:01
sbc100 pushed a commit that referenced this pull request Sep 1, 2026
This fixes a crash in `fstat` on the standard streams under
`-sNODERAWFS`, resolving #27628.

The getattr dispatch added in #27305 for virtual streams (pipes,
sockets) dereferences `stream.node`, but the standard streams created by
NODERAWFS carried no node at all — unlike streams from `open()`, which
since #23364 carry a synthetic node with the identity of the underlying
file. Rather than special-casing the missing node, this gives the
standard streams the same synthetic node, built from `fstat` of the
inherited descriptor, restoring the invariant that every stream has a
node:

* `createStandardStreams` now constructs each stdio stream with a node
carrying the id and mode of whatever the descriptor refers to (tty,
pipe, file).
* `fstat` on stdio falls through to `fs.fstatSync` on the raw descriptor
as before.

Adds `test_fs_fstat_stdio` covering `fstat` on fds 0-2 across all
filesystem backends.

_Made with AI assistance under my review_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants