Commit ccc68901 authored by Samuel Groß's avatar Samuel Groß Committed by V8 LUCI CQ

[base] Fix iOS build after AllocateSharedPages introduction

The new shared memory API should only be used on macOS, but
platform-macos.cc was also included on iOS, causing build failures. This
CL splits platform-macos.cc into platform-xnu.cc (common code for macOS
and iOS) and platform-macos.cc (the macOS specific parts)

Bug: chromium:1218005
Change-Id: Iab332865ffd8990ddd246bb9c08802909464d7e6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3468895Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Samuel Groß <saelo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79131}
parent 41308344
......@@ -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",
......
......@@ -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.
......
......@@ -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<unsigned int>(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<PlatformSharedMemoryHandle>(handle);
......@@ -541,7 +541,7 @@ inline PlatformSharedMemoryHandle SharedMemoryHandleFromVMO(uint32_t handle) {
inline uint32_t VMOFromSharedMemoryHandle(PlatformSharedMemoryHandle handle) {
return static_cast<uint32_t>(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(
......
......@@ -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.
#include <AvailabilityMacros.h>
#include <dlfcn.h>
#include <errno.h>
#include <libkern/OSAtomic.h>
#include <mach-o/dyld.h>
#include <mach-o/getsect.h>
// 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 <mach/mach.h>
#include <mach/mach_init.h>
#include <mach/mach_vm.h>
#include <mach/semaphore.h>
#include <mach/task.h>
#include <mach/vm_map.h>
#include <mach/vm_statistics.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <cmath>
#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::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> 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<const mach_header_64*>(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<uintptr_t>(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::MemoryRange> 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
......@@ -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));
......
// 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 <AvailabilityMacros.h>
#include <dlfcn.h>
#include <errno.h>
#include <libkern/OSAtomic.h>
#include <mach-o/dyld.h>
#include <mach-o/getsect.h>
#include <mach/mach.h>
#include <mach/mach_init.h>
#include <mach/semaphore.h>
#include <mach/task.h>
#include <mach/vm_statistics.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <cmath>
#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::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> 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<const mach_header_64*>(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<uintptr_t>(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::MemoryRange> 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment