[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 14:22:48 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8b062b616062: [scudo] Ensure proper allocator alignment in TSD test (authored by cryptoad).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104402/new/

https://reviews.llvm.org/D104402

Files:
  compiler-rt/lib/scudo/standalone/primary32.h
  compiler-rt/lib/scudo/standalone/primary64.h
  compiler-rt/lib/scudo/standalone/quarantine.h
  compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
  compiler-rt/lib/scudo/standalone/tsd.h


Index: compiler-rt/lib/scudo/standalone/tsd.h
===================================================================
--- compiler-rt/lib/scudo/standalone/tsd.h
+++ compiler-rt/lib/scudo/standalone/tsd.h
@@ -26,10 +26,12 @@
 template <class Allocator> struct alignas(SCUDO_CACHE_LINE_SIZE) TSD {
   typename Allocator::CacheT Cache;
   typename Allocator::QuarantineCacheT QuarantineCache;
+  using ThisT = TSD<Allocator>;
   u8 DestructorIterations = 0;
 
   void init(Allocator *Instance) {
     DCHECK_EQ(DestructorIterations, 0U);
+    DCHECK(isAligned(reinterpret_cast<uptr>(this), alignof(ThisT)));
     Instance->initCache(&Cache);
     DestructorIterations = PTHREAD_DESTRUCTOR_ITERATIONS;
   }
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
@@ -11,6 +11,8 @@
 #include "tsd_exclusive.h"
 #include "tsd_shared.h"
 
+#include <stdlib.h>
+
 #include <condition_variable>
 #include <mutex>
 #include <set>
@@ -40,6 +42,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;
Index: compiler-rt/lib/scudo/standalone/quarantine.h
===================================================================
--- compiler-rt/lib/scudo/standalone/quarantine.h
+++ compiler-rt/lib/scudo/standalone/quarantine.h
@@ -170,8 +170,10 @@
 template <typename Callback, typename Node> class GlobalQuarantine {
 public:
   typedef QuarantineCache<Callback> CacheT;
+  using ThisT = GlobalQuarantine<Callback, Node>;
 
   void init(uptr Size, uptr CacheSize) {
+    DCHECK(isAligned(reinterpret_cast<uptr>(this), alignof(ThisT)));
     DCHECK_EQ(atomic_load_relaxed(&MaxSize), 0U);
     DCHECK_EQ(atomic_load_relaxed(&MinSize), 0U);
     DCHECK_EQ(atomic_load_relaxed(&MaxCacheSize), 0U);
Index: compiler-rt/lib/scudo/standalone/primary64.h
===================================================================
--- compiler-rt/lib/scudo/standalone/primary64.h
+++ compiler-rt/lib/scudo/standalone/primary64.h
@@ -59,6 +59,7 @@
   static bool canAllocate(uptr Size) { return Size <= SizeClassMap::MaxSize; }
 
   void init(s32 ReleaseToOsInterval) {
+    DCHECK(isAligned(reinterpret_cast<uptr>(this), alignof(ThisT)));
     DCHECK_EQ(PrimaryBase, 0U);
     // Reserve the space required for the Primary.
     PrimaryBase = reinterpret_cast<uptr>(
Index: compiler-rt/lib/scudo/standalone/primary32.h
===================================================================
--- compiler-rt/lib/scudo/standalone/primary32.h
+++ compiler-rt/lib/scudo/standalone/primary32.h
@@ -67,8 +67,8 @@
     if (SCUDO_TRUSTY)
       reportError("SizeClassAllocator32 is not supported on Trusty");
 
+    DCHECK(isAligned(reinterpret_cast<uptr>(this), alignof(ThisT)));
     PossibleRegions.init();
-
     u32 Seed;
     const u64 Time = getMonotonicTime();
     if (!getRandom(reinterpret_cast<void *>(&Seed), sizeof(Seed)))


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


More information about the llvm-commits mailing list