Skip to content

Conversation

@alexcrichton
Copy link
Collaborator

This is really tricky path-related code and it's currently buggy on wasip2. Instead of duplicating it like before instead have only a single definition with some small handling of wasip1-vs-wasip2. This fixes chdir, for example, and handling of preopens. The fundamental bug from before is that a wasip2_string_t was handed out as a const char*, but it wasn't null-terminated. The bug is more apparent with all the code paths interleaved here.

This additionally fixes an issue where the previous implementation would continuously open new file descriptors for preopens. Instead now a single file descriptor is registered at preopens-registration-time which is then used throughout the lifetime of the program.

@alexcrichton
Copy link
Collaborator Author

Ah I can also note that this deletes __wasilibc_register_preopened_fd on WASIp2 targets as it should be less necessary and I think we'll want different APIs for interoperating between WASIp2 constructs and libc constructs.

This is really tricky path-related code and it's currently buggy on
wasip2. Instead of duplicating it like before instead have only a single
definition with some small handling of wasip1-vs-wasip2. This fixes
`chdir`, for example, and handling of preopens. The fundamental bug from
before is that a `wasip2_string_t` was handed out as a `const char*`,
but it wasn't null-terminated. The bug is more apparent with all the
code paths interleaved here.

This additionally fixes an issue where the previous implementation would
continuously open new file descriptors for preopens. Instead now a
single file descriptor is registered at preopens-registration-time which
is then used throughout the lifetime of the program.
@alexcrichton alexcrichton merged commit c11f469 into WebAssembly:main Nov 10, 2025
16 checks passed
@alexcrichton alexcrichton deleted the fix-wasip2-chdir branch November 10, 2025 23:17
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