Path: blob/main/contrib/llvm-project/compiler-rt/lib/tysan/tysan_platform.h
213766 views
//===------------------------ tysan_platform.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 TypeSanitizer.9//10// Platform specific information for TySan.11//===----------------------------------------------------------------------===//1213#ifndef TYSAN_PLATFORM_H14#define TYSAN_PLATFORM_H1516namespace __tysan {1718#if defined(__x86_64__) || SANITIZER_APPLE19struct Mapping {20static const uptr kShadowAddr = 0x010000000000ull;21static const uptr kAppAddr = 0x550000000000ull;22static const uptr kAppMemMsk = ~0x780000000000ull;23};24#elif defined(__aarch64__)25struct Mapping39 {26static const uptr kShadowAddr = 0x0800000000ull;27static const uptr kAppAddr = 0x5500000000ull;28static const uptr kAppMemMsk = ~0x7800000000ull;29};3031struct Mapping42 {32static const uptr kShadowAddr = 0x10000000000ull;33static const uptr kAppAddr = 0x2aa00000000ull;34static const uptr kAppMemMsk = ~0x3c000000000ull;35};3637struct Mapping48 {38static const uptr kShadowAddr = 0x0002000000000ull;39static const uptr kAppAddr = 0x0aaaa00000000ull;40static const uptr kAppMemMsk = ~0x0fff800000000ull;41};42#define TYSAN_RUNTIME_VMA 143#else44#error "TySan not supported for this platform!"45#endif4647#if TYSAN_RUNTIME_VMA48extern int vmaSize;49#endif5051enum MappingType { MAPPING_SHADOW_ADDR, MAPPING_APP_ADDR, MAPPING_APP_MASK };5253template <typename Mapping, int Type> uptr MappingImpl(void) {54switch (Type) {55case MAPPING_SHADOW_ADDR:56return Mapping::kShadowAddr;57case MAPPING_APP_ADDR:58return Mapping::kAppAddr;59case MAPPING_APP_MASK:60return Mapping::kAppMemMsk;61}62}6364template <int Type> uptr MappingArchImpl(void) {65#if defined(__aarch64__) && !SANITIZER_APPLE66switch (vmaSize) {67case 39:68return MappingImpl<Mapping39, Type>();69case 42:70return MappingImpl<Mapping42, Type>();71case 48:72return MappingImpl<Mapping48, Type>();73}74DCHECK(0);75return 0;76#else77return MappingImpl<Mapping, Type>();78#endif79}8081ALWAYS_INLINE82uptr ShadowAddr() { return MappingArchImpl<MAPPING_SHADOW_ADDR>(); }8384ALWAYS_INLINE85uptr AppAddr() { return MappingArchImpl<MAPPING_APP_ADDR>(); }8687ALWAYS_INLINE88uptr AppMask() { return MappingArchImpl<MAPPING_APP_MASK>(); }8990} // namespace __tysan9192#endif939495