about summary refs log tree commit diff
path: root/src/libstd/sys/vxworks
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2020-03-12 11:39:30 -0700
committerAlex Crichton <alex@alexcrichton.com>2020-03-20 07:34:56 -0700
commit5edaa7eefd76d4996dcf85dfc1c1a3f737087257 (patch)
tree23b94ea5de5fe2856d7f020621e0c0ea1f9734c9 /src/libstd/sys/vxworks
parent23de8275c9b5e5812dc54a12bdba6d80870d9dc8 (diff)
downloadrust-5edaa7eefd76d4996dcf85dfc1c1a3f737087257.tar.gz
rust-5edaa7eefd76d4996dcf85dfc1c1a3f737087257.zip
Fix abort-on-eprintln during process shutdown
This commit fixes an issue where if `eprintln!` is used in a TLS
destructor it can accidentally cause the process to abort. TLS
destructors are executed after `main` returns on the main thread, and at
this point we've also deinitialized global `Lazy` values like those
which store the `Stderr` and `Stdout` internals. This means that despite
handling TLS not being accessible in `eprintln!`, we will fail due to
not being able to call `stderr()`. This means that we'll double-panic
quickly because panicking also attempt to write to stderr.

The fix here is to reimplement the global stderr handle to avoid the
need for destruction. This avoids the need for `Lazy` as well as the
hidden panic inside of the `stderr` function.

Overall this should improve the robustness of printing errors and/or
panics in weird situations, since the `stderr` accessor should be
infallible in more situations.
Diffstat (limited to 'src/libstd/sys/vxworks')
-rw-r--r--src/libstd/sys/vxworks/mutex.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libstd/sys/vxworks/mutex.rs b/src/libstd/sys/vxworks/mutex.rs
index b38375a2e03..103d87e3d2f 100644
--- a/src/libstd/sys/vxworks/mutex.rs
+++ b/src/libstd/sys/vxworks/mutex.rs
@@ -92,11 +92,11 @@ unsafe impl Send for ReentrantMutex {}
 unsafe impl Sync for ReentrantMutex {}
 
 impl ReentrantMutex {
-    pub unsafe fn uninitialized() -> ReentrantMutex {
+    pub const unsafe fn uninitialized() -> ReentrantMutex {
         ReentrantMutex { inner: UnsafeCell::new(libc::PTHREAD_MUTEX_INITIALIZER) }
     }
 
-    pub unsafe fn init(&mut self) {
+    pub unsafe fn init(&self) {
         let mut attr = MaybeUninit::<libc::pthread_mutexattr_t>::uninit();
         let result = libc::pthread_mutexattr_init(attr.as_mut_ptr());
         debug_assert_eq!(result, 0);