100 lines · c
1//===-- platform.h ----------------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef SCUDO_PLATFORM_H_10#define SCUDO_PLATFORM_H_11 12// Transitive includes of stdint.h specify some of the defines checked below.13#include <stdint.h>14 15#if defined(__linux__) && !defined(__TRUSTY__)16#define SCUDO_LINUX 117#else18#define SCUDO_LINUX 019#endif20 21// See https://android.googlesource.com/platform/bionic/+/master/docs/defines.md22#if defined(__BIONIC__)23#define SCUDO_ANDROID 124// Transitive includes of unistd.h will get PAGE_SIZE if it is defined.25#include <unistd.h>26#if defined(PAGE_SIZE)27#define SCUDO_PAGE_SIZE PAGE_SIZE28#endif29#else30#define SCUDO_ANDROID 031#endif32 33#if defined(__Fuchsia__)34#define SCUDO_FUCHSIA 135#else36#define SCUDO_FUCHSIA 037#endif38 39#if defined(__TRUSTY__)40#define SCUDO_TRUSTY 141#else42#define SCUDO_TRUSTY 043#endif44 45#if defined(__riscv) && (__riscv_xlen == 64)46#define SCUDO_RISCV64 147#else48#define SCUDO_RISCV64 049#endif50 51#if defined(__LP64__)52#define SCUDO_WORDSIZE 64U53#else54#define SCUDO_WORDSIZE 32U55#endif56 57#if SCUDO_WORDSIZE == 64U58#define FIRST_32_SECOND_64(a, b) (b)59#else60#define FIRST_32_SECOND_64(a, b) (a)61#endif62 63#ifndef SCUDO_CAN_USE_PRIMARY6464#define SCUDO_CAN_USE_PRIMARY64 (SCUDO_WORDSIZE == 64U)65#endif66 67#ifndef SCUDO_CAN_USE_MTE68#define SCUDO_CAN_USE_MTE (SCUDO_LINUX || SCUDO_TRUSTY)69#endif70 71#ifndef SCUDO_ENABLE_HOOKS72#define SCUDO_ENABLE_HOOKS 073#endif74 75#ifndef SCUDO_MIN_ALIGNMENT_LOG76// We force malloc-type functions to be aligned to std::max_align_t, but there77// is no reason why the minimum alignment for all other functions can't be 878// bytes. Except obviously for applications making incorrect assumptions.79// TODO(kostyak): define SCUDO_MIN_ALIGNMENT_LOG 380#define SCUDO_MIN_ALIGNMENT_LOG FIRST_32_SECOND_64(3, 4)81#endif82 83#if defined(__aarch64__)84#define SCUDO_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 48)85#else86#define SCUDO_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)87#endif88 89// Older gcc have issues aligning to a constexpr, and require an integer.90// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56859 among others.91#if defined(__powerpc__) || defined(__powerpc64__)92#define SCUDO_CACHE_LINE_SIZE 12893#else94#define SCUDO_CACHE_LINE_SIZE 6495#endif96 97#define SCUDO_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)98 99#endif // SCUDO_PLATFORM_H_100