• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Chromium Authors
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_SRC_PARTITION_ALLOC_PARTITION_DCHECK_HELPER_H_
6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_PARTITION_DCHECK_HELPER_H_
7 
8 #include "partition_alloc/partition_alloc_base/compiler_specific.h"
9 #include "partition_alloc/partition_alloc_base/component_export.h"
10 #include "partition_alloc/partition_alloc_forward.h"
11 #include "partition_alloc/partition_lock.h"
12 
13 namespace partition_alloc::internal {
14 
15 struct PartitionSuperPageExtentEntry;
16 
17 #if BUILDFLAG(PA_DCHECK_IS_ON)
18 
19 // To allow these asserts to have empty bodies in no-DCHECK() builds, while
20 // avoiding issues with circular includes.
21 #define PA_EMPTY_BODY_IF_DCHECK_IS_OFF()
22 // Export symbol if dcheck-is-on. Because the body is not empty.
23 #define PA_EXPORT_IF_DCHECK_IS_ON() PA_COMPONENT_EXPORT(PARTITION_ALLOC)
24 
25 #else  // BUILDFLAG(PA_DCHECK_IS_ON)
26 
27 // The static_assert() eats follow-on semicolons.
28 #define PA_EMPTY_BODY_IF_DCHECK_IS_OFF() \
29   {}                                     \
30   static_assert(true)
31 // inline if dcheck-is-off so it's no overhead.
32 #define PA_EXPORT_IF_DCHECK_IS_ON() PA_ALWAYS_INLINE
33 
34 #endif  // BUILDFLAG(PA_DCHECK_IS_ON)
35 
36 PA_EXPORT_IF_DCHECK_IS_ON()
37 void DCheckIsValidSlotSpan(internal::SlotSpanMetadata* slot_span)
38     PA_EMPTY_BODY_IF_DCHECK_IS_OFF();
39 
40 PA_EXPORT_IF_DCHECK_IS_ON()
41 void DCheckIsWithInSuperPagePayload(uintptr_t address)
42     PA_EMPTY_BODY_IF_DCHECK_IS_OFF();
43 
44 PA_EXPORT_IF_DCHECK_IS_ON()
45 void DCheckNumberOfPartitionPagesInSuperPagePayload(
46     const PartitionSuperPageExtentEntry* entry,
47     const PartitionRoot* root,
48     size_t number_of_nonempty_slot_spans) PA_EMPTY_BODY_IF_DCHECK_IS_OFF();
49 
50 PA_EXPORT_IF_DCHECK_IS_ON()
51 void DCheckIsValidShiftFromSlotStart(internal::SlotSpanMetadata* slot_span,
52                                      size_t shift_from_slot_start)
53     PA_EMPTY_BODY_IF_DCHECK_IS_OFF();
54 
55 // Checks that the object is exactly |extras_offset| away from a multiple of
56 // slot size (i.e. from a slot start).
57 PA_EXPORT_IF_DCHECK_IS_ON()
58 void DCheckIsValidObjectAddress(internal::SlotSpanMetadata* slot_span,
59                                 uintptr_t object_addr)
60     PA_EMPTY_BODY_IF_DCHECK_IS_OFF();
61 
62 PA_EXPORT_IF_DCHECK_IS_ON()
63 void DCheckRootLockIsAcquired(PartitionRoot* root)
64     PA_EMPTY_BODY_IF_DCHECK_IS_OFF();
65 
66 }  // namespace partition_alloc::internal
67 
68 #endif  // BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_PARTITION_DCHECK_HELPER_H_
69