File tree 3 files changed +17
-8
lines changed
3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -37,8 +37,14 @@ typedef u8 tag_t;
37
37
38
38
// TBI (Top Byte Ignore) feature of AArch64: bits [63:56] are ignored in address
39
39
// translation and can be used to store a tag.
40
- const unsigned kAddressTagShift = 56 ;
41
- const uptr kAddressTagMask = 0xFFUL << kAddressTagShift ;
40
+ constexpr unsigned kAddressTagShift = 56 ;
41
+ constexpr unsigned kTagBits = 8 ;
42
+
43
+ // Mask for extracting tag bits from the lower 8 bits.
44
+ constexpr uptr kTagMask = (1UL << kTagBits ) - 1 ;
45
+
46
+ // Masks for extracting and removing tags from full pointers.
47
+ constexpr uptr kAddressTagMask = kTagMask << kAddressTagShift ;
42
48
43
49
// Minimal alignment of the shadow base address. Determines the space available
44
50
// for threads and stack histories. This is an ABI constant.
@@ -50,7 +56,7 @@ const unsigned kRecordFPLShift = 4;
50
56
const unsigned kRecordFPModulus = 1 << (64 - kRecordFPShift + kRecordFPLShift );
51
57
52
58
static inline tag_t GetTagFromPointer (uptr p) {
53
- return p >> kAddressTagShift ;
59
+ return ( p >> kAddressTagShift ) & kTagMask ;
54
60
}
55
61
56
62
static inline uptr UntagAddr (uptr tagged_addr) {
Original file line number Diff line number Diff line change @@ -113,18 +113,21 @@ static u32 xorshift(u32 state) {
113
113
}
114
114
115
115
// Generate a (pseudo-)random non-zero tag.
116
- tag_t Thread::GenerateRandomTag () {
116
+ tag_t Thread::GenerateRandomTag (uptr num_bits) {
117
+ DCHECK_GT (num_bits, 0 );
117
118
if (tagging_disabled_) return 0 ;
118
119
tag_t tag;
120
+ const uptr tag_mask = (1ULL << num_bits) - 1 ;
119
121
do {
120
122
if (flags ()->random_tags ) {
121
123
if (!random_buffer_)
122
124
random_buffer_ = random_state_ = xorshift (random_state_);
123
125
CHECK (random_buffer_);
124
- tag = random_buffer_ & 0xFF ;
125
- random_buffer_ >>= 8 ;
126
+ tag = random_buffer_ & tag_mask ;
127
+ random_buffer_ >>= num_bits ;
126
128
} else {
127
- tag = random_state_ = (random_state_ + 1 ) & 0xFF ;
129
+ random_state_ += 1 ;
130
+ tag = random_state_ & tag_mask;
128
131
}
129
132
} while (!tag);
130
133
return tag;
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class Thread {
42
42
HeapAllocationsRingBuffer *heap_allocations () { return heap_allocations_; }
43
43
StackAllocationsRingBuffer *stack_allocations () { return stack_allocations_; }
44
44
45
- tag_t GenerateRandomTag ();
45
+ tag_t GenerateRandomTag (uptr num_bits = kTagBits );
46
46
47
47
void DisableTagging () { tagging_disabled_++; }
48
48
void EnableTagging () { tagging_disabled_--; }
You can’t perform that action at this time.
0 commit comments