sanitizer_procmaps.h [plain text]
#ifndef SANITIZER_PROCMAPS_H
#define SANITIZER_PROCMAPS_H
#include "sanitizer_internal_defs.h"
#include "sanitizer_mutex.h"
namespace __sanitizer {
#ifdef _WIN32
class MemoryMappingLayout {
public:
MemoryMappingLayout() {}
bool GetObjectNameAndOffset(uptr addr, uptr *offset,
char filename[], uptr filename_size) {
UNIMPLEMENTED();
}
};
#else // _WIN32
#if defined(__linux__)
struct ProcSelfMapsBuff {
char *data;
uptr mmaped_size;
uptr len;
};
#endif // defined(__linux__)
class MemoryMappingLayout {
public:
MemoryMappingLayout();
bool Next(uptr *start, uptr *end, uptr *offset,
char filename[], uptr filename_size);
void Reset();
bool GetObjectNameAndOffset(uptr addr, uptr *offset,
char filename[], uptr filename_size);
static void CacheMemoryMappings();
~MemoryMappingLayout();
private:
void LoadFromCache();
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) {
*offset = (addr - (i ? start : 0)) + file_offset;
return true;
}
}
if (filename_size)
filename[0] = '\0';
return false;
}
# if defined __linux__
ProcSelfMapsBuff proc_self_maps_;
char *current_;
static ProcSelfMapsBuff cached_proc_self_maps_;
static StaticSpinMutex cache_lock_; # 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_;
u32 current_filetype_;
int current_load_cmd_count_;
char *current_load_cmd_addr_;
# endif
};
#endif // _WIN32
}
#endif // SANITIZER_PROCMAPS_H