Commit fac6d427 authored by erikchen's avatar erikchen Committed by Commit Bot

Guard use of Chrome TLS in GlobalActivityTracker::GetOrCreateTracker.

The implementation of heap_profiling uses base::Lock. That uses
GlobalActivityTracker::GetOrCreateTracker, which uses Chrome TLS. Since
heap_profiling may be used post TLS destruction, all called code must also guard
against use of Chrome TLS by checking
base::ThreadLocalStorage::HasBeenDestroyed.

Bug: 864589
Change-Id: I9b7b61d702a79062f847f17d18b6d30f3681b837
Reviewed-on: https://chromium-review.googlesource.com/1142347Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576224}
parent fc59e2b9
...@@ -860,6 +860,13 @@ class BASE_EXPORT GlobalActivityTracker { ...@@ -860,6 +860,13 @@ class BASE_EXPORT GlobalActivityTracker {
GlobalActivityTracker* global_tracker = Get(); GlobalActivityTracker* global_tracker = Get();
if (!global_tracker) if (!global_tracker)
return nullptr; return nullptr;
// It is not safe to use TLS once TLS has been destroyed. This can happen
// if code that runs late during thread destruction tries to use a
// base::Lock. See https://crbug.com/864589.
if (base::ThreadLocalStorage::HasBeenDestroyed())
return nullptr;
if (lock_allowed) if (lock_allowed)
return global_tracker->GetOrCreateTrackerForCurrentThread(); return global_tracker->GetOrCreateTrackerForCurrentThread();
else else
......
...@@ -30,6 +30,10 @@ namespace base { ...@@ -30,6 +30,10 @@ namespace base {
class SamplingHeapProfiler; class SamplingHeapProfiler;
namespace debug {
class GlobalActivityTracker;
} // namespace debug
namespace trace_event { namespace trace_event {
class MallocDumpProvider; class MallocDumpProvider;
} // namespace trace_event } // namespace trace_event
...@@ -160,6 +164,7 @@ class BASE_EXPORT ThreadLocalStorage { ...@@ -160,6 +164,7 @@ class BASE_EXPORT ThreadLocalStorage {
friend class base::SamplingHeapProfiler; friend class base::SamplingHeapProfiler;
friend class base::internal::ThreadLocalStorageTestInternal; friend class base::internal::ThreadLocalStorageTestInternal;
friend class base::trace_event::MallocDumpProvider; friend class base::trace_event::MallocDumpProvider;
friend class debug::GlobalActivityTracker;
friend class heap_profiling::ScopedAllowAlloc; friend class heap_profiling::ScopedAllowAlloc;
friend class ui::TLSDestructionCheckerForX11; friend class ui::TLSDestructionCheckerForX11;
static bool HasBeenDestroyed(); static bool HasBeenDestroyed();
......
...@@ -883,6 +883,9 @@ void AllocatorShimLogAlloc(AllocatorType type, ...@@ -883,6 +883,9 @@ void AllocatorShimLogAlloc(AllocatorType type,
} }
} }
// This function may be called post Chrome TLS destruction, so it must not use
// Chrome TLS. It currently uses 3 classes from Chrome: base::Lock,
// base::TimeTicks and base::ScopedPlatformFile, all of which are safe.
void AllocatorShimLogFree(void* address) { void AllocatorShimLogFree(void* address) {
SendBuffer* send_buffers = g_send_buffers.Read(); SendBuffer* send_buffers = g_send_buffers.Read();
if (!send_buffers) if (!send_buffers)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment