Skip to content

Commit 77e5e50

Browse files
tasakChromium LUCI CQ
authored andcommitted
[PartitionAlloc] Add partition_alloc_notreached.h.
When PartitionAlloc is used as the default allocator, we cannot use the regular (D)CHECK() macros, as they allocate internally. (c.f. //base/allocator/partition_allocator/partition_alloc_check.h) So PA_NOTREACHED() uses PA_DCHECK() instead of DCHECK(). Change-Id: I95fc01bfa7af0f79b1eafd62f4711efe0ff5de84 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3141323 Reviewed-by: Daniel Cheng <[email protected]> Reviewed-by: Benoit L <[email protected]> Reviewed-by: Bartek Nowierski <[email protected]> Reviewed-by: Kentaro Hara <[email protected]> Commit-Queue: Takashi Sakamoto <[email protected]> Cr-Commit-Position: refs/heads/main@{#919171}
1 parent cf7d905 commit 77e5e50

12 files changed

+49
-17
lines changed

base/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,7 @@ component("base") {
18921892
"allocator/partition_allocator/partition_alloc_forward.h",
18931893
"allocator/partition_allocator/partition_alloc_hooks.cc",
18941894
"allocator/partition_allocator/partition_alloc_hooks.h",
1895+
"allocator/partition_allocator/partition_alloc_notreached.h",
18951896
"allocator/partition_allocator/partition_bucket.cc",
18961897
"allocator/partition_allocator/partition_bucket.h",
18971898
"allocator/partition_allocator/partition_bucket_lookup.h",

base/allocator/partition_allocator/DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ include_rules = [
2525
"+base/lazy_instance.h",
2626
"+base/location.h",
2727
"+base/logging.h",
28+
"+base/logging_buildflags.h",
2829
"+base/mac/foundation_util.h",
2930
"+base/mac/mac_util.h",
3031
"+base/mac/scoped_cftyperef.h",
@@ -33,7 +34,6 @@ include_rules = [
3334
"+base/memory/tagging.h",
3435
"+base/metrics/histogram_functions.h",
3536
"+base/no_destructor.h",
36-
"+base/notreached.h",
3737
"+base/numerics/ranges.h",
3838
"+base/posix/eintr_wrapper.h",
3939
"+base/process/memory.h",

base/allocator/partition_allocator/address_pool_manager.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#include "base/allocator/partition_allocator/page_allocator_internal.h"
1818
#include "base/allocator/partition_allocator/partition_alloc_check.h"
1919
#include "base/allocator/partition_allocator/partition_alloc_constants.h"
20+
#include "base/allocator/partition_allocator/partition_alloc_notreached.h"
2021
#include "base/allocator/partition_allocator/reservation_offset_table.h"
2122
#include "base/cxx17_backports.h"
2223
#include "base/lazy_instance.h"
23-
#include "base/notreached.h"
2424

2525
namespace base {
2626
namespace internal {
@@ -61,7 +61,7 @@ pool_handle AddressPoolManager::Add(uintptr_t ptr, size_t length) {
6161
return i + 1;
6262
}
6363
}
64-
NOTREACHED();
64+
PA_NOTREACHED();
6565
return 0;
6666
}
6767

@@ -206,7 +206,7 @@ uintptr_t AddressPoolManager::Pool::FindChunk(size_t requested_size) {
206206
}
207207
}
208208

209-
NOTREACHED();
209+
PA_NOTREACHED();
210210
return 0;
211211
}
212212

base/allocator/partition_allocator/page_allocator_internals_fuchsia.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
#include "base/allocator/partition_allocator/page_allocator.h"
1919
#include "base/allocator/partition_allocator/partition_alloc_check.h"
20+
#include "base/allocator/partition_allocator/partition_alloc_notreached.h"
2021
#include "base/fuchsia/fuchsia_logging.h"
21-
#include "base/notreached.h"
2222

2323
namespace base {
2424

@@ -55,7 +55,7 @@ zx_vm_option_t PageAccessibilityToZxVmOptions(
5555
case PageReadWriteExecute:
5656
return ZX_VM_PERM_READ | ZX_VM_PERM_WRITE | ZX_VM_PERM_EXECUTE;
5757
default:
58-
NOTREACHED();
58+
PA_NOTREACHED();
5959
FALLTHROUGH;
6060
case PageInaccessible:
6161
return 0;

base/allocator/partition_allocator/page_allocator_internals_posix.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// found in the LICENSE file.
44

55
#include "base/allocator/partition_allocator/page_allocator.h"
6+
#include "base/allocator/partition_allocator/partition_alloc_notreached.h"
67
#include "base/cpu.h"
7-
#include "base/notreached.h"
88

99
#include <sys/mman.h>
1010

@@ -52,7 +52,7 @@ int GetAccessFlags(PageAccessibilityConfiguration accessibility) {
5252
case PageReadWriteExecute:
5353
return PROT_READ | PROT_WRITE | PROT_EXEC;
5454
default:
55-
NOTREACHED();
55+
PA_NOTREACHED();
5656
FALLTHROUGH;
5757
case PageInaccessible:
5858
return PROT_NONE;

base/allocator/partition_allocator/page_allocator_internals_win.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "base/allocator/partition_allocator/oom.h"
99
#include "base/allocator/partition_allocator/page_allocator_internal.h"
1010
#include "base/allocator/partition_allocator/partition_alloc_check.h"
11-
#include "base/notreached.h"
11+
#include "base/allocator/partition_allocator/partition_alloc_notreached.h"
1212

1313
namespace base {
1414

@@ -29,7 +29,7 @@ int GetAccessFlags(PageAccessibilityConfiguration accessibility) {
2929
case PageReadWriteExecute:
3030
return PAGE_EXECUTE_READWRITE;
3131
default:
32-
NOTREACHED();
32+
PA_NOTREACHED();
3333
FALLTHROUGH;
3434
case PageInaccessible:
3535
return PAGE_NOACCESS;

base/allocator/partition_allocator/page_allocator_unittest.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include "base/cpu.h"
1414
#include "base/logging.h"
1515
#include "base/memory/tagging.h"
16-
#include "base/notreached.h"
1716

1817
#include "base/allocator/partition_allocator/address_space_randomization.h"
18+
#include "base/allocator/partition_allocator/partition_alloc_notreached.h"
1919
#include "build/build_config.h"
2020
#if defined(OS_ANDROID)
2121
#include "base/debug/proc_maps_linux.h"
@@ -242,7 +242,7 @@ TEST(PartitionAllocPageAllocatorTest,
242242
""); // Should crash with SIGILL.
243243
FreePages(buffer, PageAllocationGranularity());
244244
#else
245-
NOTREACHED();
245+
PA_NOTREACHED();
246246
#endif
247247
}
248248

@@ -298,7 +298,7 @@ TEST(PartitionAllocPageAllocatorTest,
298298
parent_tagging_mode);
299299
FreePages(buffer, PageAllocationGranularity());
300300
#else
301-
NOTREACHED();
301+
PA_NOTREACHED();
302302
#endif
303303
}
304304

@@ -351,7 +351,7 @@ TEST(PartitionAllocPageAllocatorTest,
351351
EXPECT_EQ(memory::GetMemoryTaggingModeForCurrentThread(),
352352
parent_tagging_mode);
353353
#else
354-
NOTREACHED();
354+
PA_NOTREACHED();
355355
#endif
356356
}
357357

base/allocator/partition_allocator/partition_address_space.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#include "base/allocator/partition_allocator/partition_alloc_config.h"
1616
#include "base/allocator/partition_allocator/partition_alloc_constants.h"
1717
#include "base/allocator/partition_allocator/partition_alloc_forward.h"
18+
#include "base/allocator/partition_allocator/partition_alloc_notreached.h"
1819
#include "base/base_export.h"
1920
#include "base/bits.h"
2021
#include "base/compiler_specific.h"
21-
#include "base/notreached.h"
2222
#include "build/build_config.h"
2323
#include "build/buildflag.h"
2424

@@ -102,7 +102,7 @@ class BASE_EXPORT PartitionAddressSpace {
102102
base = brp_pool_base_address_;
103103
#endif // BUILDFLAG(USE_BACKUP_REF_PTR)
104104
} else {
105-
NOTREACHED();
105+
PA_NOTREACHED();
106106
}
107107
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
108108
return std::make_pair(pool, address_as_uintptr - base);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2021 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_NOTREACHED_H_
6+
#define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_NOTREACHED_H_
7+
8+
#include "base/allocator/partition_allocator/partition_alloc_check.h"
9+
#include "base/logging_buildflags.h"
10+
11+
// When PartitionAlloc is used as the default allocator, we cannot use the
12+
// regular (D)CHECK() macros, as they allocate internally. (c.f. //
13+
// base/allocator/partition_allocator/partition_alloc_check.h)
14+
// So PA_NOTREACHED() uses PA_DCHECK() instead of DCHECK().
15+
16+
#if BUILDFLAG(ENABLE_LOG_ERROR_NOT_REACHED)
17+
#define PA_NOTREACHED() \
18+
true ? logging::RawError(__FILE__ \
19+
"(" PA_STRINGIFY(__LINE__) ") NOTREACHED() hit.") \
20+
: EAT_CHECK_STREAM_PARAMS()
21+
#else
22+
#define PA_NOTREACHED() PA_DCHECK(false)
23+
#endif
24+
25+
#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_NOTREACHED_H_

base/allocator/partition_allocator/partition_root.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "base/allocator/partition_allocator/partition_alloc_features.h"
4646
#include "base/allocator/partition_allocator/partition_alloc_forward.h"
4747
#include "base/allocator/partition_allocator/partition_alloc_hooks.h"
48+
#include "base/allocator/partition_allocator/partition_alloc_notreached.h"
4849
#include "base/allocator/partition_allocator/partition_bucket_lookup.h"
4950
#include "base/allocator/partition_allocator/partition_direct_map_extent.h"
5051
#include "base/allocator/partition_allocator/partition_lock.h"
@@ -1590,7 +1591,7 @@ ALWAYS_INLINE void* PartitionRoot<thread_safe>::AlignedAllocFlags(
15901591
// PartitionExcessiveAllocationSize).
15911592
internal::PartitionExcessiveAllocationSize(requested_size);
15921593
// internal::PartitionExcessiveAllocationSize(size) causes OOM_CRASH.
1593-
NOTREACHED();
1594+
PA_NOTREACHED();
15941595
}
15951596
}
15961597

0 commit comments

Comments
 (0)