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
|
|
|
|
|
2017-09-26 05:51:04 +08:00
|
|
|
#include "sanitizer_platform.h"
|
|
|
|
|
2018-03-16 06:40:47 +08:00
|
|
|
#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
|
|
|
|
SANITIZER_OPENBSD || SANITIZER_MAC || SANITIZER_SOLARIS
|
2017-09-26 04:48:51 +08:00
|
|
|
|
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"
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
#include "sanitizer_linux.h"
|
|
|
|
#include "sanitizer_mac.h"
|
2012-12-01 10:39:45 +08:00
|
|
|
#include "sanitizer_mutex.h"
|
2012-06-07 14:15:12 +08:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
2012-12-04 05:21:22 +08:00
|
|
|
|
2017-07-12 02:54:00 +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;
|
|
|
|
|
2017-07-25 23:27:32 +08:00
|
|
|
struct MemoryMappedSegmentData;
|
|
|
|
|
|
|
|
class MemoryMappedSegment {
|
|
|
|
public:
|
2017-07-12 02:54:00 +08:00
|
|
|
MemoryMappedSegment(char *buff = nullptr, uptr size = 0)
|
2017-07-25 23:27:32 +08:00
|
|
|
: filename(buff), filename_size(size), data_(nullptr) {}
|
2017-07-12 02:54:00 +08:00
|
|
|
~MemoryMappedSegment() {}
|
|
|
|
|
2017-07-24 22:31:01 +08:00
|
|
|
bool IsReadable() const { return protection & kProtectionRead; }
|
|
|
|
bool IsWritable() const { return protection & kProtectionWrite; }
|
|
|
|
bool IsExecutable() const { return protection & kProtectionExecute; }
|
|
|
|
bool IsShared() const { return protection & kProtectionShared; }
|
2017-07-12 02:54:00 +08:00
|
|
|
|
2017-07-25 23:27:32 +08:00
|
|
|
void AddAddressRanges(LoadedModule *module);
|
|
|
|
|
2017-07-12 02:54:00 +08:00
|
|
|
uptr start;
|
|
|
|
uptr end;
|
|
|
|
uptr offset;
|
|
|
|
char *filename; // owned by caller
|
|
|
|
uptr filename_size;
|
|
|
|
uptr protection;
|
|
|
|
ModuleArch arch;
|
|
|
|
u8 uuid[kModuleUUIDSize];
|
2017-07-25 23:27:32 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class MemoryMappingLayout;
|
|
|
|
|
|
|
|
// This field is assigned and owned by MemoryMappingLayout if needed
|
|
|
|
MemoryMappedSegmentData *data_;
|
2017-07-12 02:54:00 +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();
|
2017-07-12 02:54:00 +08:00
|
|
|
bool Next(MemoryMappedSegment *segment);
|
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
|
|
|
|
2016-02-23 02:52:51 +08:00
|
|
|
// Adds all mapped objects into a vector.
|
2017-09-30 04:55:06 +08:00
|
|
|
void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);
|
2012-06-20 23:19:17 +08:00
|
|
|
|
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
|
|
|
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
MemoryMappingLayoutData data_;
|
2012-06-07 14:15:12 +08:00
|
|
|
};
|
|
|
|
|
2013-09-22 05:41:08 +08:00
|
|
|
// Returns code range for the specified module.
|
|
|
|
bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end);
|
|
|
|
|
2014-08-06 18:16:52 +08:00
|
|
|
bool IsDecimal(char c);
|
|
|
|
uptr ParseDecimal(const char **p);
|
|
|
|
bool IsHex(char c);
|
|
|
|
uptr ParseHex(const char **p);
|
|
|
|
|
2012-06-07 14:15:12 +08:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
2018-03-16 06:40:47 +08:00
|
|
|
#endif
|
2012-06-07 14:15:12 +08:00
|
|
|
#endif // SANITIZER_PROCMAPS_H
|