Skip to content

Commit 39e8137

Browse files
authored
[NFC] [HWASan] add example for ring buffer wrap (#87029)
Also another move comment to correct place.
1 parent 01e02e0 commit 39e8137

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,6 @@ void HWAddressSanitizer::tagAlloca(IRBuilder<> &IRB, AllocaInst *AI, Value *Tag,
11141114
// FIXME: the interceptor is not as fast as real memset. Consider lowering
11151115
// llvm.memset right here into either a sequence of stores, or a call to
11161116
// hwasan_tag_memory.
1117-
// Mechanical proof of this address calculation can be found at:
1118-
// https://github.com/google/sanitizers/blob/master/hwaddress-sanitizer/prove_hwasanwrap.smt2
11191117
if (ShadowSize)
11201118
IRB.CreateMemSet(ShadowPtr, Tag, ShadowSize, Align(1));
11211119
if (Size != AlignedSize) {
@@ -1312,6 +1310,22 @@ void HWAddressSanitizer::emitPrologue(IRBuilder<> &IRB, bool WithFrameRecord) {
13121310
// The use of AShr instead of LShr is due to
13131311
// https://bugs.llvm.org/show_bug.cgi?id=39030
13141312
// Runtime library makes sure not to use the highest bit.
1313+
//
1314+
// Mechanical proof of this address calculation can be found at:
1315+
// https://github.com/google/sanitizers/blob/master/hwaddress-sanitizer/prove_hwasanwrap.smt2
1316+
//
1317+
// Example of the wrap case for N = 1
1318+
// Pointer: 0x01AAAAAAAAAAAFF8
1319+
// +
1320+
// 0x0000000000000008
1321+
// =
1322+
// 0x01AAAAAAAAAAB000
1323+
// &
1324+
// WrapMask: 0xFFFFFFFFFFFFF000
1325+
// =
1326+
// 0x01AAAAAAAAAAA000
1327+
//
1328+
// Then the WrapMask will be a no-op until the next wrap case.
13151329
Value *WrapMask = IRB.CreateXor(
13161330
IRB.CreateShl(IRB.CreateAShr(ThreadLong, 56), 12, "", true, true),
13171331
ConstantInt::get(IntptrTy, (uint64_t)-1));

0 commit comments

Comments
 (0)