* gcc-interface/trans.c (Subprogram_Body_to_gnu): Initialize locus.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_procmaps.h
blob040f6940f17235c4b59789420e34b1407caf5187
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 || SANITIZER_MAC
19 #include "sanitizer_common.h"
20 #include "sanitizer_internal_defs.h"
21 #include "sanitizer_linux.h"
22 #include "sanitizer_mac.h"
23 #include "sanitizer_mutex.h"
25 namespace __sanitizer {
28 // Memory protection masks.
29 static const uptr kProtectionRead = 1;
30 static const uptr kProtectionWrite = 2;
31 static const uptr kProtectionExecute = 4;
32 static const uptr kProtectionShared = 8;
34 struct MemoryMappedSegmentData;
36 class MemoryMappedSegment {
37 public:
38 MemoryMappedSegment(char *buff = nullptr, uptr size = 0)
39 : filename(buff), filename_size(size), data_(nullptr) {}
40 ~MemoryMappedSegment() {}
42 bool IsReadable() const { return protection & kProtectionRead; }
43 bool IsWritable() const { return protection & kProtectionWrite; }
44 bool IsExecutable() const { return protection & kProtectionExecute; }
45 bool IsShared() const { return protection & kProtectionShared; }
47 void AddAddressRanges(LoadedModule *module);
49 uptr start;
50 uptr end;
51 uptr offset;
52 char *filename; // owned by caller
53 uptr filename_size;
54 uptr protection;
55 ModuleArch arch;
56 u8 uuid[kModuleUUIDSize];
58 private:
59 friend class MemoryMappingLayout;
61 // This field is assigned and owned by MemoryMappingLayout if needed
62 MemoryMappedSegmentData *data_;
65 class MemoryMappingLayout {
66 public:
67 explicit MemoryMappingLayout(bool cache_enabled);
68 ~MemoryMappingLayout();
69 bool Next(MemoryMappedSegment *segment);
70 void Reset();
71 // In some cases, e.g. when running under a sandbox on Linux, ASan is unable
72 // to obtain the memory mappings. It should fall back to pre-cached data
73 // instead of aborting.
74 static void CacheMemoryMappings();
76 // Adds all mapped objects into a vector.
77 void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);
79 private:
80 void LoadFromCache();
82 MemoryMappingLayoutData data_;
85 // Returns code range for the specified module.
86 bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end);
88 bool IsDecimal(char c);
89 uptr ParseDecimal(const char **p);
90 bool IsHex(char c);
91 uptr ParseHex(const char **p);
93 } // namespace __sanitizer
95 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
96 // SANITIZER_MAC
97 #endif // SANITIZER_PROCMAPS_H