diff options
Diffstat (limited to 'deps/v8/src/base/platform/platform-posix.cc')
-rw-r--r-- | deps/v8/src/base/platform/platform-posix.cc | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/deps/v8/src/base/platform/platform-posix.cc b/deps/v8/src/base/platform/platform-posix.cc index d37b6219d4..40e870a346 100644 --- a/deps/v8/src/base/platform/platform-posix.cc +++ b/deps/v8/src/base/platform/platform-posix.cc @@ -444,8 +444,8 @@ void OS::Free(void* address, size_t size) { CHECK_EQ(0, munmap(address, size)); } -// macOS specific implementation in platform-macos.cc. -#if !defined(V8_OS_MACOS) +// Darwin specific implementation in platform-darwin.cc. +#if !defined(V8_OS_DARWIN) // static void* OS::AllocateShared(void* hint, size_t size, MemoryPermission access, PlatformSharedMemoryHandle handle, uint64_t offset) { @@ -456,7 +456,7 @@ void* OS::AllocateShared(void* hint, size_t size, MemoryPermission access, if (result == MAP_FAILED) return nullptr; return result; } -#endif // !defined(V8_OS_MACOS) +#endif // !defined(V8_OS_DARWIN) // static void OS::FreeShared(void* address, size_t size) { @@ -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. // https://crbug.com/823915 #if defined(V8_OS_DARWIN) - if (access != OS::MemoryPermission::kNoAccess) + if (access != OS::MemoryPermission::kNoAccess) { madvise(address, size, MADV_FREE_REUSE); + } #endif return ret == 0; @@ -554,14 +555,19 @@ bool OS::DiscardSystemPages(void* address, size_t size) { } #elif defined(_AIX) || defined(V8_OS_SOLARIS) 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. - if (ret != 0 && errno == EINVAL) + } + if (ret != 0 && errno == EINVAL) { ret = madvise(reinterpret_cast<caddr_t>(address), size, MADV_DONTNEED); + } #else int ret = madvise(address, size, MADV_DONTNEED); #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) @@ -576,9 +582,14 @@ bool OS::DecommitPages(void* address, size_t size) { // shall be removed, as if by an appropriate call to munmap(), before the new // mapping is established." As a consequence, the memory will be // zero-initialized on next access. - void* ptr = mmap(address, size, PROT_NONE, + void* ret = mmap(address, size, PROT_NONE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - return ptr == address; + if (V8_UNLIKELY(ret == MAP_FAILED)) { + CHECK_EQ(ENOMEM, errno); + return false; + } + CHECK_EQ(ret, address); + return true; } #endif // !defined(_AIX) @@ -612,8 +623,8 @@ void OS::FreeAddressSpaceReservation(AddressSpaceReservation reservation) { Free(reservation.base(), reservation.size()); } -// macOS specific implementation in platform-macos.cc. -#if !defined(V8_OS_MACOS) +// Darwin specific implementation in platform-darwin.cc. +#if !defined(V8_OS_DARWIN) // static // Need to disable CFI_ICALL due to the indirect call to memfd_create. DISABLE_CFI_ICALL @@ -646,7 +657,7 @@ void OS::DestroySharedMemoryHandle(PlatformSharedMemoryHandle handle) { int fd = FileDescriptorFromSharedMemoryHandle(handle); CHECK_EQ(0, close(fd)); } -#endif // !defined(V8_OS_MACOS) +#endif // !defined(V8_OS_DARWIN) // static bool OS::HasLazyCommits() { @@ -1004,8 +1015,8 @@ bool AddressSpaceReservation::Free(void* address, size_t size) { return OS::DecommitPages(address, size); } -// macOS specific implementation in platform-macos.cc. -#if !defined(V8_OS_MACOS) +// Darwin specific implementation in platform-darwin.cc. +#if !defined(V8_OS_DARWIN) bool AddressSpaceReservation::AllocateShared(void* address, size_t size, OS::MemoryPermission access, PlatformSharedMemoryHandle handle, @@ -1016,7 +1027,7 @@ bool AddressSpaceReservation::AllocateShared(void* address, size_t size, return mmap(address, size, prot, MAP_SHARED | MAP_FIXED, fd, offset) != MAP_FAILED; } -#endif // !defined(V8_OS_MACOS) +#endif // !defined(V8_OS_DARWIN) bool AddressSpaceReservation::FreeShared(void* address, size_t size) { DCHECK(Contains(address, size)); @@ -1230,7 +1241,7 @@ void Thread::SetThreadLocal(LocalStorageKey key, void* value) { !defined(V8_OS_SOLARIS) // static -Stack::StackSlot Stack::GetStackStart() { +Stack::StackSlot Stack::ObtainCurrentThreadStackStart() { pthread_attr_t attr; int error = pthread_getattr_np(pthread_self(), &attr); if (!error) { |