Path: blob/main/contrib/llvm-project/compiler-rt/lib/asan/asan_mapping_sparc64.h
35233 views
//===-- asan_mapping_sparc64.h ----------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of AddressSanitizer, an address sanity checker.9//10// SPARC64-specific definitions for ASan memory mapping.11//===----------------------------------------------------------------------===//12#ifndef ASAN_MAPPING_SPARC64_H13#define ASAN_MAPPING_SPARC64_H1415// 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 part17// has all the bits above the 51st cleared, while the high part has them set.18// 0xfff8000000000000 - 0xffffffffffffffff19// 0x0000000000000000 - 0x0007ffffffffffff2021#define VMA_BITS 5222#define HIGH_BITS (64 - VMA_BITS)2324// The idea is to chop the high bits before doing the scaling, so the two25// parts become contiguous again and the usual scheme can be applied.2627#define MEM_TO_SHADOW(mem) \28((((mem) << HIGH_BITS) >> (HIGH_BITS + (ASAN_SHADOW_SCALE))) + \29(ASAN_SHADOW_OFFSET))30#define SHADOW_TO_MEM(ptr) (__asan::ShadowToMemSparc64(ptr))3132#define kLowMemBeg 033#define kLowMemEnd (ASAN_SHADOW_OFFSET - 1)3435#define kLowShadowBeg ASAN_SHADOW_OFFSET36#define kLowShadowEnd MEM_TO_SHADOW(kLowMemEnd)3738// 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.4041#define kHighMemBeg (-(1ULL << (VMA_BITS - 1)))4243#define kHighShadowBeg MEM_TO_SHADOW(kHighMemBeg)44#define kHighShadowEnd MEM_TO_SHADOW(kHighMemEnd)4546#define kMidShadowBeg 047#define kMidShadowEnd 04849// With the zero shadow base we can not actually map pages starting from 0.50// This constant is somewhat arbitrary.51#define kZeroBaseShadowStart 052#define kZeroBaseMaxShadowStart (1 << 18)5354#define kShadowGapBeg (kLowShadowEnd + 1)55#define kShadowGapEnd (kHighShadowBeg - 1)5657#define kShadowGap2Beg 058#define kShadowGap2End 05960#define kShadowGap3Beg 061#define kShadowGap3End 06263namespace __asan {6465static inline bool AddrIsInLowMem(uptr a) {66PROFILE_ASAN_MAPPING();67return a <= kLowMemEnd;68}6970static inline bool AddrIsInLowShadow(uptr a) {71PROFILE_ASAN_MAPPING();72return a >= kLowShadowBeg && a <= kLowShadowEnd;73}7475static inline bool AddrIsInMidMem(uptr a) {76PROFILE_ASAN_MAPPING();77return false;78}7980static inline bool AddrIsInMidShadow(uptr a) {81PROFILE_ASAN_MAPPING();82return false;83}8485static inline bool AddrIsInHighMem(uptr a) {86PROFILE_ASAN_MAPPING();87return kHighMemBeg && a >= kHighMemBeg && a <= kHighMemEnd;88}8990static inline bool AddrIsInHighShadow(uptr a) {91PROFILE_ASAN_MAPPING();92return kHighMemBeg && a >= kHighShadowBeg && a <= kHighShadowEnd;93}9495static inline bool AddrIsInShadowGap(uptr a) {96PROFILE_ASAN_MAPPING();97return a >= kShadowGapBeg && a <= kShadowGapEnd;98}99100static inline constexpr uptr ShadowToMemSparc64(uptr p) {101PROFILE_ASAN_MAPPING();102p -= ASAN_SHADOW_OFFSET;103p <<= ASAN_SHADOW_SCALE;104if (p >= 0x8000000000000) {105p |= (~0ULL) << VMA_BITS;106}107return p;108}109110static_assert(ShadowToMemSparc64(MEM_TO_SHADOW(0x0000000000000000)) ==1110x0000000000000000);112static_assert(ShadowToMemSparc64(MEM_TO_SHADOW(0xfff8000000000000)) ==1130xfff8000000000000);114// Gets aligned down.115static_assert(ShadowToMemSparc64(MEM_TO_SHADOW(0x0007ffffffffffff)) ==1160x0007fffffffffff8);117118} // namespace __asan119120#endif // ASAN_MAPPING_SPARC64_H121122123