From 1d19ad97871d22fb26a6ba0856d106546da8612d Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 3 Oct 2013 21:34:35 -0700 Subject: Fix thread safety issues in dynamic_lib The root issue is that dlerror isn't reentrant or even thread safe. The Windows code isn't affected since errno is thread-local on Windows and it's running in an atomically block to ensure there isn't a green thread context switch. Closes #8156 --- src/rt/rust_builtin.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/rt/rust_builtin.cpp') diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index eeb0c95337a..34d1efd577d 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -609,6 +609,18 @@ rust_drop_linenoise_lock() { linenoise_lock.unlock(); } +static lock_and_signal dlerror_lock; + +extern "C" CDECL void +rust_take_dlerror_lock() { + dlerror_lock.lock(); +} + +extern "C" CDECL void +rust_drop_dlerror_lock() { + dlerror_lock.unlock(); +} + extern "C" CDECL unsigned int rust_valgrind_stack_register(void *start, void *end) { return VALGRIND_STACK_REGISTER(start, end); -- cgit 1.4.1-3-g733a5