bug 1358151: temporary workaround for rust race condition draft
authorCarl Corcoran <carlco@gmail.com>
Sat, 06 May 2017 14:05:09 +0200
changeset 574743 c37f1194ad895141719e953b6bd50037d1b8c33f
parent 573556 37a5b7f6f101df2eb292b1b6baaf1540c9920e20
child 627699 dc7c1a145edec321c564da5a4ae292944256b3bb
push id57817
push userbmo:ccorcoran@mozilla.com
push dateTue, 09 May 2017 10:47:28 +0000
bugs1358151
milestone55.0a1
bug 1358151: temporary workaround for rust race condition MozReview-Commit-ID: KiPArBKMSu1
toolkit/library/rust/shared/lib.rs
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/library/rust/shared/lib.rs
+++ b/toolkit/library/rust/shared/lib.rs
@@ -14,16 +14,26 @@ extern crate webrender_bindings;
 #[cfg(feature = "cubeb_pulse_rust")]
 extern crate cubeb_pulse;
 
 use std::boxed::Box;
 use std::ffi::CStr;
 use std::os::raw::c_char;
 use std::panic;
 
+
+
+// This workaround is fixed in Rust 1.19. For details, see bug 1358151.
+thread_local!(static UNUSED_THREAD_LOCAL: () = ());
+#[no_mangle]
+pub extern "C" fn rust_init_please_remove_this_after_updating_rust_1_19() {
+    UNUSED_THREAD_LOCAL.with(|_| ());
+}
+
+
 /// Used to implement `nsIDebug2::RustPanic` for testing purposes.
 #[no_mangle]
 pub extern "C" fn intentional_panic(message: *const c_char) {
     panic!("{}", unsafe { CStr::from_ptr(message) }.to_string_lossy());
 }
 
 /// Contains the panic message, if set.
 static mut PANIC_REASON: Option<(*const str, usize)> = None;
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -219,16 +219,22 @@
 #include "SandboxBroker.h"
 #include "SandboxPermissions.h"
 #endif
 #endif
 
 extern uint32_t gRestartMode;
 extern void InstallSignalHandlers(const char *ProgramName);
 
+// This workaround is fixed in Rust 1.19. For details, see bug 1358151.
+// Implementation in toolkit/library/rust/shared/lib.rs
+extern "C" {
+  void rust_init_please_remove_this_after_updating_rust_1_19();
+}
+
 #define FILE_COMPATIBILITY_INFO NS_LITERAL_CSTRING("compatibility.ini")
 #define FILE_INVALIDATE_CACHES NS_LITERAL_CSTRING(".purgecaches")
 
 int    gArgc;
 char **gArgv;
 
 static const char gToolkitVersion[] = NS_STRINGIFY(GRE_MILESTONE);
 static const char gToolkitBuildID[] = NS_STRINGIFY(MOZ_BUILDID);
@@ -3109,16 +3115,19 @@ public:
  */
 int
 XREMain::XRE_mainInit(bool* aExitFlag)
 {
   if (!aExitFlag)
     return 1;
   *aExitFlag = false;
 
+  // This workaround is fixed in Rust 1.19. For details, see bug 1358151.
+  rust_init_please_remove_this_after_updating_rust_1_19();
+
   atexit(UnexpectedExit);
   auto expectedShutdown = mozilla::MakeScopeExit([&] {
     MozExpectedExit();
   });
 
   StartupTimeline::Record(StartupTimeline::MAIN);
 
   if (PR_GetEnv("MOZ_CHAOSMODE")) {