chromium/base/allocator/partition_allocator/src/partition_alloc/partition_freelist_entry.h

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PARTITION_ALLOC_PARTITION_FREELIST_ENTRY_H_
#define PARTITION_ALLOC_PARTITION_FREELIST_ENTRY_H_

#include <cstddef>

#include "partition_alloc/buildflags.h"
#include "partition_alloc/partition_alloc_base/bits.h"
#include "partition_alloc/partition_alloc_base/compiler_specific.h"
#include "partition_alloc/partition_alloc_base/component_export.h"
#include "partition_alloc/partition_alloc_constants.h"

namespace partition_allocinternal  // namespace partition_alloc::internal

#include "partition_alloc/encoded_next_freelist.h"  // IWYU pragma: export

// PA defaults to a freelist whose "next" links are encoded pointers.
// We are assessing an alternate implementation using an alternate
// encoding (pool offsets). When build support is enabled, the
// freelist implementation is determined at runtime.
#if PA_BUILDFLAG(USE_FREELIST_DISPATCHER)
#include "partition_alloc/pool_offset_freelist.h"  // IWYU pragma: export
#endif

namespace partition_alloc::internal {

// Assertions that are agnostic to the implementation of the freelist.

static_assert;
#if PA_BUILDFLAG(USE_FREELIST_DISPATCHER)
static_assert;
#endif

enum class PartitionFreelistEncoding {};

#if PA_BUILDFLAG(USE_FREELIST_DISPATCHER)
PartitionFreelistEntry;
#else
using PartitionFreelistEntry = EncodedNextFreelistEntry;
#endif  // PA_BUILDFLAG(USE_FREELIST_DISPATCHER)

#if PA_BUILDFLAG(USE_FREELIST_DISPATCHER)
static_assert;
static_assert;
#endif

struct PartitionFreelistDispatcher {};

#if PA_BUILDFLAG(USE_FREELIST_DISPATCHER)
template <PartitionFreelistEncoding encoding>
struct PartitionFreelistDispatcherImpl final : PartitionFreelistDispatcher {};

// Both dispatchers are constexpr
// 1. to avoid "declaration requires an exit-time destructor" error
//    e.g. on android-cronet-mainline-clang-arm64-dbg.
// 2. to not create re-entrancy issues with Windows CRT
//    (crbug.com/336007395).
inline static constexpr PartitionFreelistDispatcherImpl<
    PartitionFreelistEncoding::kEncodedFreeList>
    kEncodedImplDispatcher{};
inline static constexpr PartitionFreelistDispatcherImpl<
    PartitionFreelistEncoding::kPoolOffsetFreeList>
    kPoolOffsetImplDispatcher{};

PA_ALWAYS_INLINE const PartitionFreelistDispatcher*
PartitionFreelistDispatcher::Create(PartitionFreelistEncoding encoding) {}

#endif  // PA_BUILDFLAG(USE_FREELIST_DISPATCHER)

}  // namespace partition_alloc::internal

#endif  // PARTITION_ALLOC_PARTITION_FREELIST_ENTRY_H_