diff --git a/BUILD.bazel b/BUILD.bazel index 14c67173b1..9380cbb2cc 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -638,6 +638,7 @@ filegroup( "@v8//bazel/config:is_macos": [ "src/base/debug/stack_trace_posix.cc", "src/base/platform/platform-macos.cc", + "src/base/platform/platform-xnu.cc", ], "@v8//bazel/config:is_windows": [ "src/base/win32-headers.h", diff --git a/BUILD.gn b/BUILD.gn index c5d4b703ba..fb68d0ec4d 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -5183,6 +5183,7 @@ v8_component("v8_libbase") { sources += [ "src/base/debug/stack_trace_posix.cc", "src/base/platform/platform-macos.cc", + "src/base/platform/platform-xnu.cc", ] } else { sources += [ @@ -5206,10 +5207,16 @@ v8_component("v8_libbase") { "//third_party/fuchsia-sdk/sdk/pkg/fdio", "//third_party/fuchsia-sdk/sdk/pkg/zx", ] - } else if (is_mac || is_ios) { + } else if (is_mac) { sources += [ "src/base/debug/stack_trace_posix.cc", "src/base/platform/platform-macos.cc", + "src/base/platform/platform-xnu.cc", + ] + } else if (is_ios) { + sources += [ + "src/base/debug/stack_trace_posix.cc", + "src/base/platform/platform-xnu.cc", ] } else if (is_win) { # TODO(infra): Add support for cygwin. diff --git a/include/v8-platform.h b/include/v8-platform.h index 14acbf3f9c..2decd2088b 100644 --- a/include/v8-platform.h +++ b/include/v8-platform.h @@ -522,7 +522,7 @@ static constexpr PlatformSharedMemoryHandle kInvalidSharedMemoryHandle = -1; // to avoid pulling in large OS header files into this header file. Instead, // the users of these routines are expected to include the respecitve OS // headers in addition to this one. -#if V8_OS_MACOSX +#if defined(V8_OS_MACOSX) && !defined(V8_OS_IOS) // Convert between a shared memory handle and a mach_port_t referencing a memory // entry object. inline PlatformSharedMemoryHandle SharedMemoryHandleFromMachMemoryEntry( @@ -533,7 +533,7 @@ inline unsigned int MachMemoryEntryFromSharedMemoryHandle( PlatformSharedMemoryHandle handle) { return static_cast(handle); } -#elif V8_OS_FUCHSIA +#elif defined(V8_OS_FUCHSIA) // Convert between a shared memory handle and a zx_handle_t to a VMO. inline PlatformSharedMemoryHandle SharedMemoryHandleFromVMO(uint32_t handle) { return static_cast(handle); @@ -541,7 +541,7 @@ inline PlatformSharedMemoryHandle SharedMemoryHandleFromVMO(uint32_t handle) { inline uint32_t VMOFromSharedMemoryHandle(PlatformSharedMemoryHandle handle) { return static_cast(handle); } -#elif V8_OS_WIN +#elif defined(V8_OS_WIN) // Convert between a shared memory handle and a Windows HANDLE to a file mapping // object. inline PlatformSharedMemoryHandle SharedMemoryHandleFromFileMapping( diff --git a/src/base/platform/platform-macos.cc b/src/base/platform/platform-macos.cc index b09d1cbac4..4864beda7a 100644 --- a/src/base/platform/platform-macos.cc +++ b/src/base/platform/platform-macos.cc @@ -2,103 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Platform-specific code for MacOS goes here. For the POSIX-compatible -// parts, the implementation is in platform-posix.cc. +// Platform-specific code for MacOS goes here. Code shared between iOS and +// macOS is in platform-xnu.cc, while the POSIX-compatible are in in +// platform-posix.cc. -#include -#include -#include -#include -#include -#include #include -#include #include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#undef MAP_TYPE - -#include "src/base/macros.h" -#include "src/base/platform/platform-posix-time.h" -#include "src/base/platform/platform-posix.h" #include "src/base/platform/platform.h" namespace v8 { namespace base { -std::vector OS::GetSharedLibraryAddresses() { - std::vector result; - unsigned int images_count = _dyld_image_count(); - for (unsigned int i = 0; i < images_count; ++i) { - const mach_header* header = _dyld_get_image_header(i); - if (header == nullptr) continue; -#if V8_HOST_ARCH_I32 - unsigned int size; - char* code_ptr = getsectdatafromheader(header, SEG_TEXT, SECT_TEXT, &size); -#else - uint64_t size; - char* code_ptr = getsectdatafromheader_64( - reinterpret_cast(header), SEG_TEXT, SECT_TEXT, - &size); -#endif - if (code_ptr == nullptr) continue; - const intptr_t slide = _dyld_get_image_vmaddr_slide(i); - const uintptr_t start = reinterpret_cast(code_ptr) + slide; - result.push_back(SharedLibraryAddress(_dyld_get_image_name(i), start, - start + size, slide)); - } - return result; -} - -void OS::SignalCodeMovingGC() {} - -TimezoneCache* OS::CreateTimezoneCache() { - return new PosixDefaultTimezoneCache(); -} - -void OS::AdjustSchedulingParams() { -#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 - { - // Check availability of scheduling params. - uint32_t val = 0; - size_t valSize = sizeof(val); - int rc = sysctlbyname("kern.tcsm_available", &val, &valSize, NULL, 0); - if (rc < 0 || !val) return; - } - - { - // Adjust scheduling params. - uint32_t val = 1; - int rc = sysctlbyname("kern.tcsm_enable", NULL, NULL, &val, sizeof(val)); - DCHECK_GE(rc, 0); - USE(rc); - } -#endif -} - -std::vector OS::GetFreeMemoryRangesWithin( - OS::Address boundary_start, OS::Address boundary_end, size_t minimum_size, - size_t alignment) { - return {}; -} - namespace { vm_prot_t GetVMProtFromMemoryPermission(OS::MemoryPermission access) { @@ -186,10 +102,5 @@ bool AddressSpaceReservation::AllocateShared(void* address, size_t size, return kr == KERN_SUCCESS; } -// static -Stack::StackSlot Stack::GetStackStart() { - return pthread_get_stackaddr_np(pthread_self()); -} - } // namespace base } // namespace v8 diff --git a/src/base/platform/platform-posix.cc b/src/base/platform/platform-posix.cc index b84eff3d0b..76907a6248 100644 --- a/src/base/platform/platform-posix.cc +++ b/src/base/platform/platform-posix.cc @@ -435,7 +435,7 @@ bool OS::Free(void* address, size_t size) { } // macOS specific implementation in platform-macos.cc. -#if !defined(V8_OS_MACOSX) +#if !defined(V8_OS_MACOSX) || defined(V8_OS_IOS) // static void* OS::AllocateShared(void* hint, size_t size, MemoryPermission access, PlatformSharedMemoryHandle handle, uint64_t offset) { @@ -446,7 +446,7 @@ void* OS::AllocateShared(void* hint, size_t size, MemoryPermission access, if (result == MAP_FAILED) return nullptr; return result; } -#endif // !defined(V8_OS_MACOSX) +#endif // !defined(V8_OS_MACOSX) || defined(V8_OS_IOS) // static bool OS::FreeShared(void* address, size_t size) { @@ -573,7 +573,7 @@ bool OS::FreeAddressSpaceReservation(AddressSpaceReservation reservation) { } // macOS specific implementation in platform-macos.cc. -#if !defined(V8_OS_MACOSX) +#if !defined(V8_OS_MACOSX) || defined(V8_OS_IOS) // static PlatformSharedMemoryHandle OS::CreateSharedMemoryHandleForTesting(size_t size) { #if V8_OS_LINUX && !V8_OS_ANDROID @@ -594,7 +594,7 @@ void OS::DestroySharedMemoryHandle(PlatformSharedMemoryHandle handle) { int fd = FileDescriptorFromSharedMemoryHandle(handle); CHECK_EQ(0, close(fd)); } -#endif // !defined(V8_OS_MACOSX) +#endif // !defined(V8_OS_MACOSX) || defined(V8_OS_IOS) // static bool OS::HasLazyCommits() { @@ -951,7 +951,7 @@ bool AddressSpaceReservation::Free(void* address, size_t size) { } // macOS specific implementation in platform-macos.cc. -#if !defined(V8_OS_MACOSX) +#if !defined(V8_OS_MACOSX) || defined(V8_OS_IOS) bool AddressSpaceReservation::AllocateShared(void* address, size_t size, OS::MemoryPermission access, PlatformSharedMemoryHandle handle, @@ -962,7 +962,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_MACOSX) +#endif // !defined(V8_OS_MACOSX) || defined(V8_OS_IOS) bool AddressSpaceReservation::FreeShared(void* address, size_t size) { DCHECK(Contains(address, size)); diff --git a/src/base/platform/platform-xnu.cc b/src/base/platform/platform-xnu.cc new file mode 100644 index 0000000000..bf360e3136 --- /dev/null +++ b/src/base/platform/platform-xnu.cc @@ -0,0 +1,107 @@ +// Copyright 2012 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Platform-specific code shared between macOS and iOS goes here. The macOS +// specific part is in platform-macos.cc, the POSIX-compatible parts in +// platform-posix.cc. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#undef MAP_TYPE + +#include "src/base/macros.h" +#include "src/base/platform/platform-posix-time.h" +#include "src/base/platform/platform-posix.h" +#include "src/base/platform/platform.h" + +namespace v8 { +namespace base { + +std::vector OS::GetSharedLibraryAddresses() { + std::vector result; + unsigned int images_count = _dyld_image_count(); + for (unsigned int i = 0; i < images_count; ++i) { + const mach_header* header = _dyld_get_image_header(i); + if (header == nullptr) continue; +#if V8_HOST_ARCH_I32 + unsigned int size; + char* code_ptr = getsectdatafromheader(header, SEG_TEXT, SECT_TEXT, &size); +#else + uint64_t size; + char* code_ptr = getsectdatafromheader_64( + reinterpret_cast(header), SEG_TEXT, SECT_TEXT, + &size); +#endif + if (code_ptr == nullptr) continue; + const intptr_t slide = _dyld_get_image_vmaddr_slide(i); + const uintptr_t start = reinterpret_cast(code_ptr) + slide; + result.push_back(SharedLibraryAddress(_dyld_get_image_name(i), start, + start + size, slide)); + } + return result; +} + +void OS::SignalCodeMovingGC() {} + +TimezoneCache* OS::CreateTimezoneCache() { + return new PosixDefaultTimezoneCache(); +} + +void OS::AdjustSchedulingParams() { +#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 + { + // Check availability of scheduling params. + uint32_t val = 0; + size_t valSize = sizeof(val); + int rc = sysctlbyname("kern.tcsm_available", &val, &valSize, NULL, 0); + if (rc < 0 || !val) return; + } + + { + // Adjust scheduling params. + uint32_t val = 1; + int rc = sysctlbyname("kern.tcsm_enable", NULL, NULL, &val, sizeof(val)); + DCHECK_GE(rc, 0); + USE(rc); + } +#endif +} + +std::vector OS::GetFreeMemoryRangesWithin( + OS::Address boundary_start, OS::Address boundary_end, size_t minimum_size, + size_t alignment) { + return {}; +} + +// static +Stack::StackSlot Stack::GetStackStart() { + return pthread_get_stackaddr_np(pthread_self()); +} + +} // namespace base +} // namespace v8