diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sys/vxworks/ext/mod.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sys/vxworks/os.rs | 19 | ||||
| -rw-r--r-- | src/libstd/sys/vxworks/process/process_vxworks.rs | 12 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/args.rs | 1 |
4 files changed, 26 insertions, 9 deletions
diff --git a/src/libstd/sys/vxworks/ext/mod.rs b/src/libstd/sys/vxworks/ext/mod.rs index 251a198f821..8fa9bd9d1e2 100644 --- a/src/libstd/sys/vxworks/ext/mod.rs +++ b/src/libstd/sys/vxworks/ext/mod.rs @@ -18,4 +18,7 @@ pub mod prelude { #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] pub use super::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; + #[doc(no_inline)] + #[stable(feature = "rust1", since = "1.0.0")] + pub use super::process::ExitStatusExt; } diff --git a/src/libstd/sys/vxworks/os.rs b/src/libstd/sys/vxworks/os.rs index baa6c425d2e..71e1d1626c1 100644 --- a/src/libstd/sys/vxworks/os.rs +++ b/src/libstd/sys/vxworks/os.rs @@ -11,14 +11,12 @@ use crate::path::{self, PathBuf, Path}; use crate::ptr; use crate::slice; use crate::str; -use crate::sys_common::mutex::Mutex; +use crate::sys_common::mutex::{Mutex, MutexGuard}; use crate::sys::cvt; /*use sys::fd; this one is probably important */ use crate::vec; const TMPBUF_SZ: usize = 128; -static ENV_LOCK: Mutex = Mutex::new(); - // This is a terrible fix use crate::sys::os_str::Buf; @@ -200,11 +198,18 @@ pub unsafe fn environ() -> *mut *const *const c_char { &mut environ } +pub unsafe fn env_lock() -> MutexGuard<'static> { + // We never call `ENV_LOCK.init()`, so it is UB to attempt to + // acquire this mutex reentrantly! + static ENV_LOCK: Mutex = Mutex::new(); + ENV_LOCK.lock() +} + /// Returns a vector of (variable, value) byte-vector pairs for all the /// environment variables of the current process. pub fn env() -> Env { unsafe { - let _guard = ENV_LOCK.lock(); + let _guard = env_lock(); let mut environ = *environ(); if environ == ptr::null() { panic!("os::env() failure getting env string from OS: {}", @@ -244,7 +249,7 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { // always None as well let k = CString::new(k.as_bytes())?; unsafe { - let _guard = ENV_LOCK.lock(); + let _guard = env_lock(); let s = libc::getenv(k.as_ptr()) as *const libc::c_char; let ret = if s.is_null() { None @@ -260,7 +265,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { let v = CString::new(v.as_bytes())?; unsafe { - let _guard = ENV_LOCK.lock(); + let _guard = env_lock(); cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) } } @@ -269,7 +274,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { let nbuf = CString::new(n.as_bytes())?; unsafe { - let _guard = ENV_LOCK.lock(); + let _guard = env_lock(); cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) } } diff --git a/src/libstd/sys/vxworks/process/process_vxworks.rs b/src/libstd/sys/vxworks/process/process_vxworks.rs index 7446471ae31..79bfd770f8e 100644 --- a/src/libstd/sys/vxworks/process/process_vxworks.rs +++ b/src/libstd/sys/vxworks/process/process_vxworks.rs @@ -15,6 +15,7 @@ impl Command { -> io::Result<(Process, StdioPipes)> { use crate::sys::{cvt_r}; const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX"; + let envp = self.capture_env(); if self.saw_nul() { return Err(io::Error::new(ErrorKind::InvalidInput, @@ -52,12 +53,19 @@ impl Command { t!(cvt(libc::chdir(cwd.as_ptr()))); } + let c_envp = envp.as_ref().map(|c| c.as_ptr()) + .unwrap_or_else(|| *sys::os::environ() as *const _); + let stack_size = thread::min_stack(); + + // ensure that access to the environment is synchronized + let _lock = sys::os::env_lock(); + let ret = libc::rtpSpawn( self.get_argv()[0], // executing program self.get_argv().as_ptr() as *mut *const c_char, // argv - *sys::os::environ() as *mut *const c_char, + c_envp as *mut *const c_char, 100 as c_int, // initial priority - thread::min_stack(), // initial stack size. + stack_size, // initial stack size. 0, // options 0 // task options ); diff --git a/src/libstd/sys/wasi/args.rs b/src/libstd/sys/wasi/args.rs index 3db36f5e132..02aa68d6f3a 100644 --- a/src/libstd/sys/wasi/args.rs +++ b/src/libstd/sys/wasi/args.rs @@ -26,6 +26,7 @@ fn maybe_args() -> Option<Vec<OsString>> { let mut argv = Vec::with_capacity(argc); let mut buf = Vec::with_capacity(buf_size); wasi::args_get(argv.as_mut_ptr(), buf.as_mut_ptr()).ok()?; + argv.set_len(argc); let mut ret = Vec::with_capacity(argc); for ptr in argv { let s = CStr::from_ptr(ptr.cast()); |
