1 //===-- sanitizer_procmaps.h ------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is shared between AddressSanitizer and ThreadSanitizer.
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
{
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
);
53 char *filename
; // owned by caller
57 u8 uuid
[kModuleUUIDSize
];
60 friend class MemoryMappingLayout
;
62 // This field is assigned and owned by MemoryMappingLayout if needed
63 MemoryMappedSegmentData
*data_
;
66 class MemoryMappingLayout
{
68 explicit MemoryMappingLayout(bool cache_enabled
);
69 ~MemoryMappingLayout();
70 bool Next(MemoryMappedSegment
*segment
);
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
);
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
);
92 uptr
ParseHex(const char **p
);
94 } // namespace __sanitizer
97 #endif // SANITIZER_PROCMAPS_H