Skip to content

Commit

Permalink
[sanitizer][NFC] Set LargeMmapAllocator type from PrimaryAllocator
Browse files Browse the repository at this point in the history
They need to have same AddressSpaceView and MapUnmapCallback.

Reviewers: eugenis

Subscribers: kubamracek, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D61168

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@359719 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vitalybuka committed May 1, 2019
1 parent 602be70 commit 99cd89c
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 45 deletions.
8 changes: 1 addition & 7 deletions lib/asan/asan_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,9 @@ using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>;

static const uptr kNumberOfSizeClasses = SizeClassMap::kNumClasses;

template <typename AddressSpaceView>
using SecondaryAllocatorASVT =
LargeMmapAllocator<AsanMapUnmapCallback, DefaultLargeMmapAllocatorPtrArray,
AddressSpaceView>;
template <typename AddressSpaceView>
using AsanAllocatorASVT =
CombinedAllocator<PrimaryAllocatorASVT<AddressSpaceView>,
SecondaryAllocatorASVT<AddressSpaceView>,
AddressSpaceView>;
CombinedAllocator<PrimaryAllocatorASVT<AddressSpaceView>>;
using AsanAllocator = AsanAllocatorASVT<LocalAddressSpaceView>;
using AllocatorCache = AsanAllocator::AllocatorCache;

Expand Down
3 changes: 1 addition & 2 deletions lib/hwasan/hwasan_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ struct AP64 {
static const uptr kFlags = 0;
};
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
typedef LargeMmapAllocator<HwasanMapUnmapCallback> SecondaryAllocator;
typedef CombinedAllocator<PrimaryAllocator, SecondaryAllocator> Allocator;
typedef CombinedAllocator<PrimaryAllocator> Allocator;
typedef Allocator::AllocatorCache AllocatorCache;

void AllocatorSwallowThreadLocalCache(AllocatorCache *cache);
Expand Down
10 changes: 1 addition & 9 deletions lib/lsan/lsan_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,7 @@ using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>;
#endif

template <typename AddressSpaceView>
using SecondaryAllocatorASVT =
LargeMmapAllocator<NoOpMapUnmapCallback, DefaultLargeMmapAllocatorPtrArray,
AddressSpaceView>;

template <typename AddressSpaceView>
using AllocatorASVT =
CombinedAllocator<PrimaryAllocatorASVT<AddressSpaceView>,
SecondaryAllocatorASVT<AddressSpaceView>,
AddressSpaceView>;
using AllocatorASVT = CombinedAllocator<PrimaryAllocatorASVT<AddressSpaceView>>;
using Allocator = AllocatorASVT<LocalAddressSpaceView>;
using AllocatorCache = Allocator::AllocatorCache;

Expand Down
3 changes: 1 addition & 2 deletions lib/msan/msan_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ struct AP32 {
};
typedef SizeClassAllocator32<AP32> PrimaryAllocator;
#endif
typedef LargeMmapAllocator<MsanMapUnmapCallback> SecondaryAllocator;
typedef CombinedAllocator<PrimaryAllocator, SecondaryAllocator> Allocator;
typedef CombinedAllocator<PrimaryAllocator> Allocator;
typedef Allocator::AllocatorCache AllocatorCache;

