Commit 9a868c7e authored by Benoit Lize's avatar Benoit Lize Committed by Commit Bot

[PartitionAlloc] Remove static locals used on the allocation path.

Threadsafe static local variables call into the C runtime on Windows,
which may not be safe in the allocation path (see linked bug). Don't use
them for code which is on this path.

This is using base::LazyInstance. It currently fulfills our needs,
though it is not ideal for a couple reasons:
- Not guaranteed to stay independent from local statics.
- Can allocate in some paths (mostly DCHECK()s)

As such, this is temporary, and we should either make sure that
LazyInstance is suitable, or have a replacement local to PartitionAlloc.

Bug: 1126432
Change-Id: I9cffed6f313c3fb380383a1607f0e6f27397c2a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401469Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805698}
parent e7bbc732
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/allocator/partition_allocator/page_allocator_internal.h" #include "base/allocator/partition_allocator/page_allocator_internal.h"
#include "base/allocator/partition_allocator/partition_alloc_check.h" #include "base/allocator/partition_allocator/partition_alloc_check.h"
#include "base/bits.h" #include "base/bits.h"
#include "base/lazy_instance.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -53,14 +54,16 @@ bool WARN_UNUSED_RESULT CommitPages(void* address, size_t size) { ...@@ -53,14 +54,16 @@ bool WARN_UNUSED_RESULT CommitPages(void* address, size_t size) {
return true; return true;
} }
base::LazyInstance<AddressPoolManager>::Leaky g_address_pool_manager =
LAZY_INSTANCE_INITIALIZER;
} // namespace } // namespace
constexpr size_t AddressPoolManager::Pool::kMaxBits; constexpr size_t AddressPoolManager::Pool::kMaxBits;
// static // static
AddressPoolManager* AddressPoolManager::GetInstance() { AddressPoolManager* AddressPoolManager::GetInstance() {
static NoDestructor<AddressPoolManager> instance; return g_address_pool_manager.Pointer();
return instance.get();
} }
pool_handle AddressPoolManager::Add(uintptr_t ptr, size_t length) { pool_handle AddressPoolManager::Add(uintptr_t ptr, size_t length) {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/allocator/partition_allocator/address_pool_manager_types.h" #include "base/allocator/partition_allocator/address_pool_manager_types.h"
#include "base/allocator/partition_allocator/partition_alloc_constants.h" #include "base/allocator/partition_allocator/partition_alloc_constants.h"
#include "base/atomicops.h" #include "base/atomicops.h"
#include "base/no_destructor.h" #include "base/lazy_instance.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/thread_annotations.h" #include "base/thread_annotations.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -81,7 +81,7 @@ class BASE_EXPORT AddressPoolManager { ...@@ -81,7 +81,7 @@ class BASE_EXPORT AddressPoolManager {
static constexpr size_t kNumPools = 2; static constexpr size_t kNumPools = 2;
Pool pools_[kNumPools]; Pool pools_[kNumPools];
friend class NoDestructor<AddressPoolManager>; friend struct base::LazyInstanceTraitsBase<AddressPoolManager>;
DISALLOW_COPY_AND_ASSIGN(AddressPoolManager); DISALLOW_COPY_AND_ASSIGN(AddressPoolManager);
}; };
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/allocator/partition_allocator/partition_alloc_check.h" #include "base/allocator/partition_allocator/partition_alloc_check.h"
#include "base/bits.h" #include "base/bits.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "base/lazy_instance.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/numerics/checked_math.h" #include "base/numerics/checked_math.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
...@@ -36,10 +37,11 @@ namespace base { ...@@ -36,10 +37,11 @@ namespace base {
namespace { namespace {
LazyInstance<Lock>::Leaky g_reserve_lock = LAZY_INSTANCE_INITIALIZER;
// We may reserve/release address space on different threads. // We may reserve/release address space on different threads.
Lock& GetReserveLock() { Lock& GetReserveLock() {
static NoDestructor<Lock> lock; return g_reserve_lock.Get();
return *lock;
} }
std::atomic<size_t> g_total_mapped_address_space; std::atomic<size_t> g_total_mapped_address_space;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "base/allocator/partition_allocator/random.h" #include "base/allocator/partition_allocator/random.h"
#include "base/lazy_instance.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
...@@ -12,9 +13,10 @@ namespace base { ...@@ -12,9 +13,10 @@ namespace base {
namespace { namespace {
LazyInstance<Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER;
Lock& GetLock() { Lock& GetLock() {
static NoDestructor<Lock> lock; return g_lock.Get();
return *lock;
} }
} // namespace } // namespace
......
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