Skip to content

Commit 3c4a3f9

Browse files
committed
Also add a way to read environ without triggering eager init.
Add a `__wasilibc_get_environ` function which returns the value of `environ` but without performing eager init.
1 parent 82fc2c4 commit 3c4a3f9

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

expected/wasm32-wasi/defined-symbols.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ __wasilibc_fd_renumber
313313
__wasilibc_find_abspath
314314
__wasilibc_find_relpath
315315
__wasilibc_find_relpath_alloc
316+
__wasilibc_get_environ
316317
__wasilibc_initialize_environ
317318
__wasilibc_link
318319
__wasilibc_link_newat

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ void __wasilibc_deinitialize_environ(void);
2424
/// referenced in the program.
2525
void __wasilibc_maybe_reinitialize_environ_eagerly(void);
2626

27+
/// Return the value of the `environ` variable. Using `environ` directly
28+
/// requires eager initialization of the environment variables. Using this
29+
/// function instead of `environ` allows initialization to happen lazily.
30+
char **__wasilibc_get_environ(void);
31+
2732
#ifdef __cplusplus
2833
}
2934
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <wasi/libc-environ.h>
2+
3+
extern char **__wasilibc_environ;
4+
5+
// See the comments in libc-environ.h.
6+
char **__wasilibc_get_environ(void) {
7+
// Perform lazy initialization if needed.
8+
__wasilibc_ensure_environ();
9+
10+
// Return `environ`. Use the `__wasilibc_`-prefixed name so that we don't
11+
// pull in the `environ` symbol directly, which would lead to eager
12+
// initialization being done instead.
13+
return __wasilibc_environ;
14+
}

0 commit comments

Comments
 (0)