2012-01-05 09:07:27 +08:00
|
|
|
//===-- asan_process.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 a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Information about the process mappings.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef ASAN_PROCMAPS_H
|
|
|
|
#define ASAN_PROCMAPS_H
|
|
|
|
|
|
|
|
#include "asan_internal.h"
|
|
|
|
|
|
|
|
namespace __asan {
|
|
|
|
|
|
|
|
class AsanProcMaps {
|
|
|
|
public:
|
|
|
|
AsanProcMaps();
|
2012-01-06 07:50:34 +08:00
|
|
|
bool Next(uintptr_t *start, uintptr_t *end, uintptr_t *offset,
|
2012-01-05 09:07:27 +08:00
|
|
|
char filename[], size_t filename_size);
|
|
|
|
void Reset();
|
2012-01-06 07:50:34 +08:00
|
|
|
// Gets the object file name and the offset in that object for a given
|
|
|
|
// address 'addr'. Returns true on success.
|
|
|
|
bool GetObjectNameAndOffset(uintptr_t addr, uintptr_t *offset,
|
|
|
|
char filename[], size_t filename_size);
|
2012-01-05 09:07:27 +08:00
|
|
|
~AsanProcMaps();
|
|
|
|
private:
|
2012-01-18 19:16:05 +08:00
|
|
|
// Default implementation of GetObjectNameAndOffset.
|
|
|
|
// Quite slow, because it iterates through the whole process map for each
|
|
|
|
// lookup.
|
|
|
|
bool IterateForObjectNameAndOffset(uintptr_t addr, uintptr_t *offset,
|
|
|
|
char filename[], size_t filename_size) {
|
2012-01-19 20:44:06 +08:00
|
|
|
Reset();
|
2012-01-18 19:16:05 +08:00
|
|
|
uintptr_t start, end, file_offset;
|
2012-03-09 05:19:07 +08:00
|
|
|
for (int i = 0; Next(&start, &end, &file_offset, filename, filename_size);
|
|
|
|
i++) {
|
2012-01-18 19:16:05 +08:00
|
|
|
if (addr >= start && addr < end) {
|
2012-03-09 05:19:07 +08:00
|
|
|
// Don't subtract 'start' for the first entry. Don't ask me why.
|
|
|
|
*offset = (addr - (i ? start : 0)) + file_offset;
|
2012-01-18 19:16:05 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filename_size)
|
|
|
|
filename[0] = '\0';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-05 09:07:27 +08:00
|
|
|
#if defined __linux__
|
|
|
|
char *proc_self_maps_buff_;
|
|
|
|
size_t proc_self_maps_buff_mmaped_size_;
|
|
|
|
size_t proc_self_maps_buff_len_;
|
|
|
|
char *current_;
|
|
|
|
#elif defined __APPLE__
|
2012-01-31 06:11:04 +08:00
|
|
|
template<uint32_t kLCSegment, typename SegmentCommand>
|
|
|
|
bool NextSegmentLoad(uintptr_t *start, uintptr_t *end, uintptr_t *offset,
|
|
|
|
char filename[], size_t filename_size);
|
2012-01-18 19:16:05 +08:00
|
|
|
int current_image_;
|
2012-01-27 01:01:20 +08:00
|
|
|
uint32_t current_magic_;
|
2012-01-19 20:44:06 +08:00
|
|
|
int current_load_cmd_count_;
|
|
|
|
char *current_load_cmd_addr_;
|
2012-01-05 09:07:27 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace __asan
|
|
|
|
|
|
|
|
#endif // ASAN_PROCMAPS_H
|