Commit 3b955c6c authored by Keishi Hattori's avatar Keishi Hattori Committed by Chromium LUCI CQ

Fix BackupRefPtr 32bit builds

For 32 bit builds, IsManagedByPartitionAllocNormalBuckets() was declared in address_pool_manager.h
But simply including it in checked_ptr.h would balloon the amount of dependencies for checked_ptr.h
So I moved everything required to implement IsManagedByPartitionAlloc* for 32bit to address_pool_manager_bitmap.h
This reduced the amount of files to exclude from the rewriter to just base/synchronization/lock_impl.h

Bug: 1080832
Change-Id: I0f07156f7afc90e49f93e90a23d5d20595d44bcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2637095
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: default avatarBartek Nowierski <bartekn@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845071}
parent 7576e669
......@@ -1775,6 +1775,8 @@ component("base") {
# PartitionAlloc uses SpinLock, which doesn't work in NaCl (see below).
"allocator/partition_allocator/address_pool_manager.cc",
"allocator/partition_allocator/address_pool_manager.h",
"allocator/partition_allocator/address_pool_manager_bitmap.cc",
"allocator/partition_allocator/address_pool_manager_bitmap.h",
"allocator/partition_allocator/address_pool_manager_types.h",
"allocator/partition_allocator/address_space_randomization.cc",
"allocator/partition_allocator/address_space_randomization.h",
......
......@@ -204,21 +204,6 @@ AddressPoolManager::Pool::~Pool() = default;
#else // defined(PA_HAS_64_BITS_POINTERS)
namespace {
LazyInstance<Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER;
} // namespace
Lock& AddressPoolManager::GetLock() {
return g_lock.Get();
}
std::bitset<AddressPoolManager::kDirectMapBits>
AddressPoolManager::directmap_bits_; // GUARDED_BY(GetLock())
std::bitset<AddressPoolManager::kNormalBucketBits>
AddressPoolManager::normal_bucket_bits_; // GUARDED_BY(GetLock())
template <size_t bitsize>
void SetBitmap(std::bitset<bitsize>& bitmap,
size_t start_bit,
......@@ -279,39 +264,41 @@ void AddressPoolManager::MarkUsed(pool_handle handle,
const char* address,
size_t length) {
uintptr_t ptr_as_uintptr = reinterpret_cast<uintptr_t>(address);
AutoLock guard(GetLock());
AutoLock guard(AddressPoolManagerBitmap::GetLock());
if (handle == kDirectMapHandle) {
SetBitmap(directmap_bits_, ptr_as_uintptr / PageAllocationGranularity(),
SetBitmap(AddressPoolManagerBitmap::directmap_bits_,
ptr_as_uintptr / PageAllocationGranularity(),
length / PageAllocationGranularity());
} else {
PA_DCHECK(handle == kNormalBucketHandle);
PA_DCHECK(!(length & kSuperPageOffsetMask));
SetBitmap(normal_bucket_bits_, ptr_as_uintptr >> kSuperPageShift,
length >> kSuperPageShift);
SetBitmap(AddressPoolManagerBitmap::normal_bucket_bits_,
ptr_as_uintptr >> kSuperPageShift, length >> kSuperPageShift);
}
}
void AddressPoolManager::MarkUnused(pool_handle handle,
uintptr_t address,
size_t length) {
AutoLock guard(GetLock());
AutoLock guard(AddressPoolManagerBitmap::GetLock());
// Currently, address regions allocated by kNormalBucketHandle are never freed
// in PartitionAlloc. Thus we have LIKELY for kDirectMapHandle
if (LIKELY(handle == kDirectMapHandle)) {
ResetBitmap(directmap_bits_, address / PageAllocationGranularity(),
ResetBitmap(AddressPoolManagerBitmap::directmap_bits_,
address / PageAllocationGranularity(),
length / PageAllocationGranularity());
} else {
PA_DCHECK(handle == kNormalBucketHandle);
PA_DCHECK(!(length & kSuperPageOffsetMask));
ResetBitmap(normal_bucket_bits_, address >> kSuperPageShift,
length >> kSuperPageShift);
ResetBitmap(AddressPoolManagerBitmap::normal_bucket_bits_,
address >> kSuperPageShift, length >> kSuperPageShift);
}
}
void AddressPoolManager::ResetForTesting() {
AutoLock guard(GetLock());
directmap_bits_.reset();
normal_bucket_bits_.reset();
AutoLock guard(AddressPoolManagerBitmap::GetLock());
AddressPoolManagerBitmap::directmap_bits_.reset();
AddressPoolManagerBitmap::normal_bucket_bits_.reset();
}
#endif // defined(PA_HAS_64_BITS_POINTERS)
......
......@@ -7,6 +7,7 @@
#include <bitset>
#include "base/allocator/partition_allocator/address_pool_manager_bitmap.h"
#include "base/allocator/partition_allocator/address_pool_manager_types.h"
#include "base/allocator/partition_allocator/partition_alloc_check.h"
#include "base/allocator/partition_allocator/partition_alloc_constants.h"
......@@ -59,15 +60,11 @@ class BASE_EXPORT AddressPoolManager {
#if !defined(PA_HAS_64_BITS_POINTERS)
static bool IsManagedByDirectMapPool(const void* address) {
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
return TS_UNCHECKED_READ(directmap_bits_)
.test(address_as_uintptr / PageAllocationGranularity());
return AddressPoolManagerBitmap::IsManagedByDirectMapPool(address);
}
static bool IsManagedByNormalBucketPool(const void* address) {
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
return TS_UNCHECKED_READ(normal_bucket_bits_)
.test(address_as_uintptr >> kSuperPageShift);
return AddressPoolManagerBitmap::IsManagedByNormalBucketPool(address);
}
#endif
......@@ -118,21 +115,9 @@ class BASE_EXPORT AddressPoolManager {
#else // defined(PA_HAS_64_BITS_POINTERS)
static constexpr uint64_t kAddressSpaceSize = 4ULL * kGiB;
static constexpr size_t kNormalBucketBits =
kAddressSpaceSize / kSuperPageSize;
static constexpr size_t kDirectMapBits =
kAddressSpaceSize / PageAllocationGranularity();
void MarkUsed(pool_handle handle, const char* address, size_t size);
void MarkUnused(pool_handle handle, uintptr_t address, size_t size);
static Lock& GetLock();
static std::bitset<kDirectMapBits> directmap_bits_ GUARDED_BY(GetLock());
static std::bitset<kNormalBucketBits> normal_bucket_bits_
GUARDED_BY(GetLock());
static constexpr pool_handle kDirectMapHandle = 1;
static constexpr pool_handle kNormalBucketHandle = 2;
friend internal::pool_handle GetDirectMapPool();
......@@ -155,16 +140,6 @@ ALWAYS_INLINE internal::pool_handle GetNormalBucketPool() {
} // namespace internal
#if !defined(PA_HAS_64_BITS_POINTERS)
ALWAYS_INLINE bool IsManagedByPartitionAllocDirectMap(const void* address) {
return internal::AddressPoolManager::IsManagedByDirectMapPool(address);
}
ALWAYS_INLINE bool IsManagedByPartitionAllocNormalBuckets(const void* address) {
return internal::AddressPoolManager::IsManagedByNormalBucketPool(address);
}
#endif
} // namespace base
#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_ADDRESS_POOL_MANAGER_H_
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/allocator/partition_allocator/address_pool_manager_bitmap.h"
#include "base/allocator/partition_allocator/partition_alloc_constants.h"
#include "base/lazy_instance.h"
#if !defined(PA_HAS_64_BITS_POINTERS)
namespace base {
namespace internal {
namespace {
LazyInstance<Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER;
} // namespace
Lock& AddressPoolManagerBitmap::GetLock() {
return g_lock.Get();
}
std::bitset<AddressPoolManagerBitmap::kDirectMapBits>
AddressPoolManagerBitmap::directmap_bits_; // GUARDED_BY(GetLock())
std::bitset<AddressPoolManagerBitmap::kNormalBucketBits>
AddressPoolManagerBitmap::normal_bucket_bits_; // GUARDED_BY(GetLock())
} // namespace internal
} // namespace base
#endif // !defined(PA_HAS_64_BITS_POINTERS)
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_ADDRESS_POOL_MANAGER_BITMAP_H_
#define BASE_ALLOCATOR_PARTITION_ALLOCATOR_ADDRESS_POOL_MANAGER_BITMAP_H_
#include <bitset>
#include "base/allocator/partition_allocator/partition_alloc_constants.h"
#include "base/synchronization/lock.h"
#if !defined(PA_HAS_64_BITS_POINTERS)
namespace base {
namespace internal {
// AddressPoolManagerBitmap is the bitmap that tracks whether a given address is
// managed by the direct map or normal buckets.
class BASE_EXPORT AddressPoolManagerBitmap {
public:
static constexpr uint64_t kGiB = 1024 * 1024 * 1024ull;
static constexpr uint64_t kAddressSpaceSize = 4ull * kGiB;
static constexpr size_t kNormalBucketBits =
kAddressSpaceSize / kSuperPageSize;
static constexpr size_t kDirectMapBits =
kAddressSpaceSize / PageAllocationGranularity();
static bool IsManagedByDirectMapPool(const void* address) {
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
// It is safe to read |directmap_bits_| without a lock since the caller is
// responsible for guaranteeing that the address is inside a valid
// allocation and the deallocation call won't race with this call.
return TS_UNCHECKED_READ(directmap_bits_)
.test(address_as_uintptr / PageAllocationGranularity());
}
static bool IsManagedByNormalBucketPool(const void* address) {
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
// It is safe to read |normal_bucket_bits_| without a lock since the caller
// is responsible for guaranteeing that the address is inside a valid
// allocation and the deallocation call won't race with this call.
return TS_UNCHECKED_READ(normal_bucket_bits_)
.test(address_as_uintptr >> kSuperPageShift);
}
private:
friend class AddressPoolManager;
static Lock& GetLock();
static std::bitset<kDirectMapBits> directmap_bits_ GUARDED_BY(GetLock());
static std::bitset<kNormalBucketBits> normal_bucket_bits_
GUARDED_BY(GetLock());
};
} // namespace internal
ALWAYS_INLINE bool IsManagedByPartitionAllocDirectMap(const void* address) {
return internal::AddressPoolManagerBitmap::IsManagedByDirectMapPool(address);
}
ALWAYS_INLINE bool IsManagedByPartitionAllocNormalBuckets(const void* address) {
return internal::AddressPoolManagerBitmap::IsManagedByNormalBucketPool(
address);
}
} // namespace base
#endif // !defined(PA_HAS_64_BITS_POINTERS)
#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_ADDRESS_POOL_MANAGER_BITMAP_H_
......@@ -10,6 +10,7 @@
#include <utility>
#include "base/allocator/partition_allocator/address_pool_manager_bitmap.h"
#include "base/allocator/partition_allocator/checked_ptr_support.h"
#include "base/allocator/partition_allocator/partition_address_space.h"
#include "base/allocator/partition_allocator/partition_alloc_forward.h"
......
......@@ -39,6 +39,7 @@ android_webview/public/
# Exclude dependences of checked_ptr.h
base/logging.h
base/synchronization/lock_impl.h
# Exclude code that only runs inside a renderer process - renderer
# processes are excluded for now from the MiraclePtr project scope,
......
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