Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/compiler-rt/lib/tysan/tysan_platform.h
213766 views
1
//===------------------------ tysan_platform.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 TypeSanitizer.
10
//
11
// Platform specific information for TySan.
12
//===----------------------------------------------------------------------===//
13
14
#ifndef TYSAN_PLATFORM_H
15
#define TYSAN_PLATFORM_H
16
17
namespace __tysan {
18
19
#if defined(__x86_64__) || SANITIZER_APPLE
20
struct Mapping {
21
static const uptr kShadowAddr = 0x010000000000ull;
22
static const uptr kAppAddr = 0x550000000000ull;
23
static const uptr kAppMemMsk = ~0x780000000000ull;
24
};
25
#elif defined(__aarch64__)
26
struct Mapping39 {
27
static const uptr kShadowAddr = 0x0800000000ull;
28
static const uptr kAppAddr = 0x5500000000ull;
29
static const uptr kAppMemMsk = ~0x7800000000ull;
30
};
31
32
struct Mapping42 {
33
static const uptr kShadowAddr = 0x10000000000ull;
34
static const uptr kAppAddr = 0x2aa00000000ull;
35
static const uptr kAppMemMsk = ~0x3c000000000ull;
36
};
37
38
struct Mapping48 {
39
static const uptr kShadowAddr = 0x0002000000000ull;
40
static const uptr kAppAddr = 0x0aaaa00000000ull;
41
static const uptr kAppMemMsk = ~0x0fff800000000ull;
42
};
43
#define TYSAN_RUNTIME_VMA 1
44
#else
45
#error "TySan not supported for this platform!"
46
#endif
47
48
#if TYSAN_RUNTIME_VMA
49
extern int vmaSize;
50
#endif
51
52
enum MappingType { MAPPING_SHADOW_ADDR, MAPPING_APP_ADDR, MAPPING_APP_MASK };
53
54
template <typename Mapping, int Type> uptr MappingImpl(void) {
55
switch (Type) {
56
case MAPPING_SHADOW_ADDR:
57
return Mapping::kShadowAddr;
58
case MAPPING_APP_ADDR:
59
return Mapping::kAppAddr;
60
case MAPPING_APP_MASK:
61
return Mapping::kAppMemMsk;
62
}
63
}
64
65
template <int Type> uptr MappingArchImpl(void) {
66
#if defined(__aarch64__) && !SANITIZER_APPLE
67
switch (vmaSize) {
68
case 39:
69
return MappingImpl<Mapping39, Type>();
70
case 42:
71
return MappingImpl<Mapping42, Type>();
72
case 48:
73
return MappingImpl<Mapping48, Type>();
74
}
75
DCHECK(0);
76
return 0;
77
#else
78
return MappingImpl<Mapping, Type>();
79
#endif
80
}
81
82
ALWAYS_INLINE
83
uptr ShadowAddr() { return MappingArchImpl<MAPPING_SHADOW_ADDR>(); }
84
85
ALWAYS_INLINE
86
uptr AppAddr() { return MappingArchImpl<MAPPING_APP_ADDR>(); }
87
88
ALWAYS_INLINE
89
uptr AppMask() { return MappingArchImpl<MAPPING_APP_MASK>(); }
90
91
} // namespace __tysan
92
93
#endif
94
95