[compiler-rt] [scudo] Avoid splitting aligned allocations on Trusty (PR #69281)

Andrei Homescu via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 15:59:15 PST 2024


================
@@ -122,7 +122,28 @@ bool mapSecondary(const Options &Options, uptr CommitBase, uptr CommitSize,
   Flags |= MAP_RESIZABLE;
   Flags |= MAP_ALLOWNOMEM;
 
-  const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * getPageSizeCached();
+  const uptr PageSize = getPageSizeCached();
+  if (SCUDO_TRUSTY) {
+    /*
+     * On Trusty we need AllocPos to be usable for shared memory, which cannot
+     * cross multiple mappings. This means we need to split around AllocPos
+     * and not over it. We can only do this if the address is page-aligned.
+     */
+    const uptr TaggedSize = AllocPos - CommitBase;
+    if (useMemoryTagging<Config>(Options) && isAligned(TaggedSize, PageSize)) {
+      return MemMap.remap(CommitBase, TaggedSize, "scudo:secondary",
+                          MAP_MEMTAG | Flags) &&
+             MemMap.remap(AllocPos, CommitSize - TaggedSize, "scudo:secondary",
+                          Flags);
+    } else {
+      const uptr RemapFlags =
+          (useMemoryTagging<Config>(Options) ? MAP_MEMTAG : 0) | Flags;
+      return MemMap.remap(CommitBase, CommitSize, "scudo:secondary",
+                          RemapFlags);
+    }
+  }
----------------
ahomescu wrote:

Oh I see. IMHO we still want to do something different on Trusty, since breaking allocations into two like that (first 3-4 pages, then the rest) means we can't use them for shared memory.

Trusty could have its own threshold where allocations below that size get the two tags, while larger ones have tagging disabled. 

https://github.com/llvm/llvm-project/pull/69281


More information about the llvm-commits mailing list