platform.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #ifndef SCUDO_PLATFORM_H_
  9. #define SCUDO_PLATFORM_H_
  10. // Transitive includes of stdint.h specify some of the defines checked below.
  11. #include <stdint.h>
  12. #if defined(__linux__) && !defined(__TRUSTY__)
  13. #define SCUDO_LINUX 1
  14. #else
  15. #define SCUDO_LINUX 0
  16. #endif
  17. // See https://android.googlesource.com/platform/bionic/+/master/docs/defines.md
  18. #if defined(__BIONIC__)
  19. #define SCUDO_ANDROID 1
  20. #else
  21. #define SCUDO_ANDROID 0
  22. #endif
  23. #if defined(__Fuchsia__)
  24. #define SCUDO_FUCHSIA 1
  25. #else
  26. #define SCUDO_FUCHSIA 0
  27. #endif
  28. #if defined(__TRUSTY__)
  29. #define SCUDO_TRUSTY 1
  30. #else
  31. #define SCUDO_TRUSTY 0
  32. #endif
  33. #if defined(__riscv) && (__riscv_xlen == 64)
  34. #define SCUDO_RISCV64 1
  35. #else
  36. #define SCUDO_RISCV64 0
  37. #endif
  38. #if defined(__LP64__)
  39. #define SCUDO_WORDSIZE 64U
  40. #else
  41. #define SCUDO_WORDSIZE 32U
  42. #endif
  43. #if SCUDO_WORDSIZE == 64U
  44. #define FIRST_32_SECOND_64(a, b) (b)
  45. #else
  46. #define FIRST_32_SECOND_64(a, b) (a)
  47. #endif
  48. #ifndef SCUDO_CAN_USE_PRIMARY64
  49. #define SCUDO_CAN_USE_PRIMARY64 (SCUDO_WORDSIZE == 64U)
  50. #endif
  51. #ifndef SCUDO_CAN_USE_MTE
  52. #define SCUDO_CAN_USE_MTE (SCUDO_LINUX || SCUDO_TRUSTY)
  53. #endif
  54. // Use smaller table sizes for fuzzing in order to reduce input size.
  55. // Trusty just has less available memory.
  56. #ifndef SCUDO_SMALL_STACK_DEPOT
  57. #if defined(SCUDO_FUZZ) || SCUDO_TRUSTY
  58. #define SCUDO_SMALL_STACK_DEPOT 1
  59. #else
  60. #define SCUDO_SMALL_STACK_DEPOT 0
  61. #endif
  62. #endif
  63. #ifndef SCUDO_ENABLE_HOOKS
  64. #define SCUDO_ENABLE_HOOKS 0
  65. #endif
  66. #ifndef SCUDO_MIN_ALIGNMENT_LOG
  67. // We force malloc-type functions to be aligned to std::max_align_t, but there
  68. // is no reason why the minimum alignment for all other functions can't be 8
  69. // bytes. Except obviously for applications making incorrect assumptions.
  70. // TODO(kostyak): define SCUDO_MIN_ALIGNMENT_LOG 3
  71. #define SCUDO_MIN_ALIGNMENT_LOG FIRST_32_SECOND_64(3, 4)
  72. #endif
  73. #if defined(__aarch64__)
  74. #define SCUDO_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 48)
  75. #else
  76. #define SCUDO_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
  77. #endif
  78. // Older gcc have issues aligning to a constexpr, and require an integer.
  79. // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56859 among others.
  80. #if defined(__powerpc__) || defined(__powerpc64__)
  81. #define SCUDO_CACHE_LINE_SIZE 128
  82. #else
  83. #define SCUDO_CACHE_LINE_SIZE 64
  84. #endif
  85. #define SCUDO_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
  86. #endif // SCUDO_PLATFORM_H_