sanitizer_platform.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //===-- sanitizer_platform.h ------------------------------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // Common platform macros.
  9. //===----------------------------------------------------------------------===//
  10. #ifndef SANITIZER_PLATFORM_H
  11. #define SANITIZER_PLATFORM_H
  12. #if !defined(__linux__) && !defined(__FreeBSD__) && \
  13. !defined(__APPLE__) && !defined(_WIN32)
  14. # error "This operating system is not supported"
  15. #endif
  16. #if defined(__linux__)
  17. # define SANITIZER_LINUX 1
  18. #else
  19. # define SANITIZER_LINUX 0
  20. #endif
  21. #if defined(__FreeBSD__)
  22. # define SANITIZER_FREEBSD 1
  23. #else
  24. # define SANITIZER_FREEBSD 0
  25. #endif
  26. #if defined(__APPLE__)
  27. # define SANITIZER_MAC 1
  28. # include <TargetConditionals.h>
  29. # if TARGET_OS_IPHONE
  30. # define SANITIZER_IOS 1
  31. # else
  32. # define SANITIZER_IOS 0
  33. # endif
  34. #else
  35. # define SANITIZER_MAC 0
  36. # define SANITIZER_IOS 0
  37. #endif
  38. #if defined(_WIN32)
  39. # define SANITIZER_WINDOWS 1
  40. #else
  41. # define SANITIZER_WINDOWS 0
  42. #endif
  43. #if defined(__ANDROID__)
  44. # define SANITIZER_ANDROID 1
  45. #else
  46. # define SANITIZER_ANDROID 0
  47. #endif
  48. #define SANITIZER_POSIX (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC)
  49. #if __LP64__ || defined(_WIN64)
  50. # define SANITIZER_WORDSIZE 64
  51. #else
  52. # define SANITIZER_WORDSIZE 32
  53. #endif
  54. #if SANITIZER_WORDSIZE == 64
  55. # define FIRST_32_SECOND_64(a, b) (b)
  56. #else
  57. # define FIRST_32_SECOND_64(a, b) (a)
  58. #endif
  59. #if defined(__x86_64__) && !defined(_LP64)
  60. # define SANITIZER_X32 1
  61. #else
  62. # define SANITIZER_X32 0
  63. #endif
  64. // By default we allow to use SizeClassAllocator64 on 64-bit platform.
  65. // But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64
  66. // does not work well and we need to fallback to SizeClassAllocator32.
  67. // For such platforms build this code with -DSANITIZER_CAN_USE_ALLOCATOR64=0 or
  68. // change the definition of SANITIZER_CAN_USE_ALLOCATOR64 here.
  69. #ifndef SANITIZER_CAN_USE_ALLOCATOR64
  70. # if defined(__aarch64__) || defined(__mips64)
  71. # define SANITIZER_CAN_USE_ALLOCATOR64 0
  72. # else
  73. # define SANITIZER_CAN_USE_ALLOCATOR64 (SANITIZER_WORDSIZE == 64)
  74. # endif
  75. #endif
  76. // The range of addresses which can be returned my mmap.
  77. // FIXME: this value should be different on different platforms,
  78. // e.g. on AArch64 it is most likely (1ULL << 39). Larger values will still work
  79. // but will consume more memory for TwoLevelByteMap.
  80. #if defined(__aarch64__)
  81. # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 39)
  82. #else
  83. # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
  84. #endif
  85. // The AArch64 linux port uses the canonical syscall set as mandated by
  86. // the upstream linux community for all new ports. Other ports may still
  87. // use legacy syscalls.
  88. #ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
  89. # if defined(__aarch64__) && SANITIZER_LINUX
  90. # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
  91. # else
  92. # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0
  93. # endif
  94. #endif
  95. // udi16 syscalls can only be used when the following conditions are
  96. // met:
  97. // * target is one of arm32, x86-32, sparc32, sh or m68k
  98. // * libc version is libc5, glibc-2.0, glibc-2.1 or glibc-2.2 to 2.15
  99. // built against > linux-2.2 kernel headers
  100. // Since we don't want to include libc headers here, we check the
  101. // target only.
  102. #if defined(__arm__) || SANITIZER_X32 || defined(__sparc__)
  103. #define SANITIZER_USES_UID16_SYSCALLS 1
  104. #else
  105. #define SANITIZER_USES_UID16_SYSCALLS 0
  106. #endif
  107. #ifdef __mips__
  108. # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 10)
  109. #else
  110. # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
  111. #endif
  112. // Assume obsolete RPC headers are available by default
  113. #if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
  114. # define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
  115. # define HAVE_TIRPC_RPC_XDR_H 0
  116. #endif
  117. #endif // SANITIZER_PLATFORM_H