diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-06-07 06:15:12 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-06-07 06:15:12 +0000 |
commit | 6895adc39c4e09371154c8037366ad4464163ed0 (patch) | |
tree | 7f9a3e828980b8b3daf20b689450432525f26ebe /lib/sanitizer_common/sanitizer_procmaps.h | |
parent | cffe2f5c30c27234260d004b54152916ff0c45c6 (diff) | |
download | compiler-rt-6895adc39c4e09371154c8037366ad4464163ed0.tar.gz compiler-rt-6895adc39c4e09371154c8037366ad4464163ed0.tar.bz2 compiler-rt-6895adc39c4e09371154c8037366ad4464163ed0.tar.xz |
[Sanitizer] __asan::AsanProcMaps -> __sanitizer::ProcessMaps.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158139 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_procmaps.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_procmaps.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_procmaps.h b/lib/sanitizer_common/sanitizer_procmaps.h new file mode 100644 index 00000000..2140106e --- /dev/null +++ b/lib/sanitizer_common/sanitizer_procmaps.h @@ -0,0 +1,71 @@ +//===-- sanitizer_procmaps.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is shared between AddressSanitizer and ThreadSanitizer. +// +// Information about the process mappings. +//===----------------------------------------------------------------------===// +#ifndef SANITIZER_PROCMAPS_H +#define SANITIZER_PROCMAPS_H + +#include "sanitizer_internal_defs.h" + +namespace __sanitizer { + +class ProcessMaps { + public: + ProcessMaps(); + bool Next(uptr *start, uptr *end, uptr *offset, + char filename[], uptr filename_size); + void Reset(); + // Gets the object file name and the offset in that object for a given + // address 'addr'. Returns true on success. + bool GetObjectNameAndOffset(uptr addr, uptr *offset, + char filename[], uptr filename_size); + ~ProcessMaps(); + private: + // Default implementation of GetObjectNameAndOffset. + // Quite slow, because it iterates through the whole process map for each + // lookup. + bool IterateForObjectNameAndOffset(uptr addr, uptr *offset, + char filename[], uptr filename_size) { + Reset(); + uptr start, end, file_offset; + for (int i = 0; Next(&start, &end, &file_offset, filename, filename_size); + i++) { + if (addr >= start && addr < end) { + // Don't subtract 'start' for the first entry. Don't ask me why. + *offset = (addr - (i ? start : 0)) + file_offset; + return true; + } + } + if (filename_size) + filename[0] = '\0'; + return false; + } + +#if defined __linux__ + char *proc_self_maps_buff_; + uptr proc_self_maps_buff_mmaped_size_; + uptr proc_self_maps_buff_len_; + char *current_; +#elif defined __APPLE__ + template<u32 kLCSegment, typename SegmentCommand> + bool NextSegmentLoad(uptr *start, uptr *end, uptr *offset, + char filename[], uptr filename_size); + int current_image_; + u32 current_magic_; + int current_load_cmd_count_; + char *current_load_cmd_addr_; +#endif +}; + +} // namespace __sanitizer + +#endif // SANITIZER_PROCMAPS_H |