summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-03 08:30:16 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-03 08:30:16 +0000
commit45cdc834c4b25b09d9263fc4b6a6c2b6432abdc6 (patch)
treebc2e2f16e48369a61b5be7a4923945305700e747
parent8fc203ba5face785681b3f06eac1d116d937499b (diff)
thread_pthread.c (native_thread_destroy): clear native TSD pointer
mwrap <https://80x24.org/mwrap/> interposes malloc functions and checks for GVL existence to determine Ruby source locations of malloc calls. pthread_getattr_np (from get_stack) may call realloc to get the CPU set size; so when using the thread-cache, ruby_thread_has_gvl_p() may hit a false positive on reused threads with lingering rb_thread_t in thread-specific data. This was causing mwrap to call rb_source_location_cstr() and crash because it was pointed to a zero ec->cfp->iseq. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--thread_pthread.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 401fc0c774..60a3b13a68 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -427,15 +427,22 @@ native_thread_init(rb_thread_t *th)
ruby_thread_set_native(th);
}
+#ifndef USE_THREAD_CACHE
+#define USE_THREAD_CACHE 1
+#endif
+
static void
native_thread_destroy(rb_thread_t *th)
{
rb_native_cond_destroy(&th->native_thread_data.sleep_cond);
-}
-#ifndef USE_THREAD_CACHE
-#define USE_THREAD_CACHE 1
-#endif
+ /*
+ * prevent false positive from ruby_thread_has_gvl_p if that
+ * gets called from an interposing function wrapper
+ */
+ if (USE_THREAD_CACHE)
+ ruby_thread_set_native(0);
+}
#if USE_THREAD_CACHE
static rb_thread_t *register_cached_thread_and_wait(void);