1 //===-- sanitizer_procmaps.h ------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is shared between AddressSanitizer and ThreadSanitizer.
11 // Information about the process mappings.
12 //===----------------------------------------------------------------------===//
13 #ifndef SANITIZER_PROCMAPS_H
14 #define SANITIZER_PROCMAPS_H
16 #include "sanitizer_platform.h"
18 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
19 SANITIZER_OPENBSD || SANITIZER_MAC || SANITIZER_SOLARIS
21 #include "sanitizer_common.h"
22 #include "sanitizer_internal_defs.h"
23 #include "sanitizer_linux.h"
24 #include "sanitizer_mac.h"
25 #include "sanitizer_mutex.h"
27 namespace __sanitizer {
30 // Memory protection masks.
31 static const uptr kProtectionRead = 1;
32 static const uptr kProtectionWrite = 2;
33 static const uptr kProtectionExecute = 4;
34 static const uptr kProtectionShared = 8;
36 struct MemoryMappedSegmentData;
38 class MemoryMappedSegment {
40 MemoryMappedSegment(char *buff = nullptr, uptr size = 0)
41 : filename(buff), filename_size(size), data_(nullptr) {}
42 ~MemoryMappedSegment() {}
44 bool IsReadable() const { return protection & kProtectionRead; }
45 bool IsWritable() const { return protection & kProtectionWrite; }
46 bool IsExecutable() const { return protection & kProtectionExecute; }
47 bool IsShared() const { return protection & kProtectionShared; }
49 void AddAddressRanges(LoadedModule *module);
54 char *filename; // owned by caller
58 u8 uuid[kModuleUUIDSize];
61 friend class MemoryMappingLayout;
63 // This field is assigned and owned by MemoryMappingLayout if needed
64 MemoryMappedSegmentData *data_;
67 class MemoryMappingLayout {
69 explicit MemoryMappingLayout(bool cache_enabled);
70 ~MemoryMappingLayout();
71 bool Next(MemoryMappedSegment *segment);
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();
79 // Adds all mapped objects into a vector.
80 void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);
85 MemoryMappingLayoutData data_;
88 // Returns code range for the specified module.
89 bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end);
91 bool IsDecimal(char c);
92 uptr ParseDecimal(const char **p);
94 uptr ParseHex(const char **p);
96 } // namespace __sanitizer
99 #endif // SANITIZER_PROCMAPS_H