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