[PA] Make InitConfigurablePool use uintptr_t
For consistency with the rest of the file...
Bug: 1280844
Change-Id: Ie950619d7a9a6e02c037f51a70d5deec9d910443
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3396398
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Bartek Nowierski <bartekn@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960973}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
8c294d307b
commit
87b9a0eeda
base/allocator/partition_allocator
gin
@ -5,6 +5,7 @@
|
||||
#include "base/allocator/partition_allocator/partition_address_space.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <ostream>
|
||||
|
||||
#include "base/allocator/partition_allocator/address_pool_manager.h"
|
||||
@ -123,21 +124,21 @@ void PartitionAddressSpace::Init() {
|
||||
#endif // PA_STARSCAN_USE_CARD_TABLE
|
||||
}
|
||||
|
||||
// TODO(bartekn): Consider void* -> uintptr_t
|
||||
void PartitionAddressSpace::InitConfigurablePool(void* address, size_t size) {
|
||||
void PartitionAddressSpace::InitConfigurablePool(uintptr_t pool_base,
|
||||
size_t size) {
|
||||
// The ConfigurablePool must only be initialized once.
|
||||
PA_CHECK(!IsConfigurablePoolInitialized());
|
||||
|
||||
// The other Pools must be initialized first.
|
||||
Init();
|
||||
|
||||
PA_CHECK(address);
|
||||
PA_CHECK(pool_base);
|
||||
PA_CHECK(size <= kConfigurablePoolMaxSize);
|
||||
PA_CHECK(size >= kConfigurablePoolMinSize);
|
||||
PA_CHECK(bits::IsPowerOfTwo(size));
|
||||
PA_CHECK(reinterpret_cast<uintptr_t>(address) % size == 0);
|
||||
PA_CHECK(pool_base % size == 0);
|
||||
|
||||
setup_.configurable_pool_base_address_ = reinterpret_cast<uintptr_t>(address);
|
||||
setup_.configurable_pool_base_address_ = pool_base;
|
||||
setup_.configurable_pool_base_mask_ = ~(size - 1);
|
||||
|
||||
setup_.configurable_pool_ = internal::AddressPoolManager::GetInstance()->Add(
|
||||
|
@ -89,11 +89,11 @@ class BASE_EXPORT PartitionAddressSpace {
|
||||
// Initialize the GigaCage and the Pools inside of it.
|
||||
// This function must only be called from the main thread.
|
||||
static void Init();
|
||||
// Initialize the ConfigurablePool at the given address. The address must be
|
||||
// aligned to the size of the pool. The size must be a power of two and must
|
||||
// be within [ConfigurablePoolMinSize(), ConfigurablePoolMaxSize()]. This
|
||||
// Initialize the ConfigurablePool at the given address |pool_base|. It must
|
||||
// be aligned to the size of the pool. The size must be a power of two and
|
||||
// must be within [ConfigurablePoolMinSize(), ConfigurablePoolMaxSize()]. This
|
||||
// function must only be called from the main thread.
|
||||
static void InitConfigurablePool(void* address, size_t size);
|
||||
static void InitConfigurablePool(uintptr_t pool_base, size_t size);
|
||||
static void UninitForTesting();
|
||||
static void UninitConfigurablePoolForTesting();
|
||||
|
||||
|
@ -3754,7 +3754,8 @@ TEST_F(PartitionAllocTest, ConfigurablePool) {
|
||||
void* pool_memory = AllocPages(nullptr, pool_size, pool_size,
|
||||
PageInaccessible, PageTag::kPartitionAlloc);
|
||||
EXPECT_NE(nullptr, pool_memory);
|
||||
PartitionAddressSpace::InitConfigurablePool(pool_memory, pool_size);
|
||||
uintptr_t pool_base = reinterpret_cast<uintptr_t>(pool_memory);
|
||||
PartitionAddressSpace::InitConfigurablePool(pool_base, pool_size);
|
||||
|
||||
EXPECT_TRUE(IsConfigurablePoolAvailable());
|
||||
|
||||
@ -3770,7 +3771,6 @@ TEST_F(PartitionAllocTest, ConfigurablePool) {
|
||||
|
||||
const size_t count = 250;
|
||||
std::vector<void*> allocations(count, nullptr);
|
||||
uintptr_t pool_base = reinterpret_cast<uintptr_t>(pool_memory);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const size_t size = kTestSizes[base::RandGenerator(kTestSizesCount)];
|
||||
allocations[i] = root->Alloc(size, nullptr);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "base/allocator/partition_allocator/page_allocator.h"
|
||||
@ -446,10 +447,10 @@ void V8Initializer::Initialize(IsolateHolder::ScriptMode mode,
|
||||
#endif
|
||||
// Try to reserve the maximum size of the pool at first, then keep halving
|
||||
// the size on failure until it succeeds.
|
||||
void* pool_base = nullptr;
|
||||
uintptr_t pool_base = 0;
|
||||
while (!pool_base && pool_size >= min_pool_size) {
|
||||
pool_base = reinterpret_cast<void*>(sandbox_address_space->AllocatePages(
|
||||
0, pool_size, pool_size, v8::PagePermissions::kNoAccess));
|
||||
pool_base = sandbox_address_space->AllocatePages(
|
||||
0, pool_size, pool_size, v8::PagePermissions::kNoAccess);
|
||||
if (!pool_base) {
|
||||
pool_size /= 2;
|
||||
}
|
||||
|
Reference in New Issue
Block a user