Skip to content

Commit

Permalink
tsan: define all fields for all mappings
Browse files Browse the repository at this point in the history
Define all fields to 0 for all mappings.
This allows to write portable code and tests.
For all existing cases 0 values work out of the box
because we check if an address belongs to the range
and nothing belongs to [0, 0] range.

Depends on D107738.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107739
  • Loading branch information
dvyukov committed Aug 10, 2021
1 parent 3830c93 commit fd50600
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
64 changes: 50 additions & 14 deletions compiler-rt/lib/tsan/rtl/tsan_platform.h
Expand Up @@ -388,6 +388,13 @@ struct MappingGo48 {
static const uptr kShadowEnd = 0x238000000000ull;
static const uptr kLoAppMemBeg = 0x000000001000ull;
static const uptr kLoAppMemEnd = 0x00e000000000ull;
static const uptr kMidAppMemBeg = 0;
static const uptr kMidAppMemEnd = 0;
static const uptr kHiAppMemBeg = 0;
static const uptr kHiAppMemEnd = 0;
static const uptr kHeapMemBeg = 0;
static const uptr kHeapMemEnd = 0;
static const uptr kVdsoBeg = 0;
};

/* Go on windows
Expand All @@ -411,6 +418,13 @@ struct MappingGoWindows {
static const uptr kShadowEnd = 0x050000000000ull;
static const uptr kLoAppMemBeg = 0x000000001000ull;
static const uptr kLoAppMemEnd = 0x00e000000000ull;
static const uptr kMidAppMemBeg = 0;
static const uptr kMidAppMemEnd = 0;
static const uptr kHiAppMemBeg = 0;
static const uptr kHiAppMemEnd = 0;
static const uptr kHeapMemBeg = 0;
static const uptr kHeapMemEnd = 0;
static const uptr kVdsoBeg = 0;
};

/* Go on linux/powerpc64 (46-bit VMA)
Expand All @@ -435,6 +449,13 @@ struct MappingGoPPC64_46 {
static const uptr kShadowEnd = 0x238000000000ull;
static const uptr kLoAppMemBeg = 0x000000001000ull;
static const uptr kLoAppMemEnd = 0x00e000000000ull;
static const uptr kMidAppMemBeg = 0;
static const uptr kMidAppMemEnd = 0;
static const uptr kHiAppMemBeg = 0;
static const uptr kHiAppMemEnd = 0;
static const uptr kHeapMemBeg = 0;
static const uptr kHeapMemEnd = 0;
static const uptr kVdsoBeg = 0;
};

/* Go on linux/powerpc64 (47-bit VMA)
Expand All @@ -459,6 +480,13 @@ struct MappingGoPPC64_47 {
static const uptr kShadowEnd = 0x300000000000ull;
static const uptr kLoAppMemBeg = 0x000000001000ull;
static const uptr kLoAppMemEnd = 0x00e000000000ull;
static const uptr kMidAppMemBeg = 0;
static const uptr kMidAppMemEnd = 0;
static const uptr kHiAppMemBeg = 0;
static const uptr kHiAppMemEnd = 0;
static const uptr kHeapMemBeg = 0;
static const uptr kHeapMemEnd = 0;
static const uptr kVdsoBeg = 0;
};

/* Go on linux/aarch64 (48-bit VMA) and darwin/aarch64 (47-bit VMA)
Expand All @@ -482,6 +510,13 @@ struct MappingGoAarch64 {
static const uptr kShadowEnd = 0x300000000000ull;
static const uptr kLoAppMemBeg = 0x000000001000ull;
static const uptr kLoAppMemEnd = 0x00e000000000ull;
static const uptr kMidAppMemBeg = 0;
static const uptr kMidAppMemEnd = 0;
static const uptr kHiAppMemBeg = 0;
static const uptr kHiAppMemEnd = 0;
static const uptr kHeapMemBeg = 0;
static const uptr kHeapMemEnd = 0;
static const uptr kVdsoBeg = 0;
};

/*
Expand All @@ -506,6 +541,13 @@ struct MappingGoMips64_47 {
static const uptr kShadowEnd = 0x300000000000ull;
static const uptr kLoAppMemBeg = 0x000000001000ull;
static const uptr kLoAppMemEnd = 0x00e000000000ull;
static const uptr kMidAppMemBeg = 0;
static const uptr kMidAppMemEnd = 0;
static const uptr kHiAppMemBeg = 0;
static const uptr kHiAppMemEnd = 0;
static const uptr kHeapMemBeg = 0;
static const uptr kHeapMemEnd = 0;
static const uptr kVdsoBeg = 0;
};

/*
Expand All @@ -527,6 +569,13 @@ struct MappingGoS390x {
static const uptr kShadowEnd = 0x800000000000ull;
static const uptr kLoAppMemBeg = 0x000000001000ull;
static const uptr kLoAppMemEnd = 0x100000000000ull;
static const uptr kMidAppMemBeg = 0;
static const uptr kMidAppMemEnd = 0;
static const uptr kHiAppMemBeg = 0;
static const uptr kHiAppMemEnd = 0;
static const uptr kHeapMemBeg = 0;
static const uptr kHeapMemEnd = 0;
static const uptr kVdsoBeg = 0;
};

#if defined(__x86_64__)
Expand Down Expand Up @@ -669,25 +718,21 @@ struct MappingField {
switch (type) {
case MAPPING_LO_APP_BEG: return Mapping::kLoAppMemBeg;
case MAPPING_LO_APP_END: return Mapping::kLoAppMemEnd;
#if !SANITIZER_GO
case MAPPING_MID_APP_BEG: return Mapping::kMidAppMemBeg;
case MAPPING_MID_APP_END: return Mapping::kMidAppMemEnd;
case MAPPING_HI_APP_BEG: return Mapping::kHiAppMemBeg;
case MAPPING_HI_APP_END: return Mapping::kHiAppMemEnd;
case MAPPING_HEAP_BEG: return Mapping::kHeapMemBeg;
case MAPPING_HEAP_END: return Mapping::kHeapMemEnd;
case MAPPING_VDSO_BEG: return Mapping::kVdsoBeg;
#endif
case MAPPING_SHADOW_BEG: return Mapping::kShadowBeg;
case MAPPING_SHADOW_END: return Mapping::kShadowEnd;
case MAPPING_META_SHADOW_BEG: return Mapping::kMetaShadowBeg;
case MAPPING_META_SHADOW_END: return Mapping::kMetaShadowEnd;
case MAPPING_TRACE_BEG: return Mapping::kTraceMemBeg;
case MAPPING_TRACE_END: return Mapping::kTraceMemEnd;
default:
DCHECK(0);
return 0;
}
Die();
}
};

Expand All @@ -700,7 +745,6 @@ uptr LoAppMemEnd(void) {
return SelectMapping<MappingField>(MAPPING_LO_APP_END);
}

#if !SANITIZER_GO
ALWAYS_INLINE
uptr MidAppMemBeg(void) {
return SelectMapping<MappingField>(MAPPING_MID_APP_BEG);
Expand All @@ -727,16 +771,13 @@ uptr HiAppMemEnd(void) {
ALWAYS_INLINE
uptr VdsoBeg(void) { return SelectMapping<MappingField>(MAPPING_VDSO_BEG); }

#endif

static inline
bool GetUserRegion(int i, uptr *start, uptr *end) {
switch (i) {
case 0:
*start = LoAppMemBeg();
*end = LoAppMemEnd();
return true;
#if !SANITIZER_GO
case 1:
*start = HiAppMemBeg();
*end = HiAppMemEnd();
Expand All @@ -752,7 +793,6 @@ bool GetUserRegion(int i, uptr *start, uptr *end) {
return true;
}
FALLTHROUGH;
#endif
default:
return false;
}
Expand Down Expand Up @@ -784,14 +824,10 @@ uptr TraceMemEnd(void) {
struct IsAppMemImpl {
template <typename Mapping>
static bool Apply(uptr mem) {
#if !SANITIZER_GO
return (mem >= Mapping::kHeapMemBeg && mem < Mapping::kHeapMemEnd) ||
(mem >= Mapping::kMidAppMemBeg && mem < Mapping::kMidAppMemEnd) ||
(mem >= Mapping::kLoAppMemBeg && mem < Mapping::kLoAppMemEnd) ||
(mem >= Mapping::kHiAppMemBeg && mem < Mapping::kHiAppMemEnd);
#else
return mem >= Mapping::kLoAppMemBeg && mem < Mapping::kLoAppMemEnd;
#endif
}
};

Expand Down
2 changes: 0 additions & 2 deletions compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
Expand Up @@ -111,12 +111,10 @@ void FillProfileCallback(uptr p, uptr rss, bool file,
mem[MemMeta] += rss;
else if (p >= LoAppMemBeg() && p < LoAppMemEnd())
mem[file ? MemFile : MemMmap] += rss;
# if !SANITIZER_GO
else if (p >= HiAppMemBeg() && p < HiAppMemEnd())
mem[file ? MemFile : MemMmap] += rss;
else if (p >= HeapMemBeg() && p < HeapMemEnd())
mem[MemHeap] += rss;
# endif
else if (p >= TraceMemBeg() && p < TraceMemEnd())
mem[MemTrace] += rss;
else
Expand Down

0 comments on commit fd50600

Please sign in to comment.