chromium/base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr_backup_ref_impl.cc

// 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.

#include "partition_alloc/pointers/raw_ptr_backup_ref_impl.h"

#include <cstdint>

#include "partition_alloc/buildflags.h"
#include "partition_alloc/dangling_raw_ptr_checks.h"
#include "partition_alloc/in_slot_metadata.h"
#include "partition_alloc/partition_alloc.h"
#include "partition_alloc/partition_alloc_base/check.h"
#include "partition_alloc/partition_root.h"
#include "partition_alloc/reservation_offset_table.h"

namespace base::internal {

template <bool AllowDangling, bool DisableBRP>
void RawPtrBackupRefImpl<AllowDangling, DisableBRP>::AcquireInternal(
    uintptr_t address) {}

template <bool AllowDangling, bool DisableBRP>
void RawPtrBackupRefImpl<AllowDangling, DisableBRP>::ReleaseInternal(
    uintptr_t address) {}

template <bool AllowDangling, bool DisableBRP>
void RawPtrBackupRefImpl<AllowDangling, DisableBRP>::ReportIfDanglingInternal(
    uintptr_t address) {}

// static
template <bool AllowDangling, bool DisableBRP>
bool RawPtrBackupRefImpl<AllowDangling, DisableBRP>::
    CheckPointerWithinSameAlloc(uintptr_t before_addr,
                                uintptr_t after_addr,
                                size_t type_size) {}

template <bool AllowDangling, bool DisableBRP>
bool RawPtrBackupRefImpl<AllowDangling, DisableBRP>::IsPointeeAlive(
    uintptr_t address) {}

// Explicitly instantiates the two BackupRefPtr variants in the .cc. This
// ensures the definitions not visible from the .h are available in the binary.
template struct RawPtrBackupRefImpl</*AllowDangling=*/false,
                                    /*DisableBRP=*/false>;
template struct RawPtrBackupRefImpl</*AllowDangling=*/false,
                                    /*DisableBRP=*/true>;
template struct RawPtrBackupRefImpl</*AllowDangling=*/true,
                                    /*DisableBRP=*/false>;
template struct RawPtrBackupRefImpl</*AllowDangling=*/true,
                                    /*DisableBRP=*/true>;

#if PA_BUILDFLAG(DCHECKS_ARE_ON) || \
    PA_BUILDFLAG(ENABLE_BACKUP_REF_PTR_SLOW_CHECKS)
void CheckThatAddressIsntWithinFirstPartitionPage(uintptr_t address) {}
#endif  // PA_BUILDFLAG(DCHECKS_ARE_ON) ||
        // PA_BUILDFLAG(ENABLE_BACKUP_REF_PTR_SLOW_CHECKS)

}  // namespace base::internal