1 //===-- sanitizer_procmaps.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is shared between AddressSanitizer and ThreadSanitizer.
12 // Information about the process mappings.
13 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_PROCMAPS_H
15 #define SANITIZER_PROCMAPS_H
17 #include "sanitizer_platform.h"
19 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
20 SANITIZER_OPENBSD || SANITIZER_MAC || SANITIZER_SOLARIS
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"
28 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 {
41 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);
55 char *filename; // owned by caller
59 u8 uuid[kModuleUUIDSize];
62 friend class MemoryMappingLayout;
64 // This field is assigned and owned by MemoryMappingLayout if needed
65 MemoryMappedSegmentData *data_;
68 class MemoryMappingLayout {
70 explicit MemoryMappingLayout(bool cache_enabled);
71 ~MemoryMappingLayout();
72 bool Next(MemoryMappedSegment *segment);
75 // In some cases, e.g. when running under a sandbox on Linux, ASan is unable
76 // to obtain the memory mappings. It should fall back to pre-cached data
77 // instead of aborting.
78 static void CacheMemoryMappings();
80 // Adds all mapped objects into a vector.
81 void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);
86 MemoryMappingLayoutData data_;
89 // Returns code range for the specified module.
90 bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end);
92 bool IsDecimal(char c);
93 uptr ParseDecimal(const char **p);
95 uptr ParseHex(const char **p);
97 } // namespace __sanitizer
100 #endif // SANITIZER_PROCMAPS_H