[flutter_runner] Make rd and rx uniform (flutter/engine#12733)

* [flutter_runner] Make rd and rx uniform

Currently we pass paths for readonly files and pass
in fds for rx. Now passing in fds everywhere.

* pass full paths
This commit is contained in:
Kaushik Iska
2019-10-01 19:24:19 -07:00
committed by GitHub
parent 61da9e9a60
commit 341b81ec4d

View File

@@ -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;
@@ -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,
@@ -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.
@@ -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;