Home | History | Annotate | Download | only in patch
      1 From 28a638ff22f598f6aa9388db6a4cf13fe9f11644 Mon Sep 17 00:00:00 2001
      2 From: Hirokazu Honda <hiroh (a] google.com>
      3 Date: Wed, 1 Aug 2018 17:03:18 +0900
      4 Subject: [PATCH] ThreadLocalStorage: Add a function to destroy pthread key
      5  used in libchrome
      6 
      7 MojoProcessSupport needs to destroy pthread key which is globally used in libchrome. The key is
      8 stored in a local variable in thread_local_storage.cc.
      9 This adds a function to destroy the key so that MojoProcessSupport can do it.
     10 
     11 Bug: 110722333
     12 Test: No crash in opening DRMInfo.app
     13 Test: PlayStore still works
     14 Test: cheets_ContainerSmokeTest and cheets_LoginScreen
     15 Change-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 
     21 diff --git a/base/threading/thread_local_storage.cc b/base/threading/thread_local_storage.cc
     22 index 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
     43 diff --git a/base/threading/thread_local_storage.h b/base/threading/thread_local_storage.h
     44 index 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 -- 
     62 2.18.0.345.g5c9ce644c3-goog
     63 
     64