]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / lib / sanitizer_common / sanitizer_procmaps.h
1 //===-- sanitizer_procmaps.h ------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is shared between AddressSanitizer and ThreadSanitizer.
11 //
12 // Information about the process mappings.
13 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_PROCMAPS_H
15 #define SANITIZER_PROCMAPS_H
16
17 #include "sanitizer_platform.h"
18
19 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
20 SANITIZER_MAC || SANITIZER_SOLARIS
21
22 #include "sanitizer_common.h"
23 #include "sanitizer_internal_defs.h"
24 #include "sanitizer_linux.h"
25 #include "sanitizer_mac.h"
26 #include "sanitizer_mutex.h"
27
28 namespace __sanitizer {
29
30
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;
36
37 struct MemoryMappedSegmentData;
38
39 class MemoryMappedSegment {
40 public:
41 MemoryMappedSegment(char *buff = nullptr, uptr size = 0)
42 : filename(buff), filename_size(size), data_(nullptr) {}
43 ~MemoryMappedSegment() {}
44
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; }
49
50 void AddAddressRanges(LoadedModule *module);
51
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];
60
61 private:
62 friend class MemoryMappingLayout;
63
64 // This field is assigned and owned by MemoryMappingLayout if needed
65 MemoryMappedSegmentData *data_;
66 };
67
68 class MemoryMappingLayout {
69 public:
70 explicit MemoryMappingLayout(bool cache_enabled);
71 ~MemoryMappingLayout();
72 bool Next(MemoryMappedSegment *segment);
73 void Reset();
74 // In some cases, e.g. when running under a sandbox on Linux, ASan is unable
75 // to obtain the memory mappings. It should fall back to pre-cached data
76 // instead of aborting.
77 static void CacheMemoryMappings();
78
79 // Adds all mapped objects into a vector.
80 void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);
81
82 private:
83 void LoadFromCache();
84
85 MemoryMappingLayoutData data_;
86 };
87
88 // Returns code range for the specified module.
89 bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end);
90
91 bool IsDecimal(char c);
92 uptr ParseDecimal(const char **p);
93 bool IsHex(char c);
94 uptr ParseHex(const char **p);
95
96 } // namespace __sanitizer
97
98 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
99 // SANITIZER_MAC || SANITIZER_SOLARIS
100 #endif // SANITIZER_PROCMAPS_H