2012-06-07 14:15:12 +08:00
|
|
|
//===-- 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
|
|
|
|
|
2013-12-25 16:39:38 +08:00
|
|
|
#include "sanitizer_common.h"
|
2012-06-07 14:15:12 +08:00
|
|
|
#include "sanitizer_internal_defs.h"
|
2012-12-01 10:39:45 +08:00
|
|
|
#include "sanitizer_mutex.h"
|
2012-06-07 14:15:12 +08:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
2014-03-06 16:58:24 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_LINUX
|
2012-12-04 05:21:22 +08:00
|
|
|
struct ProcSelfMapsBuff {
|
|
|
|
char *data;
|
|
|
|
uptr mmaped_size;
|
|
|
|
uptr len;
|
|
|
|
};
|
2014-03-06 16:58:24 +08:00
|
|
|
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
|
2012-12-04 05:21:22 +08:00
|
|
|
|
2012-08-27 21:48:48 +08:00
|
|
|
class MemoryMappingLayout {
|
2012-06-07 14:15:12 +08:00
|
|
|
public:
|
2013-03-26 18:34:37 +08:00
|
|
|
explicit MemoryMappingLayout(bool cache_enabled);
|
2013-12-25 16:39:38 +08:00
|
|
|
~MemoryMappingLayout();
|
2012-06-07 14:15:12 +08:00
|
|
|
bool Next(uptr *start, uptr *end, uptr *offset,
|
2013-03-13 14:51:02 +08:00
|
|
|
char filename[], uptr filename_size, uptr *protection);
|
2012-06-07 14:15:12 +08:00
|
|
|
void Reset();
|
2012-12-01 10:39:45 +08:00
|
|
|
// In some cases, e.g. when running under a sandbox on Linux, ASan is unable
|
|
|
|
// to obtain the memory mappings. It should fall back to pre-cached data
|
|
|
|
// instead of aborting.
|
|
|
|
static void CacheMemoryMappings();
|
2013-12-25 16:39:38 +08:00
|
|
|
|
|
|
|
// Stores the list of mapped objects into an array.
|
|
|
|
uptr DumpListOfModules(LoadedModule *modules, uptr max_modules,
|
|
|
|
string_predicate_t filter);
|
2012-06-20 23:19:17 +08:00
|
|
|
|
2013-03-13 14:51:02 +08:00
|
|
|
// Memory protection masks.
|
|
|
|
static const uptr kProtectionRead = 1;
|
|
|
|
static const uptr kProtectionWrite = 2;
|
|
|
|
static const uptr kProtectionExecute = 4;
|
|
|
|
static const uptr kProtectionShared = 8;
|
|
|
|
|
2012-06-07 14:15:12 +08:00
|
|
|
private:
|
2012-12-01 10:39:45 +08:00
|
|
|
void LoadFromCache();
|
2012-06-07 14:15:12 +08:00
|
|
|
|
2013-12-25 16:01:16 +08:00
|
|
|
// FIXME: Hide implementation details for different platforms in
|
|
|
|
// platform-specific files.
|
2014-03-06 16:58:24 +08:00
|
|
|
# if SANITIZER_FREEBSD || SANITIZER_LINUX
|
2012-12-04 05:21:22 +08:00
|
|
|
ProcSelfMapsBuff proc_self_maps_;
|
2012-06-07 14:15:12 +08:00
|
|
|
char *current_;
|
2012-12-01 10:39:45 +08:00
|
|
|
|
|
|
|
// Static mappings cache.
|
2012-12-04 05:21:22 +08:00
|
|
|
static ProcSelfMapsBuff cached_proc_self_maps_;
|
|
|
|
static StaticSpinMutex cache_lock_; // protects cached_proc_self_maps_.
|
2013-04-03 15:24:35 +08:00
|
|
|
# elif SANITIZER_MAC
|
2012-06-07 14:15:12 +08:00
|
|
|
template<u32 kLCSegment, typename SegmentCommand>
|
|
|
|
bool NextSegmentLoad(uptr *start, uptr *end, uptr *offset,
|
2013-03-13 15:39:25 +08:00
|
|
|
char filename[], uptr filename_size,
|
|
|
|
uptr *protection);
|
2012-06-07 14:15:12 +08:00
|
|
|
int current_image_;
|
|
|
|
u32 current_magic_;
|
2012-10-02 23:42:24 +08:00
|
|
|
u32 current_filetype_;
|
2012-06-07 14:15:12 +08:00
|
|
|
int current_load_cmd_count_;
|
|
|
|
char *current_load_cmd_addr_;
|
2012-08-28 15:22:24 +08:00
|
|
|
# endif
|
2012-06-07 14:15:12 +08:00
|
|
|
};
|
|
|
|
|
2013-09-03 19:09:16 +08:00
|
|
|
typedef void (*fill_profile_f)(uptr start, uptr rss, bool file,
|
|
|
|
/*out*/uptr *stats, uptr stats_size);
|
|
|
|
|
|
|
|
// Parse the contents of /proc/self/smaps and generate a memory profile.
|
|
|
|
// |cb| is a tool-specific callback that fills the |stats| array containing
|
|
|
|
// |stats_size| elements.
|
|
|
|
void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size);
|
|
|
|
|
2013-09-22 05:41:08 +08:00
|
|
|
// Returns code range for the specified module.
|
|
|
|
bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end);
|
|
|
|
|
2012-06-07 14:15:12 +08:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
|
|
|
#endif // SANITIZER_PROCMAPS_H
|