Skip to content

Commit 7563bd9

Browse files
author
git apple-llvm automerger
committed
Merge commit '4458e8c4b42f' from llvm.org/main into apple/main
2 parents 6fffb2c + 4458e8c commit 7563bd9

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

compiler-rt/lib/scudo/standalone/linux.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#if SCUDO_LINUX
1212

13-
#include "atomic_helpers.h"
1413
#include "common.h"
1514
#include "linux.h"
1615
#include "mutex.h"
@@ -90,41 +89,10 @@ void setMemoryPermission(uptr Addr, uptr Size, uptr Flags,
9089
dieOnMapUnmapError();
9190
}
9291

93-
static bool madviseNotNeedFails() {
94-
const uptr Size = getPageSizeCached();
95-
char *P = reinterpret_cast<char *>(mmap(0, Size, PROT_READ | PROT_WRITE,
96-
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
97-
if (!P)
98-
dieOnMapUnmapError(errno == ENOMEM ? Size : 0);
99-
*P = 1;
100-
while (madvise(P, Size, MADV_DONTNEED) == -1 && errno == EAGAIN) {
101-
}
102-
const bool R = (*P != 0);
103-
if (munmap(P, Size) != 0)
104-
dieOnMapUnmapError();
105-
return R;
106-
}
107-
108-
static bool madviseNotNeedFailsCached() {
109-
static atomic_u8 Cache;
110-
enum State : u8 { Unknown = 0, Yes = 1, No = 2 };
111-
State NeedsMemset = static_cast<State>(atomic_load_relaxed(&Cache));
112-
if (NeedsMemset == Unknown) {
113-
NeedsMemset = madviseNotNeedFails() ? Yes : No;
114-
atomic_store_relaxed(&Cache, NeedsMemset);
115-
}
116-
return NeedsMemset == Yes;
117-
}
118-
11992
void releasePagesToOS(uptr BaseAddress, uptr Offset, uptr Size,
12093
UNUSED MapPlatformData *Data) {
12194
void *Addr = reinterpret_cast<void *>(BaseAddress + Offset);
122-
if (madviseNotNeedFailsCached()) {
123-
// Workaround for QEMU-user ignoring MADV_DONTNEED.
124-
// https://github.com/qemu/qemu/blob/b1cffefa1b163bce9aebc3416f562c1d3886eeaa/linux-user/syscall.c#L11941
125-
// https://bugs.launchpad.net/qemu/+bug/1926521
126-
memset(Addr, 0, Size);
127-
}
95+
12896
while (madvise(Addr, Size, MADV_DONTNEED) == -1 && errno == EAGAIN) {
12997
}
13098
}

0 commit comments

Comments
 (0)