about summary refs log tree commit diff
path: root/src/libstd/sys/vxworks
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-03-21 13:06:38 +0100
committerGitHub <noreply@github.com>2020-03-21 13:06:38 +0100
commit276b54e9c930c4ff015e1958ad1c640deffd29b2 (patch)
tree4c1eb2b3b0d3e5b53b4a4e1ada7042001f5ed089 /src/libstd/sys/vxworks
parent8deeac153fcca97f6a5185b322f8d65d59fab5f4 (diff)
parent5edaa7eefd76d4996dcf85dfc1c1a3f737087257 (diff)
downloadrust-276b54e9c930c4ff015e1958ad1c640deffd29b2.tar.gz
rust-276b54e9c930c4ff015e1958ad1c640deffd29b2.zip
Rollup merge of #69955 - alexcrichton:stderr-infallible, r=sfackler
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);