Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
57 changes: 33 additions & 24 deletions shell/platform/fuchsia/flutter/component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@ static std::string DebugLabelForURL(const std::string& url) {
}
}

static std::unique_ptr<fml::FileMapping> MakeReadExecMapping(const char* path) {
static std::unique_ptr<fml::FileMapping> MakeFileMapping(const char* path,
bool executable) {
uint32_t flags = OPEN_RIGHT_READABLE;
if (executable) {
flags |= OPEN_RIGHT_EXECUTABLE;
}

int fd = 0;
// The returned file descriptor is compatible with standard posix operations
// such as close, mmap, etc. We only need to treat open/open_at specially.
zx_status_t status =
fdio_open_fd(path, OPEN_RIGHT_READABLE | OPEN_RIGHT_EXECUTABLE, &fd);
zx_status_t status = fdio_open_fd(path, flags, &fd);

if (status != ZX_OK) {
return nullptr;
Expand All @@ -105,6 +110,14 @@ static std::unique_ptr<fml::FileMapping> MakeReadExecMapping(const char* path) {
return mapping;
}

// Defaults to readonly. If executable is `true`, we treat it as `read + exec`.
static flutter::MappingCallback MakeDataFileMapping(const char* absolute_path,
bool executable = false) {
return [absolute_path, executable = executable](void) {
return MakeFileMapping(absolute_path, executable);
};
}

Application::Application(
TerminationCallback termination_callback,
fuchsia::sys::Package package,
Expand Down Expand Up @@ -253,17 +266,15 @@ Application::Application(
}

// Compare flutter_jit_runner in BUILD.gn.
settings_.vm_snapshot_data_path = "pkg/data/vm_snapshot_data.bin";
settings_.vm_snapshot_instr = []() {
return MakeReadExecMapping("/pkg/data/vm_snapshot_instructions.bin");
};
settings_.vm_snapshot_data =
MakeDataFileMapping("/pkg/data/vm_snapshot_data.bin");
settings_.vm_snapshot_instr =
MakeDataFileMapping("/pkg/data/vm_snapshot_instructions.bin", true);

settings_.isolate_snapshot_data_path =
"pkg/data/isolate_core_snapshot_data.bin";
settings_.isolate_snapshot_instr = []() {
return MakeReadExecMapping(
"/pkg/data/isolate_core_snapshot_instructions.bin");
};
settings_.isolate_snapshot_data =
MakeDataFileMapping("/pkg/data/isolate_core_snapshot_data.bin");
settings_.isolate_snapshot_instr = MakeDataFileMapping(
"/pkg/data/isolate_core_snapshot_instructions.bin", true);

{
// Check if we can use the snapshot with the framework already loaded.
Expand All @@ -275,17 +286,15 @@ Application::Application(
"app.frameworkversion",
&app_framework) &&
(runner_framework.compare(app_framework) == 0)) {
settings_.vm_snapshot_data_path =
"pkg/data/framework_vm_snapshot_data.bin";
settings_.vm_snapshot_instr = []() {
return MakeReadExecMapping("/pkg/data/vm_snapshot_instructions.bin");
};
settings_.isolate_snapshot_data_path =
"pkg/data/framework_isolate_core_snapshot_data.bin";
settings_.isolate_snapshot_instr = []() {
return MakeReadExecMapping(
"/pkg/data/isolate_core_snapshot_instructions.bin");
};
settings_.vm_snapshot_data =
MakeDataFileMapping("/pkg/data/framework_vm_snapshot_data.bin");
settings_.vm_snapshot_instr =
MakeDataFileMapping("/pkg/data/vm_snapshot_instructions.bin", true);

settings_.isolate_snapshot_data = MakeDataFileMapping(
"/pkg/data/framework_isolate_core_snapshot_data.bin");
settings_.isolate_snapshot_instr = MakeDataFileMapping(
"/pkg/data/isolate_core_snapshot_instructions.bin", true);

FML_LOG(INFO) << "Using snapshot with framework for "
<< package.resolved_url;
Expand Down