@@ -36,6 +36,17 @@ using namespace __sanitizer;
36
36
#define SKIP_ON_SOLARIS_SPARCV9 (x ) x
37
37
#endif
38
38
39
+ // On 64-bit systems with small virtual address spaces (e.g. 39-bit) we can't
40
+ // use size class maps with a large number of classes, as that will make the
41
+ // SizeClassAllocator64 region size too small (< 2^32).
42
+ #if SANITIZER_ANDROID && defined(__aarch64__)
43
+ #define ALLOCATOR64_SMALL_SIZE 1
44
+ #elif SANITIZER_RISCV64
45
+ #define ALLOCATOR64_SMALL_SIZE 1
46
+ #else
47
+ #define ALLOCATOR64_SMALL_SIZE 0
48
+ #endif
49
+
39
50
// Too slow for debug build
40
51
#if !SANITIZER_DEBUG
41
52
@@ -53,6 +64,11 @@ static const uptr kAllocatorSpace = 0x3000000000ULL;
53
64
static const uptr kAllocatorSize = 0x2000000000ULL ;
54
65
static const u64 kAddressSpaceSize = 1ULL << 39 ;
55
66
typedef VeryCompactSizeClassMap SizeClassMap;
67
+ #elif SANITIZER_RISCV64
68
+ const uptr kAllocatorSpace = ~(uptr)0 ;
69
+ const uptr kAllocatorSize = 0x2000000000ULL ; // 128G.
70
+ static const u64 kAddressSpaceSize = 1ULL << 38 ;
71
+ typedef VeryDenseSizeClassMap SizeClassMap;
56
72
#else
57
73
static const uptr kAllocatorSpace = 0x700000000000ULL ;
58
74
static const uptr kAllocatorSize = 0x010000000000ULL ; // 1T.
@@ -276,8 +292,7 @@ TEST(SanitizerCommon, SizeClassAllocator64Dynamic) {
276
292
TestSizeClassAllocator<Allocator64Dynamic>();
277
293
}
278
294
279
- #if !SANITIZER_ANDROID
280
- // FIXME(kostyak): find values so that those work on Android as well.
295
+ #if !ALLOCATOR64_SMALL_SIZE
281
296
TEST (SanitizerCommon, SizeClassAllocator64Compact) {
282
297
TestSizeClassAllocator<Allocator64Compact>();
283
298
}
@@ -361,7 +376,7 @@ TEST(SanitizerCommon, SizeClassAllocator64DynamicMetadataStress) {
361
376
SizeClassAllocatorMetadataStress<Allocator64Dynamic>();
362
377
}
363
378
364
- #if !SANITIZER_ANDROID
379
+ #if !ALLOCATOR64_SMALL_SIZE
365
380
TEST (SanitizerCommon, SizeClassAllocator64CompactMetadataStress) {
366
381
SizeClassAllocatorMetadataStress<Allocator64Compact>();
367
382
}
@@ -408,7 +423,7 @@ TEST(SanitizerCommon, SizeClassAllocator64DynamicGetBlockBegin) {
408
423
SizeClassAllocatorGetBlockBeginStress<Allocator64Dynamic>(
409
424
1ULL << (SANITIZER_ANDROID ? 31 : 33 ));
410
425
}
411
- #if !SANITIZER_ANDROID
426
+ #if !ALLOCATOR64_SMALL_SIZE
412
427
TEST (SanitizerCommon, SizeClassAllocator64CompactGetBlockBegin) {
413
428
SizeClassAllocatorGetBlockBeginStress<Allocator64Compact>(1ULL << 33 );
414
429
}
@@ -520,7 +535,7 @@ TEST(SanitizerCommon, LargeMmapAllocatorMapUnmapCallback) {
520
535
521
536
// Don't test OOM conditions on Win64 because it causes other tests on the same
522
537
// machine to OOM.
523
- #if SANITIZER_CAN_USE_ALLOCATOR64 && !SANITIZER_WINDOWS64 && !SANITIZER_ANDROID
538
+ #if SANITIZER_CAN_USE_ALLOCATOR64 && !SANITIZER_WINDOWS64
524
539
TEST (SanitizerCommon, SizeClassAllocator64Overflow) {
525
540
Allocator64 a;
526
541
a.Init (kReleaseToOSIntervalNever );
@@ -534,7 +549,8 @@ TEST(SanitizerCommon, SizeClassAllocator64Overflow) {
534
549
uint32_t chunks[kNumChunks ];
535
550
bool allocation_failed = false ;
536
551
for (int i = 0 ; i < 1000000 ; i++) {
537
- if (!a.GetFromAllocator (&stats, 52 , chunks, kNumChunks )) {
552
+ uptr class_id = a.kNumClasses - 1 ;
553
+ if (!a.GetFromAllocator (&stats, class_id, chunks, kNumChunks )) {
538
554
allocation_failed = true ;
539
555
break ;
540
556
}
@@ -698,7 +714,7 @@ TEST(SanitizerCommon, CombinedAllocator64Dynamic) {
698
714
TestCombinedAllocator<Allocator64Dynamic>();
699
715
}
700
716
701
- #if !SANITIZER_ANDROID
717
+ #if !ALLOCATOR64_SMALL_SIZE
702
718
TEST (SanitizerCommon, CombinedAllocator64Compact) {
703
719
TestCombinedAllocator<Allocator64Compact>();
704
720
}
@@ -759,7 +775,7 @@ TEST(SanitizerCommon, SizeClassAllocator64DynamicLocalCache) {
759
775
TestSizeClassAllocatorLocalCache<Allocator64Dynamic>();
760
776
}
761
777
762
- #if !SANITIZER_ANDROID
778
+ #if !ALLOCATOR64_SMALL_SIZE
763
779
TEST (SanitizerCommon, SizeClassAllocator64CompactLocalCache) {
764
780
TestSizeClassAllocatorLocalCache<Allocator64Compact>();
765
781
}
@@ -1016,8 +1032,8 @@ TEST(SanitizerCommon, LargeMmapAllocatorBlockBegin) {
1016
1032
1017
1033
// Don't test OOM conditions on Win64 because it causes other tests on the same
1018
1034
// machine to OOM.
1019
- #if SANITIZER_CAN_USE_ALLOCATOR64 && !SANITIZER_WINDOWS64 && !SANITIZER_ANDROID
1020
- typedef __sanitizer::SizeClassMap<3 , 4 , 8 , 38 , 128 , 16 > SpecialSizeClassMap;
1035
+ #if SANITIZER_CAN_USE_ALLOCATOR64 && !SANITIZER_WINDOWS64
1036
+ typedef __sanitizer::SizeClassMap<2 , 22 , 22 , 34 , 128 , 16 > SpecialSizeClassMap;
1021
1037
template <typename AddressSpaceViewTy = LocalAddressSpaceView>
1022
1038
struct AP64_SpecialSizeClassMap {
1023
1039
static const uptr kSpaceBeg = kAllocatorSpace ;
@@ -1044,15 +1060,15 @@ TEST(SanitizerCommon, SizeClassAllocator64PopulateFreeListOOM) {
1044
1060
// ...one man is on a mission to overflow a region with a series of
1045
1061
// successive allocations.
1046
1062
1047
- const uptr kClassID = 107 ;
1063
+ const uptr kClassID = kAllocatorSize == ALLOCATOR64_SMALL_SIZE ? 18 : 24 ;
1048
1064
const uptr kAllocationSize = SpecialSizeClassMap::Size (kClassID );
1049
1065
ASSERT_LT (2 * kAllocationSize , kRegionSize );
1050
1066
ASSERT_GT (3 * kAllocationSize , kRegionSize );
1051
1067
EXPECT_NE (cache.Allocate (a, kClassID ), nullptr );
1052
1068
EXPECT_NE (cache.Allocate (a, kClassID ), nullptr );
1053
1069
EXPECT_EQ (cache.Allocate (a, kClassID ), nullptr );
1054
1070
1055
- const uptr Class2 = 100 ;
1071
+ const uptr Class2 = kAllocatorSize == ALLOCATOR64_SMALL_SIZE ? 15 : 21 ;
1056
1072
const uptr Size2 = SpecialSizeClassMap::Size (Class2);
1057
1073
ASSERT_EQ (Size2 * 8 , kRegionSize );
1058
1074
char *p[7 ];
@@ -1338,15 +1354,15 @@ TEST(SanitizerCommon, SizeClassAllocator64ReleaseFreeMemoryToOS) {
1338
1354
TestReleaseFreeMemoryToOS<Allocator64>();
1339
1355
}
1340
1356
1341
- #if !SANITIZER_ANDROID
1357
+ #if !ALLOCATOR64_SMALL_SIZE
1342
1358
TEST (SanitizerCommon, SizeClassAllocator64CompactReleaseFreeMemoryToOS) {
1343
1359
TestReleaseFreeMemoryToOS<Allocator64Compact>();
1344
1360
}
1345
1361
1346
1362
TEST (SanitizerCommon, SizeClassAllocator64VeryCompactReleaseFreeMemoryToOS) {
1347
1363
TestReleaseFreeMemoryToOS<Allocator64VeryCompact>();
1348
1364
}
1349
- #endif // !SANITIZER_ANDROID
1365
+ #endif // !ALLOCATOR64_SMALL_SIZE
1350
1366
1351
1367
#endif // SANITIZER_CAN_USE_ALLOCATOR64
1352
1368
0 commit comments