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

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 13:37:15 PST 2024


================
@@ -122,18 +122,35 @@ bool mapSecondary(const Options &Options, uptr CommitBase, uptr CommitSize,
   Flags |= MAP_RESIZABLE;
   Flags |= MAP_ALLOWNOMEM;
 
-  const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * getPageSizeCached();
+  const uptr PageSize = getPageSizeCached();
+  const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * PageSize;
   if (useMemoryTagging<Config>(Options) && CommitSize > MaxUnusedCacheBytes) {
-    const uptr UntaggedPos = Max(AllocPos, CommitBase + MaxUnusedCacheBytes);
-    return MemMap.remap(CommitBase, UntaggedPos - CommitBase, "scudo:secondary",
-                        MAP_MEMTAG | Flags) &&
-           MemMap.remap(UntaggedPos, CommitBase + CommitSize - UntaggedPos,
-                        "scudo:secondary", Flags);
-  } else {
-    const uptr RemapFlags =
-        (useMemoryTagging<Config>(Options) ? MAP_MEMTAG : 0) | Flags;
-    return MemMap.remap(CommitBase, CommitSize, "scudo:secondary", RemapFlags);
+    if (SCUDO_TRUSTY) {
+      /*
----------------
ChiaHungDuan wrote:

It's better to separate the logic. I.e.

```
if (SCUDO_TRUSTY) {
  // all the logic for trusty  
}

// all the others
if (useMemoryTagging<Config>(Options) && CommitSize > MaxUnusedCacheBytes) {
  // ...
} else {
  // ...
}
```

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


More information about the llvm-commits mailing list