1From 28a638ff22f598f6aa9388db6a4cf13fe9f11644 Mon Sep 17 00:00:00 2001 2From: Hirokazu Honda <hiroh@google.com> 3Date: Wed, 1 Aug 2018 17:03:18 +0900 4Subject: [PATCH] ThreadLocalStorage: Add a function to destroy pthread key 5 used in libchrome 6 7MojoProcessSupport needs to destroy pthread key which is globally used in libchrome. The key is 8stored in a local variable in thread_local_storage.cc. 9This adds a function to destroy the key so that MojoProcessSupport can do it. 10 11Bug: 110722333 12Test: No crash in opening DRMInfo.app 13Test: PlayStore still works 14Test: cheets_ContainerSmokeTest and cheets_LoginScreen 15Change-Id: Ib10c83deb5f7ef141d4ab9883e0d2c31d422a1b1 16--- 17 base/threading/thread_local_storage.cc | 11 +++++++++++ 18 base/threading/thread_local_storage.h | 7 +++++++ 19 2 files changed, 18 insertions(+) 20 21diff --git a/base/threading/thread_local_storage.cc b/base/threading/thread_local_storage.cc 22index 48c1dd5..90ae69e 100644 23--- a/base/threading/thread_local_storage.cc 24+++ b/base/threading/thread_local_storage.cc 25@@ -247,6 +247,17 @@ void PlatformThreadLocalStorage::OnThreadExit() { 26 void PlatformThreadLocalStorage::OnThreadExit(void* value) { 27 OnThreadExitInternal(static_cast<TlsVectorEntry*>(value)); 28 } 29+ 30+// static 31+void PlatformThreadLocalStorage::ForceFreeTLS() { 32+ PlatformThreadLocalStorage::TLSKey key = 33+ base::subtle::NoBarrier_AtomicExchange( 34+ &g_native_tls_key, 35+ PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES); 36+ if (key == PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES) 37+ return; 38+ PlatformThreadLocalStorage::FreeTLS(key); 39+} 40 #endif // defined(OS_WIN) 41 42 } // namespace internal 43diff --git a/base/threading/thread_local_storage.h b/base/threading/thread_local_storage.h 44index fd2a789..c5c7759 100644 45--- a/base/threading/thread_local_storage.h 46+++ b/base/threading/thread_local_storage.h 47@@ -75,6 +75,13 @@ class BASE_EXPORT PlatformThreadLocalStorage { 48 // GetTLSValue() to retrieve the value of slot as it has already been reset 49 // in Posix. 50 static void OnThreadExit(void* value); 51+ // Normally, Chrome runs as a process, so freeing the TLS is not needed since 52+ // the OS will perform that while it's reclaiming the process' memory upon 53+ // termination. If, however, this code is used inside a library that is 54+ // dynamically loaded and unloaded, the consumer is responsible for calling 55+ // this after all Chrome threads have stopped and prior to unloading the 56+ // library. 57+ static void ForceFreeTLS(); 58 #endif 59 }; 60 61-- 622.18.0.345.g5c9ce644c3-goog 63 64