* config/riscv/riscv.c (riscv_emit_float_compare): Use fallthru
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_procmaps.h
blob0183a0941119a6b6bdc52a6d1a60933326f630b3
1 //===-- sanitizer_procmaps.h ------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is shared between AddressSanitizer and ThreadSanitizer.
9 //
10 // Information about the process mappings.
11 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_PROCMAPS_H
13 #define SANITIZER_PROCMAPS_H
15 #include "sanitizer_common.h"
16 #include "sanitizer_internal_defs.h"
17 #include "sanitizer_mutex.h"
19 namespace __sanitizer {
21 #if SANITIZER_FREEBSD || SANITIZER_LINUX
22 struct ProcSelfMapsBuff {
23 char *data;
24 uptr mmaped_size;
25 uptr len;
28 // Reads process memory map in an OS-specific way.
29 void ReadProcMaps(ProcSelfMapsBuff *proc_maps);
30 #endif // SANITIZER_FREEBSD || SANITIZER_LINUX
32 class MemoryMappingLayout {
33 public:
34 explicit MemoryMappingLayout(bool cache_enabled);
35 ~MemoryMappingLayout();
36 bool Next(uptr *start, uptr *end, uptr *offset,
37 char filename[], uptr filename_size, uptr *protection);
38 void Reset();
39 // In some cases, e.g. when running under a sandbox on Linux, ASan is unable
40 // to obtain the memory mappings. It should fall back to pre-cached data
41 // instead of aborting.
42 static void CacheMemoryMappings();
44 // Adds all mapped objects into a vector.
45 void DumpListOfModules(InternalMmapVector<LoadedModule> *modules);
47 // Memory protection masks.
48 static const uptr kProtectionRead = 1;
49 static const uptr kProtectionWrite = 2;
50 static const uptr kProtectionExecute = 4;
51 static const uptr kProtectionShared = 8;
53 private:
54 void LoadFromCache();
56 // FIXME: Hide implementation details for different platforms in
57 // platform-specific files.
58 # if SANITIZER_FREEBSD || SANITIZER_LINUX
59 ProcSelfMapsBuff proc_self_maps_;
60 const char *current_;
62 // Static mappings cache.
63 static ProcSelfMapsBuff cached_proc_self_maps_;
64 static StaticSpinMutex cache_lock_; // protects cached_proc_self_maps_.
65 # elif SANITIZER_MAC
66 template<u32 kLCSegment, typename SegmentCommand>
67 bool NextSegmentLoad(uptr *start, uptr *end, uptr *offset,
68 char filename[], uptr filename_size,
69 uptr *protection);
70 int current_image_;
71 u32 current_magic_;
72 u32 current_filetype_;
73 int current_load_cmd_count_;
74 char *current_load_cmd_addr_;
75 # endif
78 typedef void (*fill_profile_f)(uptr start, uptr rss, bool file,
79 /*out*/uptr *stats, uptr stats_size);
81 // Parse the contents of /proc/self/smaps and generate a memory profile.
82 // |cb| is a tool-specific callback that fills the |stats| array containing
83 // |stats_size| elements.
84 void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size);
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);
91 bool IsHex(char c);
92 uptr ParseHex(const char **p);
94 } // namespace __sanitizer
96 #endif // SANITIZER_PROCMAPS_H