[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / sanitizer_common / sanitizer_procmaps.h
blob055af366ef06e2f41b4ad9ac0cb227d8d838fb59
1 //===-- sanitizer_procmaps.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 shared between AddressSanitizer and ThreadSanitizer.
11 // Information about the process mappings.
12 //===----------------------------------------------------------------------===//
13 #ifndef SANITIZER_PROCMAPS_H
14 #define SANITIZER_PROCMAPS_H
16 #include "sanitizer_platform.h"
18 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
19 SANITIZER_MAC || SANITIZER_SOLARIS || \
20 SANITIZER_FUCHSIA
22 #include "sanitizer_common.h"
23 #include "sanitizer_internal_defs.h"
24 #include "sanitizer_fuchsia.h"
25 #include "sanitizer_linux.h"
26 #include "sanitizer_mac.h"
27 #include "sanitizer_mutex.h"
29 namespace __sanitizer {
31 // Memory protection masks.
32 static const uptr kProtectionRead = 1;
33 static const uptr kProtectionWrite = 2;
34 static const uptr kProtectionExecute = 4;
35 static const uptr kProtectionShared = 8;
37 struct MemoryMappedSegmentData;
39 class MemoryMappedSegment {
40 public:
41 explicit MemoryMappedSegment(char *buff = nullptr, uptr size = 0)
42 : filename(buff), filename_size(size), data_(nullptr) {}
43 ~MemoryMappedSegment() {}
45 bool IsReadable() const { return protection & kProtectionRead; }
46 bool IsWritable() const { return protection & kProtectionWrite; }
47 bool IsExecutable() const { return protection & kProtectionExecute; }
48 bool IsShared() const { return protection & kProtectionShared; }
50 void AddAddressRanges(LoadedModule *module);
52 uptr start;
53 uptr end;
54 uptr offset;
55 char *filename; // owned by caller
56 uptr filename_size;
57 uptr protection;
58 ModuleArch arch;
59 u8 uuid[kModuleUUIDSize];
61 private:
62 friend class MemoryMappingLayout;
64 // This field is assigned and owned by MemoryMappingLayout if needed
65 MemoryMappedSegmentData *data_;
68 class MemoryMappingLayoutBase {
69 public:
70 virtual bool Next(MemoryMappedSegment *segment) { UNIMPLEMENTED(); }
71 virtual bool Error() const { UNIMPLEMENTED(); };
72 virtual void Reset() { UNIMPLEMENTED(); }
74 protected:
75 ~MemoryMappingLayoutBase() {}
78 class MemoryMappingLayout final : public MemoryMappingLayoutBase {
79 public:
80 explicit MemoryMappingLayout(bool cache_enabled);
81 ~MemoryMappingLayout();
82 virtual bool Next(MemoryMappedSegment *segment) override;
83 virtual bool Error() const override;
84 virtual void Reset() override;
85 // In some cases, e.g. when running under a sandbox on Linux, ASan is unable
86 // to obtain the memory mappings. It should fall back to pre-cached data
87 // instead of aborting.
88 static void CacheMemoryMappings();
90 // Adds all mapped objects into a vector.
91 void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);
93 private:
94 void LoadFromCache();
96 MemoryMappingLayoutData data_;
99 // Returns code range for the specified module.
100 bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end);
102 bool IsDecimal(char c);
103 uptr ParseDecimal(const char **p);
104 bool IsHex(char c);
105 uptr ParseHex(const char **p);
107 } // namespace __sanitizer
109 #endif
110 #endif // SANITIZER_PROCMAPS_H