diff options
Diffstat (limited to '')
-rw-r--r-- | libc-bottom-half/sources/preopens.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/libc-bottom-half/sources/preopens.c b/libc-bottom-half/sources/preopens.c index b495433..3386ca4 100644 --- a/libc-bottom-half/sources/preopens.c +++ b/libc-bottom-half/sources/preopens.c @@ -260,7 +260,7 @@ void __wasilibc_populate_preopens(void) { if (prefix == NULL) goto software; - // TODO: Remove the cast on `path` once the witx is updated with + // TODO: Remove the cast on `prefix` once the witx is updated with // char8 support. ret = __wasi_fd_prestat_dir_name(fd, (uint8_t *)prefix, prestat.u.dir.pr_name_len); @@ -290,3 +290,23 @@ oserr: software: _Exit(EX_SOFTWARE); } + +void __wasilibc_reset_preopens(void) { + LOCK(lock); + + if (num_preopens) { + for (int i = 0; i < num_preopens; ++i) { + free((void*) preopens[i].prefix); + } + free(preopens); + } + + preopens_populated = false; + preopens = NULL; + num_preopens = 0; + preopen_capacity = 0; + + assert_invariants(); + + UNLOCK(lock); +} |