[compiler-rt] bf89531 - [scudo] Enabled MAP_ALLOWNOMEM for all platforms
Chia-hung Duan via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 25 08:29:47 PDT 2023
Author: Marco Nelissen
Date: 2023-07-25T15:25:26Z
New Revision: bf89531c418a62fbcdc084159e4a762930a2a571
URL: https://github.com/llvm/llvm-project/commit/bf89531c418a62fbcdc084159e4a762930a2a571
DIFF: https://github.com/llvm/llvm-project/commit/bf89531c418a62fbcdc084159e4a762930a2a571.diff
LOG: [scudo] Enabled MAP_ALLOWNOMEM for all platforms
Back-ported from https://r.android.com/2591905.
Reviewed By: Chia-hungDuan
Differential Revision: https://reviews.llvm.org/D152888
Added:
Modified:
compiler-rt/lib/scudo/standalone/secondary.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index 105b154b5de265..931805c4b29aeb 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -102,20 +102,22 @@ template <typename Config> class MapAllocatorNoCache {
static const uptr MaxUnusedCachePages = 4U;
template <typename Config>
-void mapSecondary(Options Options, uptr CommitBase, uptr CommitSize,
+bool mapSecondary(Options Options, uptr CommitBase, uptr CommitSize,
uptr AllocPos, uptr Flags, MemMapT &MemMap) {
+ Flags |= MAP_RESIZABLE;
+ Flags |= MAP_ALLOWNOMEM;
+
const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * getPageSizeCached();
if (useMemoryTagging<Config>(Options) && CommitSize > MaxUnusedCacheBytes) {
const uptr UntaggedPos = Max(AllocPos, CommitBase + MaxUnusedCacheBytes);
- MemMap.remap(CommitBase, UntaggedPos - CommitBase, "scudo:secondary",
- MAP_RESIZABLE | MAP_MEMTAG | Flags);
- MemMap.remap(UntaggedPos, CommitBase + CommitSize - UntaggedPos,
- "scudo:secondary", MAP_RESIZABLE | Flags);
+ return MemMap.remap(CommitBase, UntaggedPos - CommitBase, "scudo:secondary",
+ MAP_MEMTAG | Flags) &&
+ MemMap.remap(UntaggedPos, CommitBase + CommitSize - UntaggedPos,
+ "scudo:secondary", Flags);
} else {
const uptr RemapFlags =
- MAP_RESIZABLE | (useMemoryTagging<Config>(Options) ? MAP_MEMTAG : 0) |
- Flags;
- MemMap.remap(CommitBase, CommitSize, "scudo:secondary", RemapFlags);
+ (useMemoryTagging<Config>(Options) ? MAP_MEMTAG : 0) | Flags;
+ return MemMap.remap(CommitBase, CommitSize, "scudo:secondary", RemapFlags);
}
}
@@ -295,8 +297,7 @@ template <typename Config> class MapAllocatorCache {
} else if (Entry.BlockBegin < NewBlockBegin) {
storeTags(Entry.BlockBegin, NewBlockBegin);
} else {
- storeTags(untagPointer(NewBlockBegin),
- untagPointer(Entry.BlockBegin));
+ storeTags(untagPointer(NewBlockBegin), untagPointer(Entry.BlockBegin));
}
}
(*H)->CommitBase = Entry.CommitBase;
@@ -592,7 +593,11 @@ void *MapAllocator<Config>::allocate(Options Options, uptr Size, uptr Alignment,
const uptr CommitSize = MapEnd - PageSize - CommitBase;
const uptr AllocPos = roundDown(CommitBase + CommitSize - Size, Alignment);
- mapSecondary<Config>(Options, CommitBase, CommitSize, AllocPos, 0, MemMap);
+ if (!mapSecondary<Config>(Options, CommitBase, CommitSize, AllocPos, 0,
+ MemMap)) {
+ MemMap.unmap(MemMap.getBase(), MemMap.getCapacity());
+ return nullptr;
+ }
const uptr HeaderPos =
AllocPos - Chunk::getHeaderSize() - LargeBlock::getHeaderSize();
LargeBlock::Header *H = reinterpret_cast<LargeBlock::Header *>(
More information about the llvm-commits
mailing list