chromium/base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/cpu.cc

// Copyright 2012 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/partition_alloc_base/cpu.h"

#include <algorithm>
#include <cinttypes>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <sstream>
#include <utility>

#include "partition_alloc/build_config.h"

#if PA_BUILDFLAG(PA_ARCH_CPU_ARM_FAMILY) &&                \
    (PA_BUILDFLAG(IS_ANDROID) || PA_BUILDFLAG(IS_LINUX) || \
     PA_BUILDFLAG(IS_CHROMEOS))
#include <asm/hwcap.h>
#include <sys/auxv.h>

// Temporary definitions until a new hwcap.h is pulled in everywhere.
// https://crbug.com/1265965
#if PA_BUILDFLAG(PA_ARCH_CPU_ARM64)
#ifndef HWCAP2_MTE
#define HWCAP2_MTE
#endif
#ifndef HWCAP2_BTI
#define HWCAP2_BTI
#endif
#endif  // PA_BUILDFLAG(PA_ARCH_CPU_ARM64)

#endif  // PA_BUILDFLAG(PA_ARCH_CPU_ARM_FAMILY) && (PA_BUILDFLAG(IS_ANDROID) ||
        // PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS))

#if PA_BUILDFLAG(PA_ARCH_CPU_X86_FAMILY)
#if PA_BUILDFLAG(PA_COMPILER_MSVC)
#include <immintrin.h>  // For _xgetbv()
#include <intrin.h>
#endif
#endif

namespace partition_alloc::internal::base {

CPU::CPU() {}
CPU::CPU(CPU&&) = default;

namespace {

#if PA_BUILDFLAG(PA_ARCH_CPU_X86_FAMILY)
#if !PA_BUILDFLAG(PA_COMPILER_MSVC)

#if defined(__pic__) && defined(__i386__)

void __cpuid(int cpu_info[4], int info_type) {
  __asm__ volatile(
      "mov %%ebx, %%edi\n"
      "cpuid\n"
      "xchg %%edi, %%ebx\n"
      : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]),
        "=d"(cpu_info[3])
      : "a"(info_type), "c"(0));
}

#else

void __cpuid(int cpu_info[4], int info_type) {}

#endif
#endif  // !PA_BUILDFLAG(PA_COMPILER_MSVC)

// xgetbv returns the value of an Intel Extended Control Register (XCR).
// Currently only XCR0 is defined by Intel so |xcr| should always be zero.
uint64_t xgetbv(uint32_t xcr) {}

#endif  // ARCH_CPU_X86_FAMILY

}  // namespace

void CPU::Initialize() {}

const CPU& CPU::GetInstanceNoAllocation() {}

}  // namespace partition_alloc::internal::base