|
10 | 10 |
|
11 | 11 | #if SCUDO_LINUX
|
12 | 12 |
|
13 |
| -#include "atomic_helpers.h" |
14 | 13 | #include "common.h"
|
15 | 14 | #include "linux.h"
|
16 | 15 | #include "mutex.h"
|
@@ -90,41 +89,10 @@ void setMemoryPermission(uptr Addr, uptr Size, uptr Flags,
|
90 | 89 | dieOnMapUnmapError();
|
91 | 90 | }
|
92 | 91 |
|
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 |
| - |
119 | 92 | void releasePagesToOS(uptr BaseAddress, uptr Offset, uptr Size,
|
120 | 93 | UNUSED MapPlatformData *Data) {
|
121 | 94 | 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 | + |
128 | 96 | while (madvise(Addr, Size, MADV_DONTNEED) == -1 && errno == EAGAIN) {
|
129 | 97 | }
|
130 | 98 | }
|
|
0 commit comments