Skip to content

Commit fda121a

Browse files
committed
tsan: remove TSAN_MID_APP_RANGE macro
First, the define conflicts with definition/testing of all mappings, since it's not a global property anymore. Second, macros/ifdefs are bad. Define kMidAppMemBeg/End to 0 to denote that there is no "mid" range instead. Depends on D107736. Reviewed By: melver Differential Revision: https://reviews.llvm.org/D107737
1 parent a44a873 commit fda121a

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

compiler-rt/lib/tsan/rtl/tsan_platform.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ struct MappingAppleAarch64 {
136136
static const uptr kAppMemMsk = 0x0ull;
137137
static const uptr kAppMemXor = 0x0ull;
138138
static const uptr kVdsoBeg = 0x7000000000000000ull;
139+
static const uptr kMidAppMemBeg = 0;
140+
static const uptr kMidAppMemEnd = 0;
139141
};
140142

141143
/*
@@ -258,6 +260,8 @@ struct MappingPPC64_44 {
258260
static const uptr kAppMemMsk = 0x0f0000000000ull;
259261
static const uptr kAppMemXor = 0x002100000000ull;
260262
static const uptr kVdsoBeg = 0x3c0000000000000ull;
263+
static const uptr kMidAppMemBeg = 0;
264+
static const uptr kMidAppMemEnd = 0;
261265
};
262266

263267
/*
@@ -290,6 +294,8 @@ struct MappingPPC64_46 {
290294
static const uptr kAppMemMsk = 0x3c0000000000ull;
291295
static const uptr kAppMemXor = 0x020000000000ull;
292296
static const uptr kVdsoBeg = 0x7800000000000000ull;
297+
static const uptr kMidAppMemBeg = 0;
298+
static const uptr kMidAppMemEnd = 0;
293299
};
294300

295301
/*
@@ -322,6 +328,8 @@ struct MappingPPC64_47 {
322328
static const uptr kAppMemMsk = 0x7c0000000000ull;
323329
static const uptr kAppMemXor = 0x020000000000ull;
324330
static const uptr kVdsoBeg = 0x7800000000000000ull;
331+
static const uptr kMidAppMemBeg = 0;
332+
static const uptr kMidAppMemEnd = 0;
325333
};
326334

327335
/*
@@ -354,6 +362,8 @@ struct MappingS390x {
354362
static const uptr kAppMemMsk = 0xb00000000000ull;
355363
static const uptr kAppMemXor = 0x100000000000ull;
356364
static const uptr kVdsoBeg = 0xfffffffff000ull;
365+
static const uptr kMidAppMemBeg = 0;
366+
static const uptr kMidAppMemEnd = 0;
357367
};
358368

359369
/* Go on linux, darwin and freebsd on x86_64
@@ -535,10 +545,8 @@ struct MappingGoS390x {
535545

536546
# if HAS_48_BIT_ADDRESS_SPACE
537547
typedef Mapping48AddressSpace Mapping;
538-
# define TSAN_MID_APP_RANGE 1
539548
# elif defined(__mips64)
540549
typedef MappingMips64_40 Mapping40;
541-
# define TSAN_MID_APP_RANGE 1
542550
# define TSAN_RUNTIME_VMA 1
543551
# elif defined(__aarch64__) && defined(__APPLE__)
544552
typedef MappingAppleAarch64 Mapping;
@@ -554,7 +562,6 @@ typedef MappingAarch64_48 Mapping48;
554562
// Indicates the runtime will define the memory regions at runtime.
555563
# define TSAN_RUNTIME_VMA 1
556564
// Indicates that mapping defines a mid range memory segment.
557-
# define TSAN_MID_APP_RANGE 1
558565
# elif defined(__powerpc64__)
559566
// PPC64 supports multiple VMA which leads to multiple address transformation
560567
// functions. To support these multiple VMAS transformations and mappings TSAN
@@ -643,10 +650,8 @@ enum MappingType {
643650
MAPPING_LO_APP_END,
644651
MAPPING_HI_APP_BEG,
645652
MAPPING_HI_APP_END,
646-
#ifdef TSAN_MID_APP_RANGE
647653
MAPPING_MID_APP_BEG,
648654
MAPPING_MID_APP_END,
649-
#endif
650655
MAPPING_HEAP_BEG,
651656
MAPPING_HEAP_END,
652657
MAPPING_APP_BEG,
@@ -667,10 +672,8 @@ struct MappingField {
667672
#if !SANITIZER_GO
668673
case MAPPING_LO_APP_BEG: return Mapping::kLoAppMemBeg;
669674
case MAPPING_LO_APP_END: return Mapping::kLoAppMemEnd;
670-
# ifdef TSAN_MID_APP_RANGE
671675
case MAPPING_MID_APP_BEG: return Mapping::kMidAppMemBeg;
672676
case MAPPING_MID_APP_END: return Mapping::kMidAppMemEnd;
673-
# endif
674677
case MAPPING_HI_APP_BEG: return Mapping::kHiAppMemBeg;
675678
case MAPPING_HI_APP_END: return Mapping::kHiAppMemEnd;
676679
case MAPPING_HEAP_BEG: return Mapping::kHeapMemBeg;
@@ -703,7 +706,6 @@ uptr LoAppMemEnd(void) {
703706
return SelectMapping<MappingField>(MAPPING_LO_APP_END);
704707
}
705708

706-
#ifdef TSAN_MID_APP_RANGE
707709
ALWAYS_INLINE
708710
uptr MidAppMemBeg(void) {
709711
return SelectMapping<MappingField>(MAPPING_MID_APP_BEG);
@@ -712,7 +714,6 @@ ALWAYS_INLINE
712714
uptr MidAppMemEnd(void) {
713715
return SelectMapping<MappingField>(MAPPING_MID_APP_END);
714716
}
715-
#endif
716717

717718
ALWAYS_INLINE
718719
uptr HeapMemBeg(void) { return SelectMapping<MappingField>(MAPPING_HEAP_BEG); }
@@ -743,8 +744,6 @@ uptr AppMemEnd(void) { return SelectMapping<MappingField>(MAPPING_APP_END); }
743744
static inline
744745
bool GetUserRegion(int i, uptr *start, uptr *end) {
745746
switch (i) {
746-
default:
747-
return false;
748747
#if !SANITIZER_GO
749748
case 0:
750749
*start = LoAppMemBeg();
@@ -758,18 +757,21 @@ bool GetUserRegion(int i, uptr *start, uptr *end) {
758757
*start = HeapMemBeg();
759758
*end = HeapMemEnd();
760759
return true;
761-
# ifdef TSAN_MID_APP_RANGE
762760
case 3:
763-
*start = MidAppMemBeg();
764-
*end = MidAppMemEnd();
765-
return true;
766-
# endif
761+
if (MidAppMemBeg()) {
762+
*start = MidAppMemBeg();
763+
*end = MidAppMemEnd();
764+
return true;
765+
}
766+
FALLTHROUGH;
767767
#else
768768
case 0:
769769
*start = AppMemBeg();
770770
*end = AppMemEnd();
771771
return true;
772772
#endif
773+
default:
774+
return false;
773775
}
774776
}
775777

@@ -801,9 +803,7 @@ struct IsAppMemImpl {
801803
static bool Apply(uptr mem) {
802804
#if !SANITIZER_GO
803805
return (mem >= Mapping::kHeapMemBeg && mem < Mapping::kHeapMemEnd) ||
804-
# ifdef TSAN_MID_APP_RANGE
805806
(mem >= Mapping::kMidAppMemBeg && mem < Mapping::kMidAppMemEnd) ||
806-
# endif
807807
(mem >= Mapping::kLoAppMemBeg && mem < Mapping::kLoAppMemEnd) ||
808808
(mem >= Mapping::kHiAppMemBeg && mem < Mapping::kHiAppMemEnd);
809809
#else
@@ -898,13 +898,13 @@ struct ShadowToMemImpl {
898898
if (p >= Mapping::kLoAppMemBeg && p < Mapping::kLoAppMemEnd &&
899899
MemToShadowImpl::Apply<Mapping>(p) == sp)
900900
return p;
901-
# ifdef TSAN_MID_APP_RANGE
902-
p = ((sp / kShadowCnt) ^ Mapping::kAppMemXor) +
903-
(Mapping::kMidAppMemBeg & Mapping::kAppMemMsk);
904-
if (p >= Mapping::kMidAppMemBeg && p < Mapping::kMidAppMemEnd &&
905-
MemToShadowImpl::Apply<Mapping>(p) == sp)
906-
return p;
907-
# endif
901+
if (Mapping::kMidAppMemBeg) {
902+
p = ((sp / kShadowCnt) ^ Mapping::kAppMemXor) +
903+
(Mapping::kMidAppMemBeg & Mapping::kAppMemMsk);
904+
if (p >= Mapping::kMidAppMemBeg && p < Mapping::kMidAppMemEnd &&
905+
MemToShadowImpl::Apply<Mapping>(p) == sp)
906+
return p;
907+
}
908908
return ((sp / kShadowCnt) ^ Mapping::kAppMemXor) | Mapping::kAppMemMsk;
909909
#else // #if !SANITIZER_GO
910910
# ifndef SANITIZER_WINDOWS

compiler-rt/lib/tsan/rtl/tsan_platform_posix.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ void CheckAndProtect() {
110110
#else
111111
ProtectRange(LoAppMemEnd(), ShadowBeg());
112112
ProtectRange(ShadowEnd(), MetaShadowBeg());
113-
#ifdef TSAN_MID_APP_RANGE
114-
ProtectRange(MetaShadowEnd(), MidAppMemBeg());
115-
ProtectRange(MidAppMemEnd(), TraceMemBeg());
116-
#else
117-
ProtectRange(MetaShadowEnd(), TraceMemBeg());
118-
#endif
113+
if (MidAppMemBeg()) {
114+
ProtectRange(MetaShadowEnd(), MidAppMemBeg());
115+
ProtectRange(MidAppMemEnd(), TraceMemBeg());
116+
} else {
117+
ProtectRange(MetaShadowEnd(), TraceMemBeg());
118+
}
119119
// Memory for traces is mapped lazily in MapThreadTrace.
120120
// Protect the whole range for now, so that user does not map something here.
121121
ProtectRange(TraceMemBeg(), TraceMemEnd());

0 commit comments

Comments
 (0)