[PATCH] D104402: [scudo] Ensure proper allocator alignment in TSD test

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 16 10:52:34 PDT 2021


cryptoad created this revision.
cryptoad added reviewers: vitalybuka, pcc, hctim, cferris, yroux.
cryptoad requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

The `MockAllocator` used in `ScudoTSDTest` wasn't allocated
properly aligned, which resulted in the `TSDs` of the shared
registry not being aligned either. This lead to some failures
like: https://reviews.llvm.org/D103119#2822008

This changes how the `MockAllocator` is allocated, same as
Vitaly did in the combined tests, properly aligning it, which
results in the `TSDs` being aligned as well.

Add a `DCHECK` in the shared registry to check that it is.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104402

Files:
  compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
  compiler-rt/lib/scudo/standalone/tsd_shared.h


Index: compiler-rt/lib/scudo/standalone/tsd_shared.h
===================================================================
--- compiler-rt/lib/scudo/standalone/tsd_shared.h
+++ compiler-rt/lib/scudo/standalone/tsd_shared.h
@@ -154,6 +154,8 @@
     initOnceMaybe(Instance);
     // Initial context assignment is done in a plain round-robin fashion.
     const u32 Index = atomic_fetch_add(&CurrentIndex, 1U, memory_order_relaxed);
+    DCHECK(isAligned(reinterpret_cast<uptr>(&TSDs[Index % NumberOfTSDs]),
+                     SCUDO_CACHE_LINE_SIZE));
     setCurrentTSD(&TSDs[Index % NumberOfTSDs]);
     Instance->callPostInitCallback();
   }
Index: compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
===================================================================
--- compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
+++ compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
@@ -40,6 +40,13 @@
 
   bool isInitialized() { return Initialized; }
 
+  void *operator new(size_t Size) {
+    void *P = nullptr;
+    EXPECT_EQ(0, posix_memalign(&P, alignof(ThisT), Size));
+    return P;
+  }
+  void operator delete(void *P) { free(P); }
+
 private:
   bool Initialized = false;
   TSDRegistryT TSDRegistry;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104402.352481.patch
Type: text/x-patch
Size: 1211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210616/256ed26d/attachment.bin>


More information about the llvm-commits mailing list