Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/integration/meta/dart_
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/kernel/libraries.json
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/logging.h
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/main.cc
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/mapped_resource.cc
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/mapped_resource.h
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/aot_product_runtime
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_product_runner.cmx
Expand Down Expand Up @@ -1068,8 +1070,6 @@ FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/handle_exceptio
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/handle_exception.h
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/inlines.h
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/logging.h
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.cc
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.h
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/tempfs.h
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/vmo.cc
Expand Down
31 changes: 18 additions & 13 deletions shell/platform/fuchsia/dart_runner/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ template("runner") {
"dart_runner.h",
"logging.h",
"main.cc",
"mapped_resource.cc",
"mapped_resource.h",
"service_isolate.cc",
"service_isolate.h",
]
Expand All @@ -39,22 +41,17 @@ template("runner") {

dart_deps = []
if (!invoker.product) {
dart_deps += [
"//third_party/dart/runtime/bin:dart_io_api",
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils:utils",
]
dart_deps += [ "//third_party/dart/runtime/bin:dart_io_api" ]
} else {
dart_deps += [
"//third_party/dart/runtime/bin:dart_io_api_product",
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils:utils_product",
]
dart_deps += [ "//third_party/dart/runtime/bin:dart_io_api_product" ]
}

deps = [
"$flutter_root/common",
"$flutter_root/fml",
"$flutter_root/shell/platform/fuchsia/dart-pkg/fuchsia",
"$flutter_root/shell/platform/fuchsia/dart-pkg/zircon",
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils",
"$fuchsia_sdk_root/pkg:async",
"$fuchsia_sdk_root/pkg:async-cpp",
"$fuchsia_sdk_root/pkg:async-default",
Expand Down Expand Up @@ -159,24 +156,32 @@ template("aot_runner_package") {

resources = []
if (!invoker.product) {
vmservice_snapshot = rebase_path(
vmservice_data = rebase_path(
get_label_info("vmservice:vmservice_snapshot", "target_gen_dir") +
"/vmservice_data.aotsnapshot")
vmservice_instr = rebase_path(
get_label_info("vmservice:vmservice_snapshot", "target_gen_dir") +
"/vmservice_snapshot.so")
"/vmservice_instructions.aotsnapshot")
dart_profiler_symbols = rebase_path(
get_label_info(
"$flutter_root/shell/platform/fuchsia/runtime/dart/profiler_symbols:dart_aot_runner",
"target_gen_dir") + "/dart_aot_runner.dartprofilersymbols")

inputs = [
vmservice_snapshot,
vmservice_data,
vmservice_instr,
observatory_archive_file,
dart_profiler_symbols,
]

resources += [
{
path = vmservice_snapshot
dest = "vmservice_snapshot.so"
path = vmservice_data
dest = "vmservice_isolate_snapshot_data.bin"
},
{
path = vmservice_instr
dest = "vmservice_isolate_snapshot_instructions.bin"
},
{
path = rebase_path(observatory_archive_file)
Expand Down
51 changes: 22 additions & 29 deletions shell/platform/fuchsia/dart_runner/dart_component_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <regex>
#include <utility>

#include "runtime/dart/utils/files.h"
#include "runtime/dart/utils/handle_exception.h"
#include "runtime/dart/utils/inlines.h"
#include "runtime/dart/utils/tempfs.h"
Expand Down Expand Up @@ -194,18 +193,18 @@ bool DartComponentController::SetupNamespace() {
}

bool DartComponentController::SetupFromKernel() {
dart_utils::MappedResource manifest;
if (!dart_utils::MappedResource::LoadFromNamespace(
MappedResource manifest;
if (!MappedResource::LoadFromNamespace(
namespace_, data_path_ + "/app.dilplist", manifest)) {
return false;
}

if (!dart_utils::MappedResource::LoadFromNamespace(
if (!MappedResource::LoadFromNamespace(
nullptr, "pkg/data/isolate_core_snapshot_data.bin",
isolate_snapshot_data_)) {
return false;
}
if (!dart_utils::MappedResource::LoadFromNamespace(
if (!MappedResource::LoadFromNamespace(
nullptr, "pkg/data/isolate_core_snapshot_instructions.bin",
isolate_snapshot_instructions_, true /* executable */)) {
return false;
Expand All @@ -232,9 +231,8 @@ bool DartComponentController::SetupFromKernel() {
std::string path = data_path_ + "/" + str.substr(start, end - start);
start = end + 1;

dart_utils::MappedResource kernel;
if (!dart_utils::MappedResource::LoadFromNamespace(namespace_, path,
kernel)) {
MappedResource kernel;
if (!MappedResource::LoadFromNamespace(namespace_, path, kernel)) {
FX_LOGF(ERROR, LOG_TAG, "Failed to find kernel: %s", path.c_str());
Dart_ExitScope();
return false;
Expand Down Expand Up @@ -264,30 +262,25 @@ bool DartComponentController::SetupFromKernel() {

bool DartComponentController::SetupFromAppSnapshot() {
#if !defined(AOT_RUNTIME)
// If we start generating app-jit snapshots, the code below should be able
// handle that case without modification.
return false;
#else
// Load the ELF snapshot as available, and fall back to a blobs snapshot
// otherwise.
const uint8_t *isolate_data, *isolate_instructions;
if (elf_snapshot_.Load(namespace_, data_path_ + "/app_aot_snapshot.so")) {
isolate_data = elf_snapshot_.IsolateData();
isolate_instructions = elf_snapshot_.IsolateInstrs();
if (isolate_data == nullptr || isolate_instructions == nullptr) {
return false;
}
} else {
if (!dart_utils::MappedResource::LoadFromNamespace(
namespace_, data_path_ + "/isolate_snapshot_data.bin",
isolate_snapshot_data_)) {
return false;
}
if (!dart_utils::MappedResource::LoadFromNamespace(
namespace_, data_path_ + "/isolate_snapshot_instructions.bin",
isolate_snapshot_instructions_, true /* executable */)) {
return false;
}

if (!MappedResource::LoadFromNamespace(
namespace_, data_path_ + "/isolate_snapshot_data.bin",
isolate_snapshot_data_)) {
return false;
}
return CreateIsolate(isolate_data, isolate_instructions);

if (!MappedResource::LoadFromNamespace(
namespace_, data_path_ + "/isolate_snapshot_instructions.bin",
isolate_snapshot_instructions_, true /* executable */)) {
return false;
}

return CreateIsolate(isolate_snapshot_data_.address(),
isolate_snapshot_instructions_.address());
#endif // defined(AOT_RUNTIME)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <lib/zx/timer.h>

#include "lib/fidl/cpp/binding.h"
#include "runtime/dart/utils/mapped_resource.h"
#include "mapped_resource.h"
#include "third_party/dart/runtime/include/dart_api.h"

namespace dart_runner {
Expand Down Expand Up @@ -72,10 +72,9 @@ class DartComponentController : public fuchsia::sys::ComponentController {
fdio_ns_t* namespace_ = nullptr;
int stdoutfd_ = -1;
int stderrfd_ = -1;
dart_utils::ElfSnapshot elf_snapshot_; // AOT snapshot
dart_utils::MappedResource isolate_snapshot_data_; // JIT snapshot
dart_utils::MappedResource isolate_snapshot_instructions_; // JIT snapshot
std::vector<dart_utils::MappedResource> kernel_peices_;
MappedResource isolate_snapshot_data_;
MappedResource isolate_snapshot_instructions_;
std::vector<MappedResource> kernel_peices_;

Dart_Isolate isolate_;
int32_t return_code_ = 0;
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/fuchsia/dart_runner/dart_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ DartRunner::DartRunner() : context_(sys::ComponentContext::Create()) {
params.vm_snapshot_data = ::_kDartVmSnapshotData;
params.vm_snapshot_instructions = ::_kDartVmSnapshotInstructions;
#else
if (!dart_utils::MappedResource::LoadFromNamespace(
if (!MappedResource::LoadFromNamespace(
nullptr, "pkg/data/vm_snapshot_data.bin", vm_snapshot_data_)) {
FX_LOG(FATAL, LOG_TAG, "Failed to load vm snapshot data");
}
if (!dart_utils::MappedResource::LoadFromNamespace(
if (!MappedResource::LoadFromNamespace(
nullptr, "pkg/data/vm_snapshot_instructions.bin",
vm_snapshot_instructions_, true /* executable */)) {
FX_LOG(FATAL, LOG_TAG, "Failed to load vm snapshot instructions");
Expand Down
6 changes: 3 additions & 3 deletions shell/platform/fuchsia/dart_runner/dart_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <lib/fidl/cpp/binding_set.h>
#include <lib/sys/cpp/component_context.h>

#include "runtime/dart/utils/mapped_resource.h"
#include "mapped_resource.h"

namespace dart_runner {

Expand All @@ -30,8 +30,8 @@ class DartRunner : public fuchsia::sys::Runner {
fidl::BindingSet<fuchsia::sys::Runner> bindings_;

#if !defined(AOT_RUNTIME)
dart_utils::MappedResource vm_snapshot_data_;
dart_utils::MappedResource vm_snapshot_instructions_;
MappedResource vm_snapshot_data_;
MappedResource vm_snapshot_instructions_;
#endif

// Disallow copy and assignment.
Expand Down
100 changes: 100 additions & 0 deletions shell/platform/fuchsia/dart_runner/mapped_resource.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mapped_resource.h"

#include <fcntl.h>
#include <lib/trace/event.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <zircon/status.h>

#include "flutter/fml/logging.h"
#include "logging.h"
#include "runtime/dart/utils/inlines.h"
#include "runtime/dart/utils/vmo.h"

namespace dart_runner {

bool MappedResource::LoadFromNamespace(fdio_ns_t* namespc,
const std::string& path,
MappedResource& resource,
bool executable) {
TRACE_DURATION("dart", "LoadFromNamespace", "path", path);

// openat of a path with a leading '/' ignores the namespace fd.
dart_utils::Check(path[0] != '/', LOG_TAG);

fuchsia::mem::Buffer resource_vmo;
if (namespc == nullptr) {
if (!dart_utils::VmoFromFilename(path, &resource_vmo)) {
return false;
}
} else {
auto root_dir = fdio_ns_opendir(namespc);
if (root_dir < 0) {
FML_LOG(ERROR) << "Failed to open namespace directory";
return false;
}

bool result = dart_utils::VmoFromFilenameAt(root_dir, path, &resource_vmo);
close(root_dir);
if (!result) {
return result;
}
}

if (executable) {
// VmoFromFilenameAt will return VMOs without ZX_RIGHT_EXECUTE,
// so we need replace_as_executable to be able to map them as
// ZX_VM_PERM_EXECUTE.
// TODO(mdempsky): Update comment once SEC-42 is fixed.
zx_status_t status =
resource_vmo.vmo.replace_as_executable(zx::handle(), &resource_vmo.vmo);
if (status != ZX_OK) {
FML_LOG(ERROR) << "Failed to make VMO executable: "
<< zx_status_get_string(status);
return false;
}
}

return LoadFromVmo(path, std::move(resource_vmo), resource, executable);
}

bool MappedResource::LoadFromVmo(const std::string& path,
fuchsia::mem::Buffer resource_vmo,
MappedResource& resource,
bool executable) {
if (resource_vmo.size == 0) {
return true;
}

uint32_t flags = ZX_VM_PERM_READ;
if (executable) {
flags |= ZX_VM_PERM_EXECUTE;
}
uintptr_t addr;
zx_status_t status = zx::vmar::root_self()->map(
0, resource_vmo.vmo, 0, resource_vmo.size, flags, &addr);
if (status != ZX_OK) {
FML_LOG(ERROR) << "Failed to map " << path << ": "
<< zx_status_get_string(status);

return false;
}

resource.address_ = reinterpret_cast<void*>(addr);
resource.size_ = resource_vmo.size;
return true;
}

MappedResource::~MappedResource() {
if (address_ != nullptr) {
zx::vmar::root_self()->unmap(reinterpret_cast<uintptr_t>(address_), size_);
address_ = nullptr;
size_ = 0;
}
}

} // namespace dart_runner
Loading