static Allocator allocator;
Expand Down
15 changes: 6 additions & 9 deletions lib/sanitizer_common/sanitizer_allocator_combined.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
// When allocating 2^x bytes it should return 2^x aligned chunk.
// PrimaryAllocator is used via a local AllocatorCache.
// SecondaryAllocator can allocate anything, but is not efficient.
template <class PrimaryAllocator, class SecondaryAllocator,
typename AddressSpaceViewTy = LocalAddressSpaceView> // NOLINT
template <class PrimaryAllocator,
class LargeMmapAllocatorPtrArray = DefaultLargeMmapAllocatorPtrArray>
class CombinedAllocator {
public:
using AllocatorCache = SizeClassAllocatorLocalCache<PrimaryAllocator>;
using AddressSpaceView = AddressSpaceViewTy;
static_assert(is_same<AddressSpaceView,
typename PrimaryAllocator::AddressSpaceView>::value,
"PrimaryAllocator is using wrong AddressSpaceView");
static_assert(is_same<AddressSpaceView,
typename SecondaryAllocator::AddressSpaceView>::value,
"SecondaryAllocator is using wrong AddressSpaceView");
using SecondaryAllocator =
LargeMmapAllocator<typename PrimaryAllocator::MapUnmapCallback,
LargeMmapAllocatorPtrArray,
typename PrimaryAllocator::AddressSpaceView>;

void InitLinkerInitialized(s32 release_to_os_interval_ms) {
stats_.InitLinkerInitialized();
Expand Down
7 changes: 2 additions & 5 deletions lib/sanitizer_common/sanitizer_allocator_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ struct AP32 {
};
typedef SizeClassAllocator32<AP32> PrimaryInternalAllocator;

typedef LargeMmapAllocator<NoOpMapUnmapCallback,
LargeMmapAllocatorPtrArrayStatic>
SecondaryInternalAllocator;

typedef CombinedAllocator<PrimaryInternalAllocator, SecondaryInternalAllocator>
typedef CombinedAllocator<PrimaryInternalAllocator,
LargeMmapAllocatorPtrArrayStatic>
InternalAllocator;
typedef InternalAllocator::AllocatorCache InternalAllocatorCache;

Expand Down
14 changes: 7 additions & 7 deletions lib/sanitizer_common/tests/sanitizer_allocator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,9 @@ TEST(SanitizerCommon, LargeMmapAllocator) {
a.Deallocate(&stats, p);
}

template <class PrimaryAllocator, class SecondaryAllocator>
template <class PrimaryAllocator>
void TestCombinedAllocator() {
typedef CombinedAllocator<PrimaryAllocator, SecondaryAllocator> Allocator;
typedef CombinedAllocator<PrimaryAllocator> Allocator;
Allocator *a = new Allocator;
a->Init(kReleaseToOSIntervalNever);
std::mt19937 r;
Expand Down Expand Up @@ -683,26 +683,26 @@ void TestCombinedAllocator() {

#if SANITIZER_CAN_USE_ALLOCATOR64
TEST(SanitizerCommon, CombinedAllocator64) {
TestCombinedAllocator<Allocator64, LargeMmapAllocator<>>();
TestCombinedAllocator<Allocator64>();
}

TEST(SanitizerCommon, CombinedAllocator64Dynamic) {
TestCombinedAllocator<Allocator64Dynamic, LargeMmapAllocator<>>();
TestCombinedAllocator<Allocator64Dynamic>();
}

#if !SANITIZER_ANDROID
TEST(SanitizerCommon, CombinedAllocator64Compact) {
TestCombinedAllocator<Allocator64Compact, LargeMmapAllocator<>>();
TestCombinedAllocator<Allocator64Compact>();
}
#endif

TEST(SanitizerCommon, CombinedAllocator64VeryCompact) {
TestCombinedAllocator<Allocator64VeryCompact, LargeMmapAllocator<>>();
TestCombinedAllocator<Allocator64VeryCompact>();
}
#endif

TEST(SanitizerCommon, CombinedAllocator32Compact) {
TestCombinedAllocator<Allocator32Compact, LargeMmapAllocator<>>();
TestCombinedAllocator<Allocator32Compact>();
}

template <class AllocatorCache>
Expand Down
3 changes: 1 addition & 2 deletions lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ struct __AP64 {
namespace {

typedef SizeClassAllocator64<__AP64> PrimaryAllocator;
typedef LargeMmapAllocator<> SecondaryAllocator;
typedef CombinedAllocator<PrimaryAllocator, SecondaryAllocator> Allocator;
typedef CombinedAllocator<PrimaryAllocator> Allocator;
typedef Allocator::AllocatorCache AllocatorCache;

static Allocator allocator;
Expand Down
3 changes: 1 addition & 2 deletions lib/tsan/rtl/tsan_rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name.
};
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
#endif
typedef LargeMmapAllocator<MapUnmapCallback> SecondaryAllocator;
typedef CombinedAllocator<PrimaryAllocator, SecondaryAllocator> Allocator;
typedef CombinedAllocator<PrimaryAllocator> Allocator;
typedef Allocator::AllocatorCache AllocatorCache;
Allocator *allocator();
#endif
Expand Down

0 comments on commit 99cd89c

Please sign in to comment.