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 || 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
{
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
);
52 char *filename
; // owned by caller
56 u8 uuid
[kModuleUUIDSize
];
59 friend class MemoryMappingLayout
;
61 // This field is assigned and owned by MemoryMappingLayout if needed
62 MemoryMappedSegmentData
*data_
;
65 class MemoryMappingLayout
{
67 explicit MemoryMappingLayout(bool cache_enabled
);
68 ~MemoryMappingLayout();
69 bool Next(MemoryMappedSegment
*segment
);
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
);
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
);
91 uptr
ParseHex(const char **p
);
93 } // namespace __sanitizer
95 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
97 #endif // SANITIZER_PROCMAPS_H