Skip to content

Commit 77fc5e7

Browse files
franciscojma86filmil
authored andcommitted
Revert "Use ELF for Dart AOT snapshots on Fuchsia. (flutter#13896)" (flutter#14823)
This reverts commit 09c434d.
1 parent b0e85f5 commit 77fc5e7

File tree

13 files changed

+241
-402
lines changed

13 files changed

+241
-402
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/integration/meta/dart_
986986
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/kernel/libraries.json
987987
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/logging.h
988988
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/main.cc
989+
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/mapped_resource.cc
990+
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/mapped_resource.h
989991
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/aot_product_runtime
990992
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime
991993
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_product_runner.cmx
@@ -1068,8 +1070,6 @@ FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/handle_exceptio
10681070
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/handle_exception.h
10691071
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/inlines.h
10701072
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/logging.h
1071-
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.cc
1072-
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.h
10731073
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc
10741074
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/tempfs.h
10751075
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/vmo.cc

shell/platform/fuchsia/dart_runner/BUILD.gn

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ template("runner") {
3131
"dart_runner.h",
3232
"logging.h",
3333
"main.cc",
34+
"mapped_resource.cc",
35+
"mapped_resource.h",
3436
"service_isolate.cc",
3537
"service_isolate.h",
3638
]
@@ -39,22 +41,17 @@ template("runner") {
3941

4042
dart_deps = []
4143
if (!invoker.product) {
42-
dart_deps += [
43-
"//third_party/dart/runtime/bin:dart_io_api",
44-
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils:utils",
45-
]
44+
dart_deps += [ "//third_party/dart/runtime/bin:dart_io_api" ]
4645
} else {
47-
dart_deps += [
48-
"//third_party/dart/runtime/bin:dart_io_api_product",
49-
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils:utils_product",
50-
]
46+
dart_deps += [ "//third_party/dart/runtime/bin:dart_io_api_product" ]
5147
}
5248

5349
deps = [
5450
"$flutter_root/common",
5551
"$flutter_root/fml",
5652
"$flutter_root/shell/platform/fuchsia/dart-pkg/fuchsia",
5753
"$flutter_root/shell/platform/fuchsia/dart-pkg/zircon",
54+
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils",
5855
"$fuchsia_sdk_root/pkg:async",
5956
"$fuchsia_sdk_root/pkg:async-cpp",
6057
"$fuchsia_sdk_root/pkg:async-default",
@@ -159,24 +156,32 @@ template("aot_runner_package") {
159156

160157
resources = []
161158
if (!invoker.product) {
162-
vmservice_snapshot = rebase_path(
159+
vmservice_data = rebase_path(
160+
get_label_info("vmservice:vmservice_snapshot", "target_gen_dir") +
161+
"/vmservice_data.aotsnapshot")
162+
vmservice_instr = rebase_path(
163163
get_label_info("vmservice:vmservice_snapshot", "target_gen_dir") +
164-
"/vmservice_snapshot.so")
164+
"/vmservice_instructions.aotsnapshot")
165165
dart_profiler_symbols = rebase_path(
166166
get_label_info(
167167
"$flutter_root/shell/platform/fuchsia/runtime/dart/profiler_symbols:dart_aot_runner",
168168
"target_gen_dir") + "/dart_aot_runner.dartprofilersymbols")
169169

170170
inputs = [
171-
vmservice_snapshot,
171+
vmservice_data,
172+
vmservice_instr,
172173
observatory_archive_file,
173174
dart_profiler_symbols,
174175
]
175176

176177
resources += [
177178
{
178-
path = vmservice_snapshot
179-
dest = "vmservice_snapshot.so"
179+
path = vmservice_data
180+
dest = "vmservice_isolate_snapshot_data.bin"
181+
},
182+
{
183+
path = vmservice_instr
184+
dest = "vmservice_isolate_snapshot_instructions.bin"
180185
},
181186
{
182187
path = rebase_path(observatory_archive_file)

shell/platform/fuchsia/dart_runner/dart_component_controller.cc

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <regex>
2525
#include <utility>
2626

27-
#include "runtime/dart/utils/files.h"
2827
#include "runtime/dart/utils/handle_exception.h"
2928
#include "runtime/dart/utils/inlines.h"
3029
#include "runtime/dart/utils/tempfs.h"
@@ -194,18 +193,18 @@ bool DartComponentController::SetupNamespace() {
194193
}
195194

196195
bool DartComponentController::SetupFromKernel() {
197-
dart_utils::MappedResource manifest;
198-
if (!dart_utils::MappedResource::LoadFromNamespace(
196+
MappedResource manifest;
197+
if (!MappedResource::LoadFromNamespace(
199198
namespace_, data_path_ + "/app.dilplist", manifest)) {
200199
return false;
201200
}
202201

203-
if (!dart_utils::MappedResource::LoadFromNamespace(
202+
if (!MappedResource::LoadFromNamespace(
204203
nullptr, "pkg/data/isolate_core_snapshot_data.bin",
205204
isolate_snapshot_data_)) {
206205
return false;
207206
}
208-
if (!dart_utils::MappedResource::LoadFromNamespace(
207+
if (!MappedResource::LoadFromNamespace(
209208
nullptr, "pkg/data/isolate_core_snapshot_instructions.bin",
210209
isolate_snapshot_instructions_, true /* executable */)) {
211210
return false;
@@ -232,9 +231,8 @@ bool DartComponentController::SetupFromKernel() {
232231
std::string path = data_path_ + "/" + str.substr(start, end - start);
233232
start = end + 1;
234233

235-
dart_utils::MappedResource kernel;
236-
if (!dart_utils::MappedResource::LoadFromNamespace(namespace_, path,
237-
kernel)) {
234+
MappedResource kernel;
235+
if (!MappedResource::LoadFromNamespace(namespace_, path, kernel)) {
238236
FX_LOGF(ERROR, LOG_TAG, "Failed to find kernel: %s", path.c_str());
239237
Dart_ExitScope();
240238
return false;
@@ -264,30 +262,25 @@ bool DartComponentController::SetupFromKernel() {
264262

265263
bool DartComponentController::SetupFromAppSnapshot() {
266264
#if !defined(AOT_RUNTIME)
265+
// If we start generating app-jit snapshots, the code below should be able
266+
// handle that case without modification.
267267
return false;
268268
#else
269-
// Load the ELF snapshot as available, and fall back to a blobs snapshot
270-
// otherwise.
271-
const uint8_t *isolate_data, *isolate_instructions;
272-
if (elf_snapshot_.Load(namespace_, data_path_ + "/app_aot_snapshot.so")) {
273-
isolate_data = elf_snapshot_.IsolateData();
274-
isolate_instructions = elf_snapshot_.IsolateInstrs();
275-
if (isolate_data == nullptr || isolate_instructions == nullptr) {
276-
return false;
277-
}
278-
} else {
279-
if (!dart_utils::MappedResource::LoadFromNamespace(
280-
namespace_, data_path_ + "/isolate_snapshot_data.bin",
281-
isolate_snapshot_data_)) {
282-
return false;
283-
}
284-
if (!dart_utils::MappedResource::LoadFromNamespace(
285-
namespace_, data_path_ + "/isolate_snapshot_instructions.bin",
286-
isolate_snapshot_instructions_, true /* executable */)) {
287-
return false;
288-
}
269+
270+
if (!MappedResource::LoadFromNamespace(
271+
namespace_, data_path_ + "/isolate_snapshot_data.bin",
272+
isolate_snapshot_data_)) {
273+
return false;
289274
}
290-
return CreateIsolate(isolate_data, isolate_instructions);
275+
276+
if (!MappedResource::LoadFromNamespace(
277+
namespace_, data_path_ + "/isolate_snapshot_instructions.bin",
278+
isolate_snapshot_instructions_, true /* executable */)) {
279+
return false;
280+
}
281+
282+
return CreateIsolate(isolate_snapshot_data_.address(),
283+
isolate_snapshot_instructions_.address());
291284
#endif // defined(AOT_RUNTIME)
292285
}
293286

shell/platform/fuchsia/dart_runner/dart_component_controller.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <lib/zx/timer.h>
1717

1818
#include "lib/fidl/cpp/binding.h"
19-
#include "runtime/dart/utils/mapped_resource.h"
19+
#include "mapped_resource.h"
2020
#include "third_party/dart/runtime/include/dart_api.h"
2121

2222
namespace dart_runner {
@@ -72,10 +72,9 @@ class DartComponentController : public fuchsia::sys::ComponentController {
7272
fdio_ns_t* namespace_ = nullptr;
7373
int stdoutfd_ = -1;
7474
int stderrfd_ = -1;
75-
dart_utils::ElfSnapshot elf_snapshot_; // AOT snapshot
76-
dart_utils::MappedResource isolate_snapshot_data_; // JIT snapshot
77-
dart_utils::MappedResource isolate_snapshot_instructions_; // JIT snapshot
78-
std::vector<dart_utils::MappedResource> kernel_peices_;
75+
MappedResource isolate_snapshot_data_;
76+
MappedResource isolate_snapshot_instructions_;
77+
std::vector<MappedResource> kernel_peices_;
7978

8079
Dart_Isolate isolate_;
8180
int32_t return_code_ = 0;

shell/platform/fuchsia/dart_runner/dart_runner.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ DartRunner::DartRunner() : context_(sys::ComponentContext::Create()) {
155155
params.vm_snapshot_data = ::_kDartVmSnapshotData;
156156
params.vm_snapshot_instructions = ::_kDartVmSnapshotInstructions;
157157
#else
158-
if (!dart_utils::MappedResource::LoadFromNamespace(
158+
if (!MappedResource::LoadFromNamespace(
159159
nullptr, "pkg/data/vm_snapshot_data.bin", vm_snapshot_data_)) {
160160
FX_LOG(FATAL, LOG_TAG, "Failed to load vm snapshot data");
161161
}
162-
if (!dart_utils::MappedResource::LoadFromNamespace(
162+
if (!MappedResource::LoadFromNamespace(
163163
nullptr, "pkg/data/vm_snapshot_instructions.bin",
164164
vm_snapshot_instructions_, true /* executable */)) {
165165
FX_LOG(FATAL, LOG_TAG, "Failed to load vm snapshot instructions");

shell/platform/fuchsia/dart_runner/dart_runner.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <lib/fidl/cpp/binding_set.h>
1010
#include <lib/sys/cpp/component_context.h>
1111

12-
#include "runtime/dart/utils/mapped_resource.h"
12+
#include "mapped_resource.h"
1313

1414
namespace dart_runner {
1515

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

3232
#if !defined(AOT_RUNTIME)
33-
dart_utils::MappedResource vm_snapshot_data_;
34-
dart_utils::MappedResource vm_snapshot_instructions_;
33+
MappedResource vm_snapshot_data_;
34+
MappedResource vm_snapshot_instructions_;
3535
#endif
3636

3737
// Disallow copy and assignment.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "mapped_resource.h"
6+
7+
#include <fcntl.h>
8+
#include <lib/trace/event.h>
9+
#include <sys/stat.h>
10+
#include <sys/types.h>
11+
#include <zircon/status.h>
12+
13+
#include "flutter/fml/logging.h"
14+
#include "logging.h"
15+
#include "runtime/dart/utils/inlines.h"
16+
#include "runtime/dart/utils/vmo.h"
17+
18+
namespace dart_runner {
19+
20+
bool MappedResource::LoadFromNamespace(fdio_ns_t* namespc,
21+
const std::string& path,
22+
MappedResource& resource,
23+
bool executable) {
24+
TRACE_DURATION("dart", "LoadFromNamespace", "path", path);
25+
26+
// openat of a path with a leading '/' ignores the namespace fd.
27+
dart_utils::Check(path[0] != '/', LOG_TAG);
28+
29+
fuchsia::mem::Buffer resource_vmo;
30+
if (namespc == nullptr) {
31+
if (!dart_utils::VmoFromFilename(path, &resource_vmo)) {
32+
return false;
33+
}
34+
} else {
35+
auto root_dir = fdio_ns_opendir(namespc);
36+
if (root_dir < 0) {
37+
FML_LOG(ERROR) << "Failed to open namespace directory";
38+
return false;
39+
}
40+
41+
bool result = dart_utils::VmoFromFilenameAt(root_dir, path, &resource_vmo);
42+
close(root_dir);
43+
if (!result) {
44+
return result;
45+
}
46+
}
47+
48+
if (executable) {
49+
// VmoFromFilenameAt will return VMOs without ZX_RIGHT_EXECUTE,
50+
// so we need replace_as_executable to be able to map them as
51+
// ZX_VM_PERM_EXECUTE.
52+
// TODO(mdempsky): Update comment once SEC-42 is fixed.
53+
zx_status_t status =
54+
resource_vmo.vmo.replace_as_executable(zx::handle(), &resource_vmo.vmo);
55+
if (status != ZX_OK) {
56+
FML_LOG(ERROR) << "Failed to make VMO executable: "
57+
<< zx_status_get_string(status);
58+
return false;
59+
}
60+
}
61+
62+
return LoadFromVmo(path, std::move(resource_vmo), resource, executable);
63+
}
64+
65+
bool MappedResource::LoadFromVmo(const std::string& path,
66+
fuchsia::mem::Buffer resource_vmo,
67+
MappedResource& resource,
68+
bool executable) {
69+
if (resource_vmo.size == 0) {
70+
return true;
71+
}
72+
73+
uint32_t flags = ZX_VM_PERM_READ;
74+
if (executable) {
75+
flags |= ZX_VM_PERM_EXECUTE;
76+
}
77+
uintptr_t addr;
78+
zx_status_t status = zx::vmar::root_self()->map(
79+
0, resource_vmo.vmo, 0, resource_vmo.size, flags, &addr);
80+
if (status != ZX_OK) {
81+
FML_LOG(ERROR) << "Failed to map " << path << ": "
82+
<< zx_status_get_string(status);
83+
84+
return false;
85+
}
86+
87+
resource.address_ = reinterpret_cast<void*>(addr);
88+
resource.size_ = resource_vmo.size;
89+
return true;
90+
}
91+
92+
MappedResource::~MappedResource() {
93+
if (address_ != nullptr) {
94+
zx::vmar::root_self()->unmap(reinterpret_cast<uintptr_t>(address_), size_);
95+
address_ = nullptr;
96+
size_ = 0;
97+
}
98+
}
99+
100+
} // namespace dart_runner

0 commit comments

Comments
 (0)