From e7f818b8668a685b31c8177357ea3632acfc8c10 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Tue, 31 Mar 2026 19:59:09 -0700 Subject: [PATCH] [vm, fuchsia] Always look for VmexResource. TEST=ci Bug: https://dartbug.com/52579 Change-Id: I856fb8ae5a5bc282471c1ecf3774fc49f7c5b57a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491926 Commit-Queue: Ryan Macnak Reviewed-by: Liam Appelbe --- runtime/bin/BUILD.gn | 10 ++-------- runtime/bin/analyze_snapshot.cc | 3 --- runtime/bin/dartdev.cc | 3 --- runtime/bin/gen_snapshot.cc | 3 --- runtime/bin/main_impl.cc | 7 ------- runtime/bin/platform.h | 4 ---- runtime/bin/platform_fuchsia.cc | 15 --------------- runtime/bin/run_vm_tests.cc | 3 --- runtime/include/dart_api.h | 11 +---------- runtime/vm/BUILD.gn | 1 + runtime/vm/dart.cc | 4 ---- runtime/vm/virtual_memory.h | 4 ---- runtime/vm/virtual_memory_fuchsia.cc | 18 ++++++++++++++++-- 13 files changed, 20 insertions(+), 66 deletions(-) diff --git a/runtime/bin/BUILD.gn b/runtime/bin/BUILD.gn index a1a7bda2884..0eedc4279fc 100644 --- a/runtime/bin/BUILD.gn +++ b/runtime/bin/BUILD.gn @@ -446,10 +446,7 @@ template("build_gen_snapshot_dart_io") { deps = [ "//third_party/zlib" ] if (is_fuchsia) { - deps += [ - "$fuchsia_sdk/fidl/fuchsia.io", - "$fuchsia_sdk/fidl/fuchsia.kernel", - ] + deps += [ "$fuchsia_sdk/fidl/fuchsia.io" ] public_deps = [ "$fuchsia_sdk/pkg/fdio" ] } @@ -567,10 +564,7 @@ template("dart_io") { deps += [ "//third_party/boringssl" ] if (is_fuchsia) { - deps += [ - "$fuchsia_sdk/fidl/fuchsia.io", - "$fuchsia_sdk/fidl/fuchsia.kernel", - ] + deps += [ "$fuchsia_sdk/fidl/fuchsia.io" ] public_deps = [ "$fuchsia_sdk/pkg/fdio" ] } diff --git a/runtime/bin/analyze_snapshot.cc b/runtime/bin/analyze_snapshot.cc index eb77134d410..6b89a1fbef7 100644 --- a/runtime/bin/analyze_snapshot.cc +++ b/runtime/bin/analyze_snapshot.cc @@ -189,9 +189,6 @@ int RunAnalyzer(int argc, char** argv) { init_params.file_write = DartUtils::WriteFile; init_params.file_close = DartUtils::CloseFile; init_params.entropy_source = DartUtils::EntropySource; -#if defined(DART_HOST_OS_FUCHSIA) - init_params.vmex_resource = Platform::GetVMEXResource(); -#endif error = Dart_Initialize(&init_params); if (error != nullptr) { diff --git a/runtime/bin/dartdev.cc b/runtime/bin/dartdev.cc index 98295586926..2979ed7159e 100644 --- a/runtime/bin/dartdev.cc +++ b/runtime/bin/dartdev.cc @@ -1115,9 +1115,6 @@ void main(int argc, char** argv) { init_params.file_close = DartUtils::CloseFile; init_params.entropy_source = DartUtils::EntropySource; init_params.start_kernel_isolate = false; -#if defined(DART_HOST_OS_FUCHSIA) - init_params.vmex_resource = ZX_HANDLE_INVALID; -#endif error = Dart_Initialize(&init_params); if (error != nullptr) { diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc index b4cafce7dd8..ab04917dc5f 100644 --- a/runtime/bin/gen_snapshot.cc +++ b/runtime/bin/gen_snapshot.cc @@ -918,9 +918,6 @@ int main(int argc, char** argv) { init_params.file_close = DartUtils::CloseFile; init_params.entropy_source = DartUtils::EntropySource; init_params.start_kernel_isolate = false; -#if defined(DART_HOST_OS_FUCHSIA) - init_params.vmex_resource = Platform::GetVMEXResource(); -#endif std::unique_ptr mapped_vm_snapshot_data; std::unique_ptr mapped_vm_snapshot_instructions; diff --git a/runtime/bin/main_impl.cc b/runtime/bin/main_impl.cc index ff554818407..e9a8add77dd 100644 --- a/runtime/bin/main_impl.cc +++ b/runtime/bin/main_impl.cc @@ -1384,13 +1384,6 @@ void main(int argc, char** argv) { dfe.UseDartFrontend() && dfe.CanUseDartFrontend(); #else init_params.start_kernel_isolate = false; -#endif -#if defined(DART_HOST_OS_FUCHSIA) -#if defined(DART_PRECOMPILED_RUNTIME) - init_params.vmex_resource = ZX_HANDLE_INVALID; -#else - init_params.vmex_resource = Platform::GetVMEXResource(); -#endif #endif error = Dart_Initialize(&init_params); diff --git a/runtime/bin/platform.h b/runtime/bin/platform.h index f0e8b1cf6f6..9c744d5fbae 100644 --- a/runtime/bin/platform.h +++ b/runtime/bin/platform.h @@ -110,10 +110,6 @@ class Platform { static void SetCoreDumpResourceLimit(int value); -#if defined(DART_HOST_OS_FUCHSIA) - static zx_handle_t GetVMEXResource(); -#endif - private: // The path to the executable. static const char* executable_name_; diff --git a/runtime/bin/platform_fuchsia.cc b/runtime/bin/platform_fuchsia.cc index 3a9bc4f30e3..428fa9caed3 100644 --- a/runtime/bin/platform_fuchsia.cc +++ b/runtime/bin/platform_fuchsia.cc @@ -7,9 +7,6 @@ #include "bin/platform.h" -#include -#include -#include #include #include #include @@ -170,18 +167,6 @@ void Platform::SetCoreDumpResourceLimit(int value) { // Not supported. } -zx_handle_t Platform::GetVMEXResource() { - zx::resource vmex_resource; - fuchsia::kernel::VmexResourceSyncPtr vmex_resource_svc; - zx_status_t status = fdio_service_connect( - "/svc/fuchsia.kernel.VmexResource", - vmex_resource_svc.NewRequest().TakeChannel().release()); - ASSERT(status == ZX_OK); - status = vmex_resource_svc->Get(&vmex_resource); - ASSERT(status == ZX_OK); - return vmex_resource.release(); -} - } // namespace bin } // namespace dart diff --git a/runtime/bin/run_vm_tests.cc b/runtime/bin/run_vm_tests.cc index 5bc2f56e823..d247f870dca 100644 --- a/runtime/bin/run_vm_tests.cc +++ b/runtime/bin/run_vm_tests.cc @@ -443,9 +443,6 @@ static int Main(int argc, const char** argv) { init_params.file_write = dart::bin::DartUtils::WriteFile; init_params.file_close = dart::bin::DartUtils::CloseFile; init_params.start_kernel_isolate = start_kernel_isolate; -#if defined(DART_HOST_OS_FUCHSIA) - init_params.vmex_resource = dart::bin::Platform::GetVMEXResource(); -#endif error = Dart::Init(&init_params); if (error != nullptr) { Syslog::PrintErr("Failed to initialize VM: %s\n", error); diff --git a/runtime/include/dart_api.h b/runtime/include/dart_api.h index b146d32bad1..46a01c3632a 100644 --- a/runtime/include/dart_api.h +++ b/runtime/include/dart_api.h @@ -837,7 +837,7 @@ typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)(void); * The current version of the Dart_InitializeFlags. Should be incremented every * time Dart_InitializeFlags changes in a binary incompatible way. */ -#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000009) +#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x0000000A) /** Forward declaration */ struct Dart_CodeObserver; @@ -942,15 +942,6 @@ typedef struct { * as early as during the Dart_Initialize() call. */ Dart_CodeObserver* code_observer; - -#if defined(__Fuchsia__) - /** - * The resource needed to use zx_vmo_replace_as_executable. Can be - * ZX_HANDLE_INVALID if the process has ambient-replace-as-executable or if - * executable memory is not needed (e.g., this is an AOT runtime). - */ - zx_handle_t vmex_resource; -#endif } Dart_InitializeParams; /** diff --git a/runtime/vm/BUILD.gn b/runtime/vm/BUILD.gn index d93c47ef4a8..39749fad158 100644 --- a/runtime/vm/BUILD.gn +++ b/runtime/vm/BUILD.gn @@ -84,6 +84,7 @@ library_for_all_configs("libdart_vm") { if (is_fuchsia) { extra_deps += [ "$fuchsia_sdk/fidl/fuchsia.intl", + "$fuchsia_sdk/fidl/fuchsia.kernel", "$fuchsia_sdk/pkg/async", "$fuchsia_sdk/pkg/async-default", "$fuchsia_sdk/pkg/async-loop", diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc index 4ff7edf7e98..2a10d7a3524 100644 --- a/runtime/vm/dart.cc +++ b/runtime/vm/dart.cc @@ -331,11 +331,7 @@ char* Dart::DartInit(const Dart_InitializeParams* params) { NOT_IN_PRODUCT(CodeObservers::RegisterExternal(*params->code_observer)); } start_time_micros_ = OS::GetCurrentMonotonicMicros(); -#if defined(DART_HOST_OS_FUCHSIA) - VirtualMemory::Init(params->vmex_resource); -#else VirtualMemory::Init(); -#endif #if defined(DART_PRECOMPILED_RUNTIME) && defined(DART_TARGET_OS_LINUX) if (VirtualMemory::PageSize() > kElfPageSize) { diff --git a/runtime/vm/virtual_memory.h b/runtime/vm/virtual_memory.h index 353dc9128f8..821fd345ae2 100644 --- a/runtime/vm/virtual_memory.h +++ b/runtime/vm/virtual_memory.h @@ -65,11 +65,7 @@ class VirtualMemory { #endif } -#if defined(DART_HOST_OS_FUCHSIA) - static void Init(zx_handle_t vmex_resource); -#else static void Init(); -#endif static void Cleanup(); DART_FORCE_INLINE static bool ShouldDualMapExecutablePages() { diff --git a/runtime/vm/virtual_memory_fuchsia.cc b/runtime/vm/virtual_memory_fuchsia.cc index 210040277bb..c3964f29c12 100644 --- a/runtime/vm/virtual_memory_fuchsia.cc +++ b/runtime/vm/virtual_memory_fuchsia.cc @@ -7,6 +7,9 @@ #include "vm/virtual_memory.h" +#include +#include +#include #include #include #include @@ -51,7 +54,7 @@ intptr_t VirtualMemory::CalculatePageSize() { return page_size; } -void VirtualMemory::Init(zx_handle_t vmex_resource) { +void VirtualMemory::Init() { if (FLAG_old_gen_heap_size < 0 || FLAG_old_gen_heap_size > kMaxAddrSpaceMB) { OS::PrintErr( "warning: value specified for --old_gen_heap_size %d is larger than" @@ -89,7 +92,18 @@ void VirtualMemory::Init(zx_handle_t vmex_resource) { #endif // defined(DART_COMPRESSED_POINTERS) page_size_ = CalculatePageSize(); - vmex_resource_ = vmex_resource; + + // If VmexResource is unavailable or does not return a valid handle then + // this will be observed as failures from vmo_replace_as_executable below. + zx::resource vmex_resource; + fuchsia::kernel::VmexResourceSyncPtr vmex_resource_svc; + zx_status_t status = fdio_service_connect( + "/svc/fuchsia.kernel.VmexResource", + vmex_resource_svc.NewRequest().TakeChannel().release()); + ASSERT(status == ZX_OK); + status = vmex_resource_svc->Get(&vmex_resource); + ASSERT(status == ZX_OK); + vmex_resource_ = vmex_resource.release(); } void VirtualMemory::Cleanup() {