Skip to content

Commit c11f469

Browse files
authored
wasip2: Don't reimplement preopens.c (#655)
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.
1 parent f683ada commit c11f469

File tree

5 files changed

+198
-311
lines changed

5 files changed

+198
-311
lines changed

expected/wasm32-wasip2/defined-symbols.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ __wasilibc_open_nomode
339339
__wasilibc_populate_preopens
340340
__wasilibc_pthread_self
341341
__wasilibc_random
342-
__wasilibc_register_preopened_fd
343342
__wasilibc_rename_newat
344343
__wasilibc_rename_oldat
345344
__wasilibc_reset_preopens

libc-bottom-half/headers/public/wasi/libc.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ struct timespec;
2121
/// afterward, you should call this before doing so.
2222
void __wasilibc_populate_preopens(void);
2323

24+
#ifndef __wasilibc_use_wasip2
2425
/// Register the given pre-opened file descriptor under the given path.
25-
#ifdef __wasilibc_use_wasip2
26-
int __wasilibc_register_preopened_fd(filesystem_preopens_own_descriptor_t fd,
27-
wasip2_string_t relprefix);
28-
#else
2926
int __wasilibc_register_preopened_fd(int fd,
3027
const char* prefix);
3128
#endif

0 commit comments

Comments
 (0)