[platform] Check for failure of DiscardSystemPages

The {madvise} call should typically not fail.
There are only two errors specified (EINVAL and ENOMEM), both of which
would only happen for invalid parameters.

Thus add a CHECK that the {madvise} call does not fail.

R=mlippautz@chromium.org

Bug: chromium:1403519
Change-Id: Ib8c7ca9bbcab921b89305f1614319ecaddd79812
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4124534
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85054}
This commit is contained in:
Clemens Backes 2023-01-02 13:42:25 +01:00 committed by V8 LUCI CQ
parent f23a3ecccf
commit 6ace5cfb51

View File

@ -505,8 +505,9 @@ bool OS::SetPermissions(void* address, size_t size, MemoryPermission access) {
// TODO(erikchen): Fix this to only call MADV_FREE_REUSE when necessary. // TODO(erikchen): Fix this to only call MADV_FREE_REUSE when necessary.
// https://crbug.com/823915 // https://crbug.com/823915
#if defined(V8_OS_DARWIN) #if defined(V8_OS_DARWIN)
if (access != OS::MemoryPermission::kNoAccess) if (access != OS::MemoryPermission::kNoAccess) {
madvise(address, size, MADV_FREE_REUSE); madvise(address, size, MADV_FREE_REUSE);
}
#endif #endif
return ret == 0; return ret == 0;
@ -554,14 +555,19 @@ bool OS::DiscardSystemPages(void* address, size_t size) {
} }
#elif defined(_AIX) || defined(V8_OS_SOLARIS) #elif defined(_AIX) || defined(V8_OS_SOLARIS)
int ret = madvise(reinterpret_cast<caddr_t>(address), size, MADV_FREE); int ret = madvise(reinterpret_cast<caddr_t>(address), size, MADV_FREE);
if (ret != 0 && errno == ENOSYS) if (ret != 0 && errno == ENOSYS) {
return true; // madvise is not available on all systems. return true; // madvise is not available on all systems.
if (ret != 0 && errno == EINVAL) }
if (ret != 0 && errno == EINVAL) {
ret = madvise(reinterpret_cast<caddr_t>(address), size, MADV_DONTNEED); ret = madvise(reinterpret_cast<caddr_t>(address), size, MADV_DONTNEED);
}
#else #else
int ret = madvise(address, size, MADV_DONTNEED); int ret = madvise(address, size, MADV_DONTNEED);
#endif #endif
return ret == 0; // madvise with MADV_DONTNEED only fails on illegal parameters. That's a bug
// in the caller.
CHECK_EQ(0, ret);
return true;
} }
#if !defined(_AIX) #if !defined(_AIX)