[前][次][番号順一覧][スレッド一覧]

ruby-changes:51625

From: normal <ko1@a...>
Date: Tue, 3 Jul 2018 17:30:21 +0900 (JST)
Subject: [ruby-changes:51625] normal:r63836 (trunk): thread_pthread.c (native_thread_destroy): clear native TSD pointer

normal	2018-07-03 17:30:16 +0900 (Tue, 03 Jul 2018)

  New Revision: 63836

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63836

  Log:
    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.

  Modified files:
    trunk/thread_pthread.c
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 63835)
+++ thread_pthread.c	(revision 63836)
@@ -427,15 +427,22 @@ native_thread_init(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L427
     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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]