• 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_FREELIST_ENTRY_H_
6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_PARTITION_FREELIST_ENTRY_H_
7 
8 #include <cstddef>
9 
10 #include "partition_alloc/partition_alloc_base/bits.h"
11 #include "partition_alloc/partition_alloc_base/compiler_specific.h"
12 #include "partition_alloc/partition_alloc_base/component_export.h"
13 #include "partition_alloc/partition_alloc_buildflags.h"
14 #include "partition_alloc/partition_alloc_constants.h"
15 
16 namespace partition_alloc::internal {
17 
18 [[noreturn]] PA_NOINLINE PA_COMPONENT_EXPORT(
19     PARTITION_ALLOC) void FreelistCorruptionDetected(size_t slot_size);
20 
21 }  // namespace partition_alloc::internal
22 
23 #if BUILDFLAG(USE_FREELIST_POOL_OFFSETS)
24 #include "partition_alloc/pool_offset_freelist.h"  // IWYU pragma: export
25 #else
26 #include "partition_alloc/encoded_next_freelist.h"  // IWYU pragma: export
27 #endif  // BUILDFLAG(USE_FREELIST_POOL_OFFSETS)
28 
29 namespace partition_alloc::internal {
30 
31 // Assertions that are agnostic to the implementation of the freelist.
32 
33 static_assert(kSmallestBucket >= sizeof(EncodedNextFreelistEntry),
34               "Need enough space for freelist entries in the smallest slot");
35 
36 #if BUILDFLAG(PUT_REF_COUNT_IN_PREVIOUS_SLOT)
37 // The smallest bucket actually used. Note that the smallest request is 1 (if
38 // it's 0, it gets patched to 1), and ref-count gets added to it.
39 namespace {
40 constexpr size_t kSmallestUsedBucket =
41     base::bits::AlignUp(1 + sizeof(PartitionRefCount), kSmallestBucket);
42 }
43 static_assert(kSmallestUsedBucket >=
44                   sizeof(EncodedNextFreelistEntry) + sizeof(PartitionRefCount),
45               "Need enough space for freelist entries and the ref-count in the "
46               "smallest *used* slot");
47 #endif  // BUILDFLAG(PUT_REF_COUNT_IN_PREVIOUS_SLOT)
48 
49 }  // namespace partition_alloc::internal
50 
51 #endif  // BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_PARTITION_FREELIST_ENTRY_H_
52