#include "partition_alloc/page_allocator.h"
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include "partition_alloc/address_space_randomization.h"
#include "partition_alloc/build_config.h"
#include "partition_alloc/buildflags.h"
#include "partition_alloc/page_allocator_constants.h"
#include "partition_alloc/partition_alloc_base/cpu.h"
#include "partition_alloc/partition_alloc_base/logging.h"
#include "partition_alloc/partition_alloc_base/notreached.h"
#include "partition_alloc/partition_alloc_config.h"
#include "partition_alloc/tagging.h"
#if defined(LINUX_NAME_REGION)
#include "partition_alloc/partition_alloc_base/debug/proc_maps_linux.h"
#endif
#include "testing/gtest/include/gtest/gtest.h"
#if PA_BUILDFLAG(IS_POSIX)
#include <sys/mman.h>
#include <sys/time.h>
#include <csetjmp>
#include <csignal>
#endif
#include "partition_alloc/arm_bti_test_functions.h"
#if PA_BUILDFLAG(HAS_MEMORY_TAGGING)
#include <arm_acle.h>
#if PA_BUILDFLAG(IS_ANDROID) || PA_BUILDFLAG(IS_LINUX)
#define MTE_KILLED_BY_SIGNAL_AVAILABLE
#endif
#endif
#if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
namespace partition_alloc::internal {
namespace {
size_t EasyAllocSize() { … }
size_t HugeMemoryAmount() { … }
}
TEST(PartitionAllocPageAllocatorTest, Rounding) { … }
TEST(PartitionAllocPageAllocatorTest, NextAlignedWithOffset) { … }
TEST(PartitionAllocPageAllocatorTest, AllocFailure) { … }
#if PA_BUILDFLAG(IS_WIN) && PA_BUILDFLAG(PA_ARCH_CPU_64_BITS)
#define MAYBE_ReserveAddressSpace …
#else
#define MAYBE_ReserveAddressSpace …
#endif
TEST(PartitionAllocPageAllocatorTest, MAYBE_ReserveAddressSpace) { … }
TEST(PartitionAllocPageAllocatorTest, AllocAndFreePages) { … }
TEST(PartitionAllocPageAllocatorTest, AllocPagesAligned) { … }
TEST(PartitionAllocPageAllocatorTest,
AllocAndFreePagesWithPageReadWriteTagged) { … }
TEST(PartitionAllocPageAllocatorTest,
AllocAndFreePagesWithPageReadExecuteConfirmCFI) { … }
TEST(PartitionAllocPageAllocatorTest,
AllocAndFreePagesWithPageReadWriteTaggedSynchronous) { … }
TEST(PartitionAllocPageAllocatorTest,
AllocAndFreePagesWithPageReadWriteTaggedAsynchronous) { … }
#if PA_BUILDFLAG(IS_POSIX)
namespace {
sigjmp_buf g_continuation;
void SignalHandler(int signal, siginfo_t* info, void*) { … }
}
#if PA_BUILDFLAG(IS_APPLE)
#define EXTRA_FAULT_BEGIN_ACTION …
#define EXTRA_FAULT_END_ACTION …
#else
#define EXTRA_FAULT_BEGIN_ACTION() …
#define EXTRA_FAULT_END_ACTION() …
#endif
#define FAULT_TEST_BEGIN() …
#define FAULT_TEST_END() …
TEST(PartitionAllocPageAllocatorTest, InaccessiblePages) { … }
#if PA_BUILDFLAG(IS_IOS)
#define MAYBE_ReadExecutePages …
#else
#define MAYBE_ReadExecutePages …
#endif
TEST(PartitionAllocPageAllocatorTest, MAYBE_ReadExecutePages) { … }
#endif
#if defined(LINUX_NAME_REGION)
TEST(PartitionAllocPageAllocatorTest, PageTagging) { … }
#endif
TEST(PartitionAllocPageAllocatorTest, DecommitErasesMemory) { … }
TEST(PartitionAllocPageAllocatorTest, DecommitAndZero) { … }
TEST(PartitionAllocPageAllocatorTest, MappedPagesAccounting) { … }
TEST(PartitionAllocPageAllocatorTest, AllocInaccessibleWillJitLater) { … }
#if PA_BUILDFLAG(IS_IOS) || PA_BUILDFLAG(IS_MAC)
#define MAYBE_AllocReadWriteExecute …
#else
#define MAYBE_AllocReadWriteExecute …
#endif
TEST(PartitionAllocPageAllocatorTest, MAYBE_AllocReadWriteExecute) { … }
}
#endif