diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-02-10 15:28:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-10 15:28:48 +0100 |
| commit | a4c64b9c0e24e2436a5cc0a75ab65d2738a73bab (patch) | |
| tree | 357c2482fe899982b22292e1919e42a9700a531d /library/std/src | |
| parent | d8e4d99001660334bdc28704cda6f63d846c90da (diff) | |
| parent | 4b1157509f96e4fffe7ef40ab8cbaa08704d36cc (diff) | |
| download | rust-a4c64b9c0e24e2436a5cc0a75ab65d2738a73bab.tar.gz rust-a4c64b9c0e24e2436a5cc0a75ab65d2738a73bab.zip | |
Rollup merge of #107866 - sunfishcode:sunfishcode/wasi-lazy-environ, r=workingjubilee
Allow wasi-libc to initialize its environment variables lazily. Use `__wasilibc_get_environ()` to read the environment variable list from wasi-libc instead of using `environ`. `environ` is a global variable which effectively requires wasi-libc to initialize the environment variables eagerly, and `__wasilibc_get_environ()` is specifically designed to be an alternative that lets wasi-libc intiailize its environment variables lazily. This should have the side effect of fixing at least some of the cases of #107635.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sys/wasi/os.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/sys/wasi/os.rs b/library/std/src/sys/wasi/os.rs index f5513e9996d..9919dc7087e 100644 --- a/library/std/src/sys/wasi/os.rs +++ b/library/std/src/sys/wasi/os.rs @@ -21,6 +21,7 @@ mod libc { extern "C" { pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char; pub fn chdir(dir: *const c_char) -> c_int; + pub fn __wasilibc_get_environ() -> *mut *mut c_char; } } @@ -161,7 +162,12 @@ impl Iterator for Env { pub fn env() -> Env { unsafe { let _guard = env_read_lock(); - let mut environ = libc::environ; + + // Use `__wasilibc_get_environ` instead of `environ` here so that we + // don't require wasi-libc to eagerly initialize the environment + // variables. + let mut environ = libc::__wasilibc_get_environ(); + let mut result = Vec::new(); if !environ.is_null() { while !(*environ).is_null() { |
