diff options
author | Hirokazu Honda <hiroh@google.com> | 2018-08-01 17:03:18 +0900 |
---|---|---|
committer | Hirokazu Honda <hiroh@google.com> | 2018-08-01 17:04:51 +0900 |
commit | 780a5f1a24afe772e90085769ffc1bbc1ef39d48 (patch) | |
tree | 7c75a642abe063c1fb5e86cb2246baeb7546855c | |
parent | 1fef1a678393e55d295f295a1d0e5fff89a5c725 (diff) | |
download | libchrome-780a5f1a24afe772e90085769ffc1bbc1ef39d48.tar.gz |
ThreadLocalStorage: Add a function to destroy pthread key used in libchrome
MojoProcessSupport needs to destroy pthread key which is globally used in libchrome. The key is
stored in a local variable in thread_local_storage.cc.
This adds a function to destroy the key so that MojoProcessSupport can do it.
Bug: 110722333
Test: No crash in opening DRMInfo.app
Test: PlayStore still works
Test: cheets_ContainerSmokeTest and cheets_LoginScreen
Change-Id: Ib10c83deb5f7ef141d4ab9883e0d2c31d422a1b1
-rw-r--r-- | ThreadLocalStorage-Add-a-function-to-destroy-pthread.patch | 63 | ||||
-rw-r--r-- | base/threading/thread_local_storage.cc | 11 | ||||
-rw-r--r-- | base/threading/thread_local_storage.h | 7 |
3 files changed, 81 insertions, 0 deletions
diff --git a/ThreadLocalStorage-Add-a-function-to-destroy-pthread.patch b/ThreadLocalStorage-Add-a-function-to-destroy-pthread.patch new file mode 100644 index 0000000000..2c214379b3 --- /dev/null +++ b/ThreadLocalStorage-Add-a-function-to-destroy-pthread.patch @@ -0,0 +1,63 @@ +From 28a638ff22f598f6aa9388db6a4cf13fe9f11644 Mon Sep 17 00:00:00 2001 +From: Hirokazu Honda <hiroh@google.com> +Date: Wed, 1 Aug 2018 17:03:18 +0900 +Subject: [PATCH] ThreadLocalStorage: Add a function to destroy pthread key + used in libchrome + +MojoProcessSupport needs to destroy pthread key which is globally used in libchrome. The key is +stored in a local variable in thread_local_storage.cc. +This adds a function to destroy the key so that MojoProcessSupport can do it. + +Bug: 110722333 +Test: No crash in opening DRMInfo.app +Test: PlayStore still works +Test: cheets_ContainerSmokeTest and cheets_LoginScreen +Change-Id: Ib10c83deb5f7ef141d4ab9883e0d2c31d422a1b1 +--- + base/threading/thread_local_storage.cc | 11 +++++++++++ + base/threading/thread_local_storage.h | 7 +++++++ + 2 files changed, 18 insertions(+) + +diff --git a/base/threading/thread_local_storage.cc b/base/threading/thread_local_storage.cc +index 48c1dd5..90ae69e 100644 +--- a/base/threading/thread_local_storage.cc ++++ b/base/threading/thread_local_storage.cc +@@ -247,6 +247,17 @@ void PlatformThreadLocalStorage::OnThreadExit() { + void PlatformThreadLocalStorage::OnThreadExit(void* value) { + OnThreadExitInternal(static_cast<TlsVectorEntry*>(value)); + } ++ ++// static ++void PlatformThreadLocalStorage::ForceFreeTLS() { ++ PlatformThreadLocalStorage::TLSKey key = ++ base::subtle::NoBarrier_AtomicExchange( ++ &g_native_tls_key, ++ PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES); ++ if (key == PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES) ++ return; ++ PlatformThreadLocalStorage::FreeTLS(key); ++} + #endif // defined(OS_WIN) + + } // namespace internal +diff --git a/base/threading/thread_local_storage.h b/base/threading/thread_local_storage.h +index fd2a789..c5c7759 100644 +--- a/base/threading/thread_local_storage.h ++++ b/base/threading/thread_local_storage.h +@@ -75,6 +75,13 @@ class BASE_EXPORT PlatformThreadLocalStorage { + // GetTLSValue() to retrieve the value of slot as it has already been reset + // in Posix. + static void OnThreadExit(void* value); ++ // Normally, Chrome runs as a process, so freeing the TLS is not needed since ++ // the OS will perform that while it's reclaiming the process' memory upon ++ // termination. If, however, this code is used inside a library that is ++ // dynamically loaded and unloaded, the consumer is responsible for calling ++ // this after all Chrome threads have stopped and prior to unloading the ++ // library. ++ static void ForceFreeTLS(); + #endif + }; + +-- +2.18.0.345.g5c9ce644c3-goog + diff --git a/base/threading/thread_local_storage.cc b/base/threading/thread_local_storage.cc index 48c1dd58c2..90ae69e90e 100644 --- a/base/threading/thread_local_storage.cc +++ b/base/threading/thread_local_storage.cc @@ -247,6 +247,17 @@ void PlatformThreadLocalStorage::OnThreadExit() { void PlatformThreadLocalStorage::OnThreadExit(void* value) { OnThreadExitInternal(static_cast<TlsVectorEntry*>(value)); } + +// static +void PlatformThreadLocalStorage::ForceFreeTLS() { + PlatformThreadLocalStorage::TLSKey key = + base::subtle::NoBarrier_AtomicExchange( + &g_native_tls_key, + PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES); + if (key == PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES) + return; + PlatformThreadLocalStorage::FreeTLS(key); +} #endif // defined(OS_WIN) } // namespace internal diff --git a/base/threading/thread_local_storage.h b/base/threading/thread_local_storage.h index fd2a789d01..c5c7759efc 100644 --- a/base/threading/thread_local_storage.h +++ b/base/threading/thread_local_storage.h @@ -75,6 +75,13 @@ class BASE_EXPORT PlatformThreadLocalStorage { // GetTLSValue() to retrieve the value of slot as it has already been reset // in Posix. static void OnThreadExit(void* value); + // Normally, Chrome runs as a process, so freeing the TLS is not needed since + // the OS will perform that while it's reclaiming the process' memory upon + // termination. If, however, this code is used inside a library that is + // dynamically loaded and unloaded, the consumer is responsible for calling + // this after all Chrome threads have stopped and prior to unloading the + // library. + static void ForceFreeTLS(); #endif }; |