[compiler-rt] [scudo] Avoid splitting aligned allocations on Trusty (PR #69281)
Andrei Homescu via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 14:48: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) {
+ /*
+ * On Trusty we need AllocPos to be usable for memrefs, 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 (TaggedSize != 0 && isAligned(TaggedSize, PageSize)) {
----------------
ahomescu wrote:
`mapSecondary` is called with `AllocPos == CommitBase` on line 215:
```
mapSecondary<Config>(Options, Entry.CommitBase, Entry.CommitSize,
Entry.CommitBase, MAP_NOACCESS, Entry.MemMap);
```
but I'm wondering if that code path is every used on Trusty. It's also disabled explicitly on Fuchsia, wondering if Trusty should do that too.
https://github.com/llvm/llvm-project/pull/69281
More information about the llvm-commits
mailing list