|
| 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 + (SHADOW_SCALE))) + (SHADOW_OFFSET)) |
| 30 | + |
| 31 | +#define kLowMemBeg 0 |
| 32 | +#define kLowMemEnd (SHADOW_OFFSET - 1) |
| 33 | + |
| 34 | +#define kLowShadowBeg SHADOW_OFFSET |
| 35 | +#define kLowShadowEnd MEM_TO_SHADOW(kLowMemEnd) |
| 36 | + |
| 37 | +// But of course there is the huge hole between the high shadow memory, |
| 38 | +// which is in the low part, and the beginning of the high part. |
| 39 | + |
| 40 | +#define kHighMemBeg (-(1ULL << (VMA_BITS - 1))) |
| 41 | + |
| 42 | +#define kHighShadowBeg MEM_TO_SHADOW(kHighMemBeg) |
| 43 | +#define kHighShadowEnd MEM_TO_SHADOW(kHighMemEnd) |
| 44 | + |
| 45 | +#define kMidShadowBeg 0 |
| 46 | +#define kMidShadowEnd 0 |
| 47 | + |
| 48 | +// With the zero shadow base we can not actually map pages starting from 0. |
| 49 | +// This constant is somewhat arbitrary. |
| 50 | +#define kZeroBaseShadowStart 0 |
| 51 | +#define kZeroBaseMaxShadowStart (1 << 18) |
| 52 | + |
| 53 | +#define kShadowGapBeg (kLowShadowEnd + 1) |
| 54 | +#define kShadowGapEnd (kHighShadowBeg - 1) |
| 55 | + |
| 56 | +#define kShadowGap2Beg 0 |
| 57 | +#define kShadowGap2End 0 |
| 58 | + |
| 59 | +#define kShadowGap3Beg 0 |
| 60 | +#define kShadowGap3End 0 |
| 61 | + |
| 62 | +namespace __asan { |
| 63 | + |
| 64 | +static inline bool AddrIsInLowMem(uptr a) { |
| 65 | + PROFILE_ASAN_MAPPING(); |
| 66 | + return a <= kLowMemEnd; |
| 67 | +} |
| 68 | + |
| 69 | +static inline bool AddrIsInLowShadow(uptr a) { |
| 70 | + PROFILE_ASAN_MAPPING(); |
| 71 | + return a >= kLowShadowBeg && a <= kLowShadowEnd; |
| 72 | +} |
| 73 | + |
| 74 | +static inline bool AddrIsInMidMem(uptr a) { |
| 75 | + PROFILE_ASAN_MAPPING(); |
| 76 | + return false; |
| 77 | +} |
| 78 | + |
| 79 | +static inline bool AddrIsInMidShadow(uptr a) { |
| 80 | + PROFILE_ASAN_MAPPING(); |
| 81 | + return false; |
| 82 | +} |
| 83 | + |
| 84 | +static inline bool AddrIsInHighMem(uptr a) { |
| 85 | + PROFILE_ASAN_MAPPING(); |
| 86 | + return kHighMemBeg && a >= kHighMemBeg && a <= kHighMemEnd; |
| 87 | +} |
| 88 | + |
| 89 | +static inline bool AddrIsInHighShadow(uptr a) { |
| 90 | + PROFILE_ASAN_MAPPING(); |
| 91 | + return kHighMemBeg && a >= kHighShadowBeg && a <= kHighShadowEnd; |
| 92 | +} |
| 93 | + |
| 94 | +static inline bool AddrIsInShadowGap(uptr a) { |
| 95 | + PROFILE_ASAN_MAPPING(); |
| 96 | + return a >= kShadowGapBeg && a <= kShadowGapEnd; |
| 97 | +} |
| 98 | + |
| 99 | +} // namespace __asan |
| 100 | + |
| 101 | +#endif // ASAN_MAPPING_SPARC64_H |
0 commit comments