Commit a5264871 authored by Bartek Nowierski's avatar Bartek Nowierski Committed by Commit Bot

[PartitionAlloc] Better guard PartitionAllocGetSlotOffset tests

If GigaCage is disabled, PartitionAllocGetSlotOffset() triggers a DCHECK
which checks if the pointer is in the GigaCage's normal bucket pool.

Change-Id: I9ea2683944ee308b9055a2c182e7bb5387c5fc1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2534992
Commit-Queue: Bartek Nowierski <bartekn@chromium.org>
Commit-Queue: Kentaro Hara <haraken@chromium.org>
Auto-Submit: Bartek Nowierski <bartekn@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826784}
parent cc89d61c
...@@ -871,9 +871,11 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) { ...@@ -871,9 +871,11 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) {
EXPECT_EQ(predicted_size, actual_size); EXPECT_EQ(predicted_size, actual_size);
EXPECT_LT(requested_size, actual_size); EXPECT_LT(requested_size, actual_size);
#if defined(PA_HAS_64_BITS_POINTERS) #if defined(PA_HAS_64_BITS_POINTERS)
for (size_t offset = 0; offset < requested_size; ++offset) { if (features::IsPartitionAllocGigaCageEnabled()) {
EXPECT_EQ(PartitionAllocGetSlotOffset(static_cast<char*>(ptr) + offset), for (size_t offset = 0; offset < requested_size; ++offset) {
offset); EXPECT_EQ(PartitionAllocGetSlotOffset(static_cast<char*>(ptr) + offset),
offset);
}
} }
#endif #endif
allocator.root()->Free(ptr); allocator.root()->Free(ptr);
...@@ -888,9 +890,11 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) { ...@@ -888,9 +890,11 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) {
EXPECT_EQ(predicted_size, actual_size); EXPECT_EQ(predicted_size, actual_size);
EXPECT_EQ(requested_size, actual_size); EXPECT_EQ(requested_size, actual_size);
#if defined(PA_HAS_64_BITS_POINTERS) #if defined(PA_HAS_64_BITS_POINTERS)
for (size_t offset = 0; offset < requested_size; offset += 877) { if (features::IsPartitionAllocGigaCageEnabled()) {
EXPECT_EQ(PartitionAllocGetSlotOffset(static_cast<char*>(ptr) + offset), for (size_t offset = 0; offset < requested_size; offset += 877) {
offset); EXPECT_EQ(PartitionAllocGetSlotOffset(static_cast<char*>(ptr) + offset),
offset);
}
} }
#endif #endif
allocator.root()->Free(ptr); allocator.root()->Free(ptr);
...@@ -909,9 +913,11 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) { ...@@ -909,9 +913,11 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) {
EXPECT_EQ(predicted_size, actual_size); EXPECT_EQ(predicted_size, actual_size);
EXPECT_EQ(requested_size + SystemPageSize(), actual_size); EXPECT_EQ(requested_size + SystemPageSize(), actual_size);
#if defined(PA_HAS_64_BITS_POINTERS) #if defined(PA_HAS_64_BITS_POINTERS)
for (size_t offset = 0; offset < requested_size; offset += 4999) { if (features::IsPartitionAllocGigaCageEnabled()) {
EXPECT_EQ(PartitionAllocGetSlotOffset(static_cast<char*>(ptr) + offset), for (size_t offset = 0; offset < requested_size; offset += 4999) {
offset); EXPECT_EQ(PartitionAllocGetSlotOffset(static_cast<char*>(ptr) + offset),
offset);
}
} }
#endif #endif
...@@ -923,10 +929,12 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) { ...@@ -923,10 +929,12 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) {
actual_size = allocator.root()->GetSize(ptr); actual_size = allocator.root()->GetSize(ptr);
EXPECT_EQ(predicted_size, actual_size); EXPECT_EQ(predicted_size, actual_size);
EXPECT_EQ(requested_size, actual_size); EXPECT_EQ(requested_size, actual_size);
#if defined(ARCH_CPU_64_BITS) && !defined(OS_NACL) #if defined(PA_HAS_64_BITS_POINTERS)
for (size_t offset = 0; offset < requested_size; offset += 4999) { if (features::IsPartitionAllocGigaCageEnabled()) {
EXPECT_EQ(PartitionAllocGetSlotOffset(static_cast<char*>(ptr) + offset), for (size_t offset = 0; offset < requested_size; offset += 4999) {
offset); EXPECT_EQ(PartitionAllocGetSlotOffset(static_cast<char*>(ptr) + offset),
offset);
}
} }
#endif #endif
...@@ -958,6 +966,9 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) { ...@@ -958,6 +966,9 @@ TEST_F(PartitionAllocTest, AllocGetSizeAndOffset) {
#if defined(PA_HAS_64_BITS_POINTERS) #if defined(PA_HAS_64_BITS_POINTERS)
TEST_F(PartitionAllocTest, GetOffsetMultiplePages) { TEST_F(PartitionAllocTest, GetOffsetMultiplePages) {
if (!features::IsPartitionAllocGigaCageEnabled())
return;
const size_t real_size = 80; const size_t real_size = 80;
const size_t requested_size = real_size - kExtraAllocSize; const size_t requested_size = real_size - kExtraAllocSize;
// Double check we don't end up with 0 or negative size. // Double check we don't end up with 0 or negative size.
......
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