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"
|
|
|
|
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
|
|
|
|
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
|
|
|
|
|
2017-09-26 05:26:34 +08:00
|
|
|
#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
// SANITIZER_MAC || SANITIZER_SOLARIS
|
2012-06-07 14:15:12 +08:00
|
|
|
#endif // SANITIZER_PROCMAPS_H
|