2012-06-07 14:15:12 +08:00
|
|
|
//===-- sanitizer_procmaps.h ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-06-07 14:15:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2020-01-25 08:33:49 +08:00
|
|
|
#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
|
2020-10-20 18:14:26 +08:00
|
|
|
SANITIZER_MAC || SANITIZER_SOLARIS || \
|
2020-01-25 08:33:49 +08:00
|
|
|
SANITIZER_FUCHSIA
|
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"
|
2020-01-25 08:33:49 +08:00
|
|
|
#include "sanitizer_fuchsia.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 {
|
|
|
|
|
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:
|
2019-09-12 05:33:06 +08:00
|
|
|
explicit 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
|
|
|
};
|
|
|
|
|
2021-10-13 02:30:23 +08:00
|
|
|
class MemoryMappingLayoutBase {
|
|
|
|
public:
|
|
|
|
virtual bool Next(MemoryMappedSegment *segment) { UNIMPLEMENTED(); }
|
|
|
|
virtual bool Error() const { UNIMPLEMENTED(); };
|
|
|
|
virtual void Reset() { UNIMPLEMENTED(); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~MemoryMappingLayoutBase() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MemoryMappingLayout final : public MemoryMappingLayoutBase {
|
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();
|
2021-10-13 02:30:23 +08:00
|
|
|
virtual bool Next(MemoryMappedSegment *segment) override;
|
|
|
|
virtual bool Error() const override;
|
|
|
|
virtual void Reset() override;
|
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
|