asan_mapping_sparc64.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //===-- asan_mapping_sparc64.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. // This file is a part of AddressSanitizer, an address sanity checker.
  10. //
  11. // SPARC64-specific definitions for ASan memory mapping.
  12. //===----------------------------------------------------------------------===//
  13. #ifndef ASAN_MAPPING_SPARC64_H
  14. #define ASAN_MAPPING_SPARC64_H
  15. // This is tailored to the 52-bit VM layout on SPARC-T4 and later.
  16. // The VM space is split into two 51-bit halves at both ends: the low part
  17. // has all the bits above the 51st cleared, while the high part has them set.
  18. // 0xfff8000000000000 - 0xffffffffffffffff
  19. // 0x0000000000000000 - 0x0007ffffffffffff
  20. #define VMA_BITS 52
  21. #define HIGH_BITS (64 - VMA_BITS)
  22. // The idea is to chop the high bits before doing the scaling, so the two
  23. // parts become contiguous again and the usual scheme can be applied.
  24. #define MEM_TO_SHADOW(mem) \
  25. ((((mem) << HIGH_BITS) >> (HIGH_BITS + (ASAN_SHADOW_SCALE))) + \
  26. (ASAN_SHADOW_OFFSET))
  27. #define kLowMemBeg 0
  28. #define kLowMemEnd (ASAN_SHADOW_OFFSET - 1)
  29. #define kLowShadowBeg ASAN_SHADOW_OFFSET
  30. #define kLowShadowEnd MEM_TO_SHADOW(kLowMemEnd)
  31. // But of course there is the huge hole between the high shadow memory,
  32. // which is in the low part, and the beginning of the high part.
  33. #define kHighMemBeg (-(1ULL << (VMA_BITS - 1)))
  34. #define kHighShadowBeg MEM_TO_SHADOW(kHighMemBeg)
  35. #define kHighShadowEnd MEM_TO_SHADOW(kHighMemEnd)
  36. #define kMidShadowBeg 0
  37. #define kMidShadowEnd 0
  38. // With the zero shadow base we can not actually map pages starting from 0.
  39. // This constant is somewhat arbitrary.
  40. #define kZeroBaseShadowStart 0
  41. #define kZeroBaseMaxShadowStart (1 << 18)
  42. #define kShadowGapBeg (kLowShadowEnd + 1)
  43. #define kShadowGapEnd (kHighShadowBeg - 1)
  44. #define kShadowGap2Beg 0
  45. #define kShadowGap2End 0
  46. #define kShadowGap3Beg 0
  47. #define kShadowGap3End 0
  48. namespace __asan {
  49. static inline bool AddrIsInLowMem(uptr a) {
  50. PROFILE_ASAN_MAPPING();
  51. return a <= kLowMemEnd;
  52. }
  53. static inline bool AddrIsInLowShadow(uptr a) {
  54. PROFILE_ASAN_MAPPING();
  55. return a >= kLowShadowBeg && a <= kLowShadowEnd;
  56. }
  57. static inline bool AddrIsInMidMem(uptr a) {
  58. PROFILE_ASAN_MAPPING();
  59. return false;
  60. }
  61. static inline bool AddrIsInMidShadow(uptr a) {
  62. PROFILE_ASAN_MAPPING();
  63. return false;
  64. }
  65. static inline bool AddrIsInHighMem(uptr a) {
  66. PROFILE_ASAN_MAPPING();
  67. return kHighMemBeg && a >= kHighMemBeg && a <= kHighMemEnd;
  68. }
  69. static inline bool AddrIsInHighShadow(uptr a) {
  70. PROFILE_ASAN_MAPPING();
  71. return kHighMemBeg && a >= kHighShadowBeg && a <= kHighShadowEnd;
  72. }
  73. static inline bool AddrIsInShadowGap(uptr a) {
  74. PROFILE_ASAN_MAPPING();
  75. return a >= kShadowGapBeg && a <= kShadowGapEnd;
  76. }
  77. } // namespace __asan
  78. #endif // ASAN_MAPPING_SPARC64_H