PR rtl-optimization/87817
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_procmaps.h
blob606b29214434194e4668bd0d617110805684b0ca
1 //===-- sanitizer_procmaps.h ------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is shared between AddressSanitizer and ThreadSanitizer.
9 //
10 // Information about the process mappings.
11 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_PROCMAPS_H
13 #define SANITIZER_PROCMAPS_H
15 #include "sanitizer_platform.h"
17 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
18 SANITIZER_OPENBSD || SANITIZER_MAC || SANITIZER_SOLARIS
20 #include "sanitizer_common.h"
21 #include "sanitizer_internal_defs.h"
22 #include "sanitizer_linux.h"
23 #include "sanitizer_mac.h"
24 #include "sanitizer_mutex.h"
26 namespace __sanitizer {
29 // Memory protection masks.
30 static const uptr kProtectionRead = 1;
31 static const uptr kProtectionWrite = 2;
32 static const uptr kProtectionExecute = 4;
33 static const uptr kProtectionShared = 8;
35 struct MemoryMappedSegmentData;
37 class MemoryMappedSegment {
38 public:
39 MemoryMappedSegment(char *buff = nullptr, uptr size = 0)
40 : filename(buff), filename_size(size), data_(nullptr) {}
41 ~MemoryMappedSegment() {}
43 bool IsReadable() const { return protection & kProtectionRead; }
44 bool IsWritable() const { return protection & kProtectionWrite; }
45 bool IsExecutable() const { return protection & kProtectionExecute; }
46 bool IsShared() const { return protection & kProtectionShared; }
48 void AddAddressRanges(LoadedModule *module);
50 uptr start;
51 uptr end;
52 uptr offset;
53 char *filename; // owned by caller
54 uptr filename_size;
55 uptr protection;
56 ModuleArch arch;
57 u8 uuid[kModuleUUIDSize];
59 private:
60 friend class MemoryMappingLayout;
62 // This field is assigned and owned by MemoryMappingLayout if needed
63 MemoryMappedSegmentData *data_;
66 class MemoryMappingLayout {
67 public:
68 explicit MemoryMappingLayout(bool cache_enabled);
69 ~MemoryMappingLayout();
70 bool Next(MemoryMappedSegment *segment);
71 void Reset();
72 // In some cases, e.g. when running under a sandbox on Linux, ASan is unable
73 // to obtain the memory mappings. It should fall back to pre-cached data
74 // instead of aborting.
75 static void CacheMemoryMappings();
77 // Adds all mapped objects into a vector.
78 void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);
80 private:
81 void LoadFromCache();
83 MemoryMappingLayoutData data_;
86 // Returns code range for the specified module.
87 bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end);
89 bool IsDecimal(char c);
90 uptr ParseDecimal(const char **p);
91 bool IsHex(char c);
92 uptr ParseHex(const char **p);
94 } // namespace __sanitizer
96 #endif
97 #endif // SANITIZER_PROCMAPS_H