chromium/base/memory/safety_checks_unittest.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 "base/memory/safety_checks.h"

#include <new>

#include "base/allocator/partition_alloc_features.h"
#include "base/feature_list.h"
#include "partition_alloc/partition_address_space.h"
#include "partition_alloc/tagging.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {
is_memory_safety_checked;
MemorySafetyCheck;

// Normal object: should be targeted by no additional |MemorySafetyCheck|.
struct DefaultChecks {};

// Annotated object: should have |base::internal::kAdvancedMemorySafetyChecks|.
struct AdvancedChecks {};

// Annotated object: should have |base::internal::kAdvancedMemorySafetyChecks|.
struct AnotherAdvancedChecks {};

// Annotated and aligned object for testing aligned allocations.
constexpr int kLargeAlignment =;
struct alignas(kLargeAlignment) AlignedAdvancedChecks {};

struct PrivateInheritanceWithInheritMacro : private AdvancedChecks {};
static_assert;

struct PrivateInheritanceWithDefaultMacro : private AdvancedChecks {};
static_assert;

struct MultipleInheritanceWithInheritMacro : AdvancedChecks,
                                             AnotherAdvancedChecks {};
static_assert;

struct MultipleInheritanceWithDefaultMacro : AdvancedChecks,
                                             AnotherAdvancedChecks {};
static_assert;

struct AdvancedChecksWithPartialOverwrite {};
static_assert;

struct InheritanceWithPartialOverwrite : private AdvancedChecks {};
static_assert;

// The macro may hook memory allocation/deallocation but should forward the
// request to PA or any other allocator via
// |HandleMemorySafetyCheckedOperator***|.
TEST(MemorySafetyCheckTest, AllocatorFunctions) {}

#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)

TEST(MemorySafetyCheckTest, SchedulerLoopQuarantine) {}

TEST(MemorySafetyCheckTest, ZapOnFree) {}

#endif  // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)

}  // namespace