181418a27Smrg //===-- asan_mapping_sparc64.h ----------------------------------*- C++ -*-===//
281418a27Smrg //
3*490215a3Smrg // This file is distributed under the University of Illinois Open Source
4*490215a3Smrg // License. See LICENSE.TXT for details
581418a27Smrg //
681418a27Smrg //===----------------------------------------------------------------------===//
781418a27Smrg //
881418a27Smrg // This file is a part of AddressSanitizer, an address sanity checker.
981418a27Smrg //
1081418a27Smrg // SPARC64-specific definitions for ASan memory mapping.
1181418a27Smrg //===----------------------------------------------------------------------===//
1281418a27Smrg #ifndef ASAN_MAPPING_SPARC64_H
1381418a27Smrg #define ASAN_MAPPING_SPARC64_H
1481418a27Smrg 
1581418a27Smrg // This is tailored to the 52-bit VM layout on SPARC-T4 and later.
1681418a27Smrg // The VM space is split into two 51-bit halves at both ends: the low part
1781418a27Smrg // has all the bits above the 51st cleared, while the high part has them set.
1881418a27Smrg //   0xfff8000000000000 - 0xffffffffffffffff
1981418a27Smrg //   0x0000000000000000 - 0x0007ffffffffffff
2081418a27Smrg 
2181418a27Smrg #define VMA_BITS 52
2281418a27Smrg #define HIGH_BITS (64 - VMA_BITS)
2381418a27Smrg 
2481418a27Smrg // The idea is to chop the high bits before doing the scaling, so the two
2581418a27Smrg // parts become contiguous again and the usual scheme can be applied.
2681418a27Smrg 
2781418a27Smrg #define MEM_TO_SHADOW(mem) \
2881418a27Smrg   ((((mem) << HIGH_BITS) >> (HIGH_BITS + (SHADOW_SCALE))) + (SHADOW_OFFSET))
2981418a27Smrg 
3081418a27Smrg #define kLowMemBeg 0
3181418a27Smrg #define kLowMemEnd (SHADOW_OFFSET - 1)
3281418a27Smrg 
3381418a27Smrg #define kLowShadowBeg SHADOW_OFFSET
3481418a27Smrg #define kLowShadowEnd MEM_TO_SHADOW(kLowMemEnd)
3581418a27Smrg 
3681418a27Smrg // But of course there is the huge hole between the high shadow memory,
3781418a27Smrg // which is in the low part, and the beginning of the high part.
3881418a27Smrg 
3981418a27Smrg #define kHighMemBeg (-(1ULL << (VMA_BITS - 1)))
4081418a27Smrg 
4181418a27Smrg #define kHighShadowBeg MEM_TO_SHADOW(kHighMemBeg)
4281418a27Smrg #define kHighShadowEnd MEM_TO_SHADOW(kHighMemEnd)
4381418a27Smrg 
4481418a27Smrg #define kMidShadowBeg 0
4581418a27Smrg #define kMidShadowEnd 0
4681418a27Smrg 
4781418a27Smrg // With the zero shadow base we can not actually map pages starting from 0.
4881418a27Smrg // This constant is somewhat arbitrary.
4981418a27Smrg #define kZeroBaseShadowStart 0
5081418a27Smrg #define kZeroBaseMaxShadowStart (1 << 18)
5181418a27Smrg 
5281418a27Smrg #define kShadowGapBeg (kLowShadowEnd + 1)
5381418a27Smrg #define kShadowGapEnd (kHighShadowBeg - 1)
5481418a27Smrg 
5581418a27Smrg #define kShadowGap2Beg 0
5681418a27Smrg #define kShadowGap2End 0
5781418a27Smrg 
5881418a27Smrg #define kShadowGap3Beg 0
5981418a27Smrg #define kShadowGap3End 0
6081418a27Smrg 
6181418a27Smrg namespace __asan {
6281418a27Smrg 
AddrIsInLowMem(uptr a)6381418a27Smrg static inline bool AddrIsInLowMem(uptr a) {
6481418a27Smrg   PROFILE_ASAN_MAPPING();
6581418a27Smrg   return a <= kLowMemEnd;
6681418a27Smrg }
6781418a27Smrg 
AddrIsInLowShadow(uptr a)6881418a27Smrg static inline bool AddrIsInLowShadow(uptr a) {
6981418a27Smrg   PROFILE_ASAN_MAPPING();
7081418a27Smrg   return a >= kLowShadowBeg && a <= kLowShadowEnd;
7181418a27Smrg }
7281418a27Smrg 
AddrIsInMidMem(uptr a)7381418a27Smrg static inline bool AddrIsInMidMem(uptr a) {
7481418a27Smrg   PROFILE_ASAN_MAPPING();
7581418a27Smrg   return false;
7681418a27Smrg }
7781418a27Smrg 
AddrIsInMidShadow(uptr a)7881418a27Smrg static inline bool AddrIsInMidShadow(uptr a) {
7981418a27Smrg   PROFILE_ASAN_MAPPING();
8081418a27Smrg   return false;
8181418a27Smrg }
8281418a27Smrg 
AddrIsInHighMem(uptr a)8381418a27Smrg static inline bool AddrIsInHighMem(uptr a) {
8481418a27Smrg   PROFILE_ASAN_MAPPING();
8581418a27Smrg   return kHighMemBeg && a >= kHighMemBeg && a <= kHighMemEnd;
8681418a27Smrg }
8781418a27Smrg 
AddrIsInHighShadow(uptr a)8881418a27Smrg static inline bool AddrIsInHighShadow(uptr a) {
8981418a27Smrg   PROFILE_ASAN_MAPPING();
9081418a27Smrg   return kHighMemBeg && a >= kHighShadowBeg && a <= kHighShadowEnd;
9181418a27Smrg }
9281418a27Smrg 
AddrIsInShadowGap(uptr a)9381418a27Smrg static inline bool AddrIsInShadowGap(uptr a) {
9481418a27Smrg   PROFILE_ASAN_MAPPING();
9581418a27Smrg   return a >= kShadowGapBeg && a <= kShadowGapEnd;
9681418a27Smrg }
9781418a27Smrg 
9881418a27Smrg }  // namespace __asan
9981418a27Smrg 
10081418a27Smrg #endif  // ASAN_MAPPING_SPARC64_H
101