[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / dfsan / dfsan_platform.h
blob9b4333ee99d0ca1c7ad42aae432b369e44a6b2ef
1 //===-- dfsan_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 DataFlowSanitizer.
11 // Platform specific information for DFSan.
12 //===----------------------------------------------------------------------===//
14 #ifndef DFSAN_PLATFORM_H
15 #define DFSAN_PLATFORM_H
17 #include "sanitizer_common/sanitizer_common.h"
18 #include "sanitizer_common/sanitizer_platform.h"
20 namespace __dfsan {
22 using __sanitizer::uptr;
24 // TODO: The memory mapping code to setup a 1:1 shadow is based on msan.
25 // Consider refactoring these into a shared implementation.
27 struct MappingDesc {
28 uptr start;
29 uptr end;
30 enum Type { INVALID, APP, SHADOW, ORIGIN } type;
31 const char *name;
34 #if SANITIZER_LINUX && SANITIZER_WORDSIZE == 64
36 // All of the following configurations are supported.
37 // ASLR disabled: main executable and DSOs at 0x555550000000
38 // PIE and ASLR: main executable and DSOs at 0x7f0000000000
39 // non-PIE: main executable below 0x100000000, DSOs at 0x7f0000000000
40 // Heap at 0x700000000000.
41 const MappingDesc kMemoryLayout[] = {
42 {0x000000000000ULL, 0x010000000000ULL, MappingDesc::APP, "app-1"},
43 {0x010000000000ULL, 0x100000000000ULL, MappingDesc::SHADOW, "shadow-2"},
44 {0x100000000000ULL, 0x110000000000ULL, MappingDesc::INVALID, "invalid"},
45 {0x110000000000ULL, 0x200000000000ULL, MappingDesc::ORIGIN, "origin-2"},
46 {0x200000000000ULL, 0x300000000000ULL, MappingDesc::SHADOW, "shadow-3"},
47 {0x300000000000ULL, 0x400000000000ULL, MappingDesc::ORIGIN, "origin-3"},
48 {0x400000000000ULL, 0x500000000000ULL, MappingDesc::INVALID, "invalid"},
49 {0x500000000000ULL, 0x510000000000ULL, MappingDesc::SHADOW, "shadow-1"},
50 {0x510000000000ULL, 0x600000000000ULL, MappingDesc::APP, "app-2"},
51 {0x600000000000ULL, 0x610000000000ULL, MappingDesc::ORIGIN, "origin-1"},
52 {0x610000000000ULL, 0x700000000000ULL, MappingDesc::INVALID, "invalid"},
53 {0x700000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app-3"}};
54 # define MEM_TO_SHADOW(mem) (((uptr)(mem)) ^ 0x500000000000ULL)
55 # define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x100000000000ULL)
57 #else
58 # error "Unsupported platform"
59 #endif
61 const uptr kMemoryLayoutSize = sizeof(kMemoryLayout) / sizeof(kMemoryLayout[0]);
63 #define MEM_TO_ORIGIN(mem) (SHADOW_TO_ORIGIN(MEM_TO_SHADOW((mem))))
65 #ifndef __clang__
66 __attribute__((optimize("unroll-loops")))
67 #endif
68 inline bool
69 addr_is_type(uptr addr, MappingDesc::Type mapping_type) {
70 // It is critical for performance that this loop is unrolled (because then it is
71 // simplified into just a few constant comparisons).
72 #ifdef __clang__
73 # pragma unroll
74 #endif
75 for (unsigned i = 0; i < kMemoryLayoutSize; ++i)
76 if (kMemoryLayout[i].type == mapping_type &&
77 addr >= kMemoryLayout[i].start && addr < kMemoryLayout[i].end)
78 return true;
79 return false;
82 #define MEM_IS_APP(mem) addr_is_type((uptr)(mem), MappingDesc::APP)
83 #define MEM_IS_SHADOW(mem) addr_is_type((uptr)(mem), MappingDesc::SHADOW)
84 #define MEM_IS_ORIGIN(mem) addr_is_type((uptr)(mem), MappingDesc::ORIGIN)
86 } // namespace __dfsan
88 #endif