@@ -83,8 +83,6 @@ const char kHwasanShadowMemoryDynamicAddress[] =
83
83
static const size_t kNumberOfAccessSizes = 5 ;
84
84
85
85
static const size_t kDefaultShadowScale = 4 ;
86
- static const uint64_t kDynamicShadowSentinel =
87
- std::numeric_limits<uint64_t >::max();
88
86
89
87
static const unsigned kShadowBaseAlignment = 32 ;
90
88
@@ -385,44 +383,44 @@ class HWAddressSanitizer {
385
383
std::unique_ptr<RandomNumberGenerator> Rng;
386
384
387
385
// / This struct defines the shadow mapping using the rule:
386
+ // / If `kFixed`, then
388
387
// / shadow = (mem >> Scale) + Offset.
389
- // / If InGlobal is true, then
388
+ // / If `kGlobal`, then
389
+ // / extern char* __hwasan_shadow_memory_dynamic_address;
390
+ // / shadow = (mem >> Scale) + __hwasan_shadow_memory_dynamic_address
391
+ // / If `kIfunc`, then
390
392
// / extern char __hwasan_shadow[];
391
393
// / shadow = (mem >> Scale) + &__hwasan_shadow
392
- // / If InTls is true , then
394
+ // / If `kTls` , then
393
395
// / extern char *__hwasan_tls;
394
396
// / shadow = (mem>>Scale) + align_up(__hwasan_shadow, kShadowBaseAlignment)
395
397
// /
396
398
// / If WithFrameRecord is true, then __hwasan_tls will be used to access the
397
399
// / ring buffer for storing stack allocations on targets that support it.
398
400
class ShadowMapping {
399
- uint8_t Scale;
401
+ enum class OffsetKind {
402
+ kFixed = 0 ,
403
+ kGlobal ,
404
+ kIfunc ,
405
+ kTls ,
406
+ };
407
+ OffsetKind Kind;
400
408
uint64_t Offset;
401
- bool InGlobal;
402
- bool InTls;
409
+ uint8_t Scale;
403
410
bool WithFrameRecord;
404
411
412
+ void SetFixed (uint64_t O) {
413
+ Kind = OffsetKind::kFixed ;
414
+ Offset = O;
415
+ }
416
+
405
417
public:
406
418
void init (Triple &TargetTriple, bool InstrumentWithCalls);
407
419
Align getObjectAlignment () const { return Align (1ULL << Scale); }
408
- bool isInGlobal () const {
409
- return !InGlobal && !InTls && Offset == kDynamicShadowSentinel ;
410
- }
411
- bool isInIfunc () const {
412
- assert (!InGlobal || !InTls);
413
- assert (!InGlobal || Offset == kDynamicShadowSentinel );
414
- return InGlobal;
415
- }
416
- bool isInTls () const {
417
- assert (!InTls || !InGlobal);
418
- assert (!InTls || Offset == kDynamicShadowSentinel );
419
- return InTls;
420
- }
421
- bool isFixed () const {
422
- assert (Offset == kDynamicShadowSentinel || !InTls);
423
- assert (Offset == kDynamicShadowSentinel || !InGlobal);
424
- return Offset != kDynamicShadowSentinel ;
425
- }
420
+ bool isInGlobal () const { return Kind == OffsetKind::kGlobal ; }
421
+ bool isInIfunc () const { return Kind == OffsetKind::kIfunc ; }
422
+ bool isInTls () const { return Kind == OffsetKind::kTls ; }
423
+ bool isFixed () const { return Kind == OffsetKind::kFixed ; }
426
424
uint8_t scale () const { return Scale; };
427
425
uint64_t offset () const {
428
426
assert (isFixed ());
@@ -1930,34 +1928,22 @@ void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
1930
1928
if (TargetTriple.isOSFuchsia ()) {
1931
1929
// Fuchsia is always PIE, which means that the beginning of the address
1932
1930
// space is always available.
1933
- InGlobal = false ;
1934
- InTls = false ;
1935
- Offset = 0 ;
1931
+ SetFixed (0 );
1936
1932
WithFrameRecord = true ;
1937
1933
} else if (ClMappingOffset.getNumOccurrences () > 0 ) {
1938
- InGlobal = false ;
1939
- InTls = false ;
1940
- Offset = ClMappingOffset;
1934
+ SetFixed (ClMappingOffset);
1941
1935
WithFrameRecord = false ;
1942
1936
} else if (ClEnableKhwasan || InstrumentWithCalls) {
1943
- InGlobal = false ;
1944
- InTls = false ;
1945
- Offset = 0 ;
1937
+ SetFixed (0 );
1946
1938
WithFrameRecord = false ;
1947
1939
} else if (ClWithIfunc) {
1948
- InGlobal = true ;
1949
- InTls = false ;
1950
- Offset = kDynamicShadowSentinel ;
1940
+ Kind = OffsetKind::kIfunc ;
1951
1941
WithFrameRecord = false ;
1952
1942
} else if (ClWithTls) {
1953
- InGlobal = false ;
1954
- InTls = true ;
1955
- Offset = kDynamicShadowSentinel ;
1943
+ Kind = OffsetKind::kTls ;
1956
1944
WithFrameRecord = true ;
1957
1945
} else {
1958
- InGlobal = false ;
1959
- InTls = false ;
1960
- Offset = kDynamicShadowSentinel ;
1946
+ Kind = OffsetKind::kGlobal ;
1961
1947
WithFrameRecord = false ;
1962
1948
}
1963
1949
}
0 commit comments