scudo_platform.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //===-- scudo_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. /// Scudo platform specific definitions.
  10. /// TODO(kostyak): add tests for the compile time defines.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #ifndef SCUDO_PLATFORM_H_
  14. #define SCUDO_PLATFORM_H_
  15. #include "sanitizer_common/sanitizer_allocator.h"
  16. #if !SANITIZER_LINUX && !SANITIZER_FUCHSIA
  17. # error "The Scudo hardened allocator is not supported on this platform."
  18. #endif
  19. #define SCUDO_TSD_EXCLUSIVE_SUPPORTED (!SANITIZER_ANDROID && !SANITIZER_FUCHSIA)
  20. #ifndef SCUDO_TSD_EXCLUSIVE
  21. // SCUDO_TSD_EXCLUSIVE wasn't defined, use a default TSD model for the platform.
  22. # if SANITIZER_ANDROID || SANITIZER_FUCHSIA
  23. // Android and Fuchsia use a pool of TSDs shared between threads.
  24. # define SCUDO_TSD_EXCLUSIVE 0
  25. # elif SANITIZER_LINUX && !SANITIZER_ANDROID
  26. // Non-Android Linux use an exclusive TSD per thread.
  27. # define SCUDO_TSD_EXCLUSIVE 1
  28. # else
  29. # error "No default TSD model defined for this platform."
  30. # endif // SANITIZER_ANDROID || SANITIZER_FUCHSIA
  31. #endif // SCUDO_TSD_EXCLUSIVE
  32. // If the exclusive TSD model is chosen, make sure the platform supports it.
  33. #if SCUDO_TSD_EXCLUSIVE && !SCUDO_TSD_EXCLUSIVE_SUPPORTED
  34. # error "The exclusive TSD model is not supported on this platform."
  35. #endif
  36. // Maximum number of TSDs that can be created for the Shared model.
  37. #ifndef SCUDO_SHARED_TSD_POOL_SIZE
  38. # if SANITIZER_ANDROID
  39. # define SCUDO_SHARED_TSD_POOL_SIZE 2U
  40. # else
  41. # define SCUDO_SHARED_TSD_POOL_SIZE 32U
  42. # endif // SANITIZER_ANDROID
  43. #endif // SCUDO_SHARED_TSD_POOL_SIZE
  44. // The following allows the public interface functions to be disabled.
  45. #ifndef SCUDO_CAN_USE_PUBLIC_INTERFACE
  46. # define SCUDO_CAN_USE_PUBLIC_INTERFACE 1
  47. #endif
  48. // Hooks in the allocation & deallocation paths can become a security concern if
  49. // implemented improperly, or if overwritten by an attacker. Use with caution.
  50. #ifndef SCUDO_CAN_USE_HOOKS
  51. # if SANITIZER_FUCHSIA
  52. # define SCUDO_CAN_USE_HOOKS 1
  53. # else
  54. # define SCUDO_CAN_USE_HOOKS 0
  55. # endif // SANITIZER_FUCHSIA
  56. #endif // SCUDO_CAN_USE_HOOKS
  57. namespace __scudo {
  58. #if SANITIZER_CAN_USE_ALLOCATOR64
  59. # if defined(__aarch64__) && SANITIZER_ANDROID
  60. const uptr AllocatorSize = 0x4000000000ULL; // 256G.
  61. # elif defined(__aarch64__)
  62. const uptr AllocatorSize = 0x10000000000ULL; // 1T.
  63. # else
  64. const uptr AllocatorSize = 0x40000000000ULL; // 4T.
  65. # endif
  66. #else
  67. const uptr RegionSizeLog = SANITIZER_ANDROID ? 19 : 20;
  68. #endif // SANITIZER_CAN_USE_ALLOCATOR64
  69. #if !defined(SCUDO_SIZE_CLASS_MAP)
  70. # define SCUDO_SIZE_CLASS_MAP Dense
  71. #endif
  72. #define SIZE_CLASS_MAP_TYPE SIZE_CLASS_MAP_TYPE_(SCUDO_SIZE_CLASS_MAP)
  73. #define SIZE_CLASS_MAP_TYPE_(T) SIZE_CLASS_MAP_TYPE__(T)
  74. #define SIZE_CLASS_MAP_TYPE__(T) T##SizeClassMap
  75. typedef SIZE_CLASS_MAP_TYPE SizeClassMap;
  76. } // namespace __scudo
  77. #endif // SCUDO_PLATFORM_H_