Commit 998997d0 authored by Bartek Nowierski's avatar Bartek Nowierski Committed by Commit Bot

Make AlignedAllocations test use aligned root

This is a continuation of crrev.com/c/2275886. If PA-Everywhere and
tagging for CheckedPtr were to be enabled, this test would've failed.
By switching to aligned root, we're making it pass in all situations.

Bug: 1092288, 998048
Change-Id: Ib638818cc1e433c937c3c6fd375a492f5b3b22ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2282837
Commit-Queue: Bartek Nowierski <bartekn@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786170}
parent ea3b2bde
......@@ -900,6 +900,19 @@ ALWAYS_INLINE size_t PartitionRoot<thread_safe>::ActualSize(size_t size) {
#endif
}
enum class PartitionAllocatorAlignment {
// By default all allocations will be aligned to 8B (16B if
// BUILDFLAG_INTERNAL_USE_PARTITION_ALLOC_AS_MALLOC is true).
kRegular,
// In addition to the above alignment enforcement, this option allows using
// AlignedAlloc() which can align at a larger boundary.
// This option comes at a cost of disallowing cookies on Debug builds and tags
// for CheckedPtr. It also causes all allocations to go outside of GigaCage,
// so that CheckedPtr can easily tell if a pointer comes with a tag or not.
kAlignedAlloc,
};
namespace internal {
template <bool thread_safe>
struct BASE_EXPORT PartitionAllocator {
......@@ -909,8 +922,9 @@ struct BASE_EXPORT PartitionAllocator {
&partition_root_);
}
void init() {
partition_root_.Init(true);
void init(PartitionAllocatorAlignment alignment =
PartitionAllocatorAlignment::kRegular) {
partition_root_.Init(alignment == PartitionAllocatorAlignment::kRegular);
PartitionAllocMemoryReclaimer::Instance()->RegisterPartition(
&partition_root_);
}
......
......@@ -150,7 +150,8 @@ class PartitionAllocTest : public testing::Test {
void SetUp() override {
scoped_feature_list.InitWithFeatures({kPartitionAllocGigaCage}, {});
PartitionAllocGlobalInit(HandleOOM);
allocator.init();
allocator.init(PartitionAllocatorAlignment::kRegular);
aligned_allocator.init(PartitionAllocatorAlignment::kAlignedAlloc);
test_bucket_index_ = SizeToIndex(kRealAllocSize);
}
......@@ -290,6 +291,7 @@ class PartitionAllocTest : public testing::Test {
base::test::ScopedFeatureList scoped_feature_list;
PartitionAllocator<base::internal::ThreadSafe> allocator;
PartitionAllocator<base::internal::ThreadSafe> aligned_allocator;
size_t test_bucket_index_;
};
......@@ -2448,7 +2450,7 @@ TEST_F(PartitionAllocTest, AlignedAllocations) {
for (size_t alloc_size : alloc_sizes) {
for (size_t alignment : alignemnts) {
void* ptr = allocator.root()->AlignedAlloc(alignment, alloc_size);
void* ptr = aligned_allocator.root()->AlignedAlloc(alignment, alloc_size);
ASSERT_TRUE(ptr);
EXPECT_EQ(reinterpret_cast<uintptr_t>(ptr) % alignment, 0ull);
allocator.root()->Free(ptr);
......
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