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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef SCUDO_PLATFORM_H_ 10 #define SCUDO_PLATFORM_H_ 11 12 #if defined(__linux__) 13 #define SCUDO_LINUX 1 14 #else 15 #define SCUDO_LINUX 0 16 #endif 17 18 #if defined(__ANDROID__) 19 #define SCUDO_ANDROID 1 20 #else 21 #define SCUDO_ANDROID 0 22 #endif 23 24 #if defined(__Fuchsia__) 25 #define SCUDO_FUCHSIA 1 26 #else 27 #define SCUDO_FUCHSIA 0 28 #endif 29 30 #if __LP64__ 31 #define SCUDO_WORDSIZE 64U 32 #else 33 #define SCUDO_WORDSIZE 32U 34 #endif 35 36 #if SCUDO_WORDSIZE == 64U 37 #define FIRST_32_SECOND_64(a, b) (b) 38 #else 39 #define FIRST_32_SECOND_64(a, b) (a) 40 #endif 41 42 #ifndef SCUDO_CAN_USE_PRIMARY64 43 #define SCUDO_CAN_USE_PRIMARY64 (SCUDO_WORDSIZE == 64U) 44 #endif 45 46 #ifndef SCUDO_MIN_ALIGNMENT_LOG 47 // We force malloc-type functions to be aligned to std::max_align_t, but there 48 // is no reason why the minimum alignment for all other functions can't be 8 49 // bytes. Except obviously for applications making incorrect assumptions. 50 // TODO(kostyak): define SCUDO_MIN_ALIGNMENT_LOG 3 51 #define SCUDO_MIN_ALIGNMENT_LOG FIRST_32_SECOND_64(3, 4) 52 #endif 53 54 #if defined(__aarch64__) 55 #define SCUDO_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 48) 56 #else 57 #define SCUDO_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47) 58 #endif 59 60 // Older gcc have issues aligning to a constexpr, and require an integer. 61 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56859 among others. 62 #if defined(__powerpc__) || defined(__powerpc64__) 63 #define SCUDO_CACHE_LINE_SIZE 128 64 #else 65 #define SCUDO_CACHE_LINE_SIZE 64 66 #endif 67 68 #define SCUDO_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12) 69 70 #endif // SCUDO_PLATFORM_H_ 71