Skip to content

clear descriptor table in __wasilibc_reset_preopens#776

Merged
dicej merged 1 commit intoWebAssembly:mainfrom
dicej:clear-descriptor-table
Mar 23, 2026
Merged

clear descriptor table in __wasilibc_reset_preopens#776
dicej merged 1 commit intoWebAssembly:mainfrom
dicej:clear-descriptor-table

Conversation

@dicej
Copy link
Collaborator

@dicej dicej commented Mar 20, 2026

The original intention of __wasilibc_reset_preopens was to clear the stdio state as the last step of Wizer-style pre-initialization since none of the handles would be valid when the snapshot is resumed. In earlier versions of wasi-libc, which didn't have native p2 or p3 support for stdio or file I/O, resetting the WASIp1 state was sufficient; the wasi_snapshot_preview1 adapter took care of emulating p1 in terms of p2. However, now that wasi-libc has native support for p2 and p3, we need to also reset the descriptor table.

At this point, the name __wasilibc_reset_preopens is a bit misleading for p2+ since we're clearing more than just the preopens, but changing the name would break tools which use it, so probably not worth the trouble.

@dicej dicej requested a review from alexcrichton March 20, 2026 18:59
@dicej dicej force-pushed the clear-descriptor-table branch 4 times, most recently from c7272ec to abda872 Compare March 20, 2026 20:01
@dicej dicej force-pushed the clear-descriptor-table branch 2 times, most recently from e705522 to 4fb1d89 Compare March 23, 2026 14:26
The original intention of `__wasilibc_reset_preopens` was to clear the stdio
state as the last step of Wizer-style pre-initialization since none of the
handles would be valid when the snapshot is resumed.  In earlier versions of
`wasi-libc`, which didn't have native p2 or p3 support for stdio or file I/O,
resetting the WASIp1 state was sufficient; the `wasi_snapshot_preview1` adapter
took care of emulating p1 in terms of p2.  However, now that `wasi-libc` has
native support for p2 and p3, we need to also reset the descriptor table.

At this point, the name `__wasilibc_reset_preopens` is a bit misleading for p2+
since we're clearing more than just the preopens, but changing the name would
break tools which use it, so probably not worth the trouble.
@dicej dicej force-pushed the clear-descriptor-table branch from 4fb1d89 to a74116f Compare March 23, 2026 15:29
@dicej dicej merged commit 4d9cd9d into WebAssembly:main Mar 23, 2026
32 checks passed
@dicej dicej deleted the clear-descriptor-table branch March 23, 2026 15:44
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