diff options
author | Dan Liew <dan@su-root.co.uk> | 2018-12-14 09:03:18 +0000 |
---|---|---|
committer | Dan Liew <dan@su-root.co.uk> | 2018-12-14 09:03:18 +0000 |
commit | 41fec1bfc58783f136f09c90b0f1a88c16703e6c (patch) | |
tree | 60c46a1d12c7f199acc642d2e942a21fadbd7283 /compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc | |
parent | 257ce3871e5b94e3fa0db2a3f4abd0b3c491830c (diff) | |
download | bcm5719-llvm-41fec1bfc58783f136f09c90b0f1a88c16703e6c.tar.gz bcm5719-llvm-41fec1bfc58783f136f09c90b0f1a88c16703e6c.zip |
Introduce `AddressSpaceView` template parameter to `SizeClassAllocator32`, `FlatByteMap`, and `TwoLevelByteMap`.
Summary:
This is a follow up patch to r346956 for the `SizeClassAllocator32`
allocator.
This patch makes `AddressSpaceView` a template parameter both to the
`ByteMap` implementations (but makes `LocalAddressSpaceView` the
default), some `AP32` implementations and is used in `SizeClassAllocator32`.
The actual changes to `ByteMap` implementations and
`SizeClassAllocator32` are very simple. However the patch is large
because it requires changing all the `AP32` definitions, and users of
those definitions.
For ASan and LSan we make `AP32` and `ByteMap` templateds type that take
a single `AddressSpaceView` argument. This has been done because we will
instantiate the allocator with a type that isn't `LocalAddressSpaceView`
in the future patches. For the allocators used in the other sanitizers
(i.e. HWAsan, MSan, Scudo, and TSan) use of `LocalAddressSpaceView` is
hard coded because we do not intend to instantiate the allocators with
any other type.
In the cases where untemplated types have become templated on a single
`AddressSpaceView` parameter (e.g. `PrimaryAllocator`) their name has
been changed to have a `ASVT` suffix (Address Space View Type) to
indicate they are templated. The only exception to this are the `AP32`
types due to the desire to keep the type name as short as possible.
In order to check that template is instantiated in the correct a way a
`static_assert(...)` has been added that checks that the
`AddressSpaceView` type used by `Params::ByteMap::AddressSpaceView` matches
the `Params::AddressSpaceView`. This uses the new `sanitizer_type_traits.h`
header.
rdar://problem/45284065
Reviewers: kcc, dvyukov, vitalybuka, cryptoad, eugenis, kubamracek, george.karpenkov
Subscribers: mgorny, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D54904
llvm-svn: 349138
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc')
-rw-r--r-- | compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc index c13da36ce75..f12b70e7b67 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -118,17 +118,22 @@ static const u64 kAddressSpaceSize = 1ULL << 32; static const uptr kRegionSizeLog = FIRST_32_SECOND_64(20, 24); static const uptr kFlatByteMapSize = kAddressSpaceSize >> kRegionSizeLog; +template <typename AddressSpaceViewTy> struct AP32Compact { static const uptr kSpaceBeg = 0; static const u64 kSpaceSize = kAddressSpaceSize; static const uptr kMetadataSize = 16; typedef CompactSizeClassMap SizeClassMap; static const uptr kRegionSizeLog = ::kRegionSizeLog; - typedef FlatByteMap<kFlatByteMapSize> ByteMap; + using AddressSpaceView = AddressSpaceViewTy; + using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>; typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; }; -typedef SizeClassAllocator32<AP32Compact> Allocator32Compact; +template <typename AddressSpaceView> +using Allocator32CompactASVT = + SizeClassAllocator32<AP32Compact<AddressSpaceView>>; +using Allocator32Compact = Allocator32CompactASVT<LocalAddressSpaceView>; template <class SizeClassMap> void TestSizeClassMap() { @@ -259,18 +264,24 @@ TEST(SanitizerCommon, SizeClassAllocator32Compact) { TestSizeClassAllocator<Allocator32Compact>(); } +template <typename AddressSpaceViewTy> struct AP32SeparateBatches { static const uptr kSpaceBeg = 0; static const u64 kSpaceSize = kAddressSpaceSize; static const uptr kMetadataSize = 16; typedef DefaultSizeClassMap SizeClassMap; static const uptr kRegionSizeLog = ::kRegionSizeLog; - typedef FlatByteMap<kFlatByteMapSize> ByteMap; + using AddressSpaceView = AddressSpaceViewTy; + using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>; typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch; }; -typedef SizeClassAllocator32<AP32SeparateBatches> Allocator32SeparateBatches; +template <typename AddressSpaceView> +using Allocator32SeparateBatchesASVT = + SizeClassAllocator32<AP32SeparateBatches<AddressSpaceView>>; +using Allocator32SeparateBatches = + Allocator32SeparateBatchesASVT<LocalAddressSpaceView>; TEST(SanitizerCommon, SizeClassAllocator32SeparateBatches) { TestSizeClassAllocator<Allocator32SeparateBatches>(); @@ -426,13 +437,15 @@ TEST(SanitizerCommon, SizeClassAllocator64MapUnmapCallback) { #endif #endif +template <typename AddressSpaceViewTy = LocalAddressSpaceView> struct AP32WithCallback { static const uptr kSpaceBeg = 0; static const u64 kSpaceSize = kAddressSpaceSize; static const uptr kMetadataSize = 16; typedef CompactSizeClassMap SizeClassMap; static const uptr kRegionSizeLog = ::kRegionSizeLog; - typedef FlatByteMap<kFlatByteMapSize> ByteMap; + using AddressSpaceView = AddressSpaceViewTy; + using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>; typedef TestMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; }; @@ -440,7 +453,7 @@ struct AP32WithCallback { TEST(SanitizerCommon, SizeClassAllocator32MapUnmapCallback) { TestMapUnmapCallback::map_count = 0; TestMapUnmapCallback::unmap_count = 0; - typedef SizeClassAllocator32<AP32WithCallback> Allocator32WithCallBack; + typedef SizeClassAllocator32<AP32WithCallback<>> Allocator32WithCallBack; Allocator32WithCallBack *a = new Allocator32WithCallBack; a->Init(kReleaseToOSIntervalNever); EXPECT_EQ(TestMapUnmapCallback::map_count, 0); @@ -1337,8 +1350,10 @@ TEST(SanitizerCommon, TwoLevelByteMap) { m.TestOnlyUnmap(); } - -typedef TwoLevelByteMap<1 << 12, 1 << 13, TestMapUnmapCallback> TestByteMap; +template <typename AddressSpaceView> +using TestByteMapASVT = + TwoLevelByteMap<1 << 12, 1 << 13, AddressSpaceView, TestMapUnmapCallback>; +using TestByteMap = TestByteMapASVT<LocalAddressSpaceView>; struct TestByteMapParam { TestByteMap *m; |