forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elf_loader.cc
88 lines (73 loc) · 2.76 KB
/
elf_loader.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 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 "flutter/testing/elf_loader.h"
#include "flutter/fml/file.h"
#include "flutter/fml/paths.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/testing/testing.h"
namespace flutter {
namespace testing {
static constexpr const char* kAOTAppELFFileName = "app_elf_snapshot.so";
ELFAOTSymbols LoadELFSymbolFromFixturesIfNeccessary() {
if (!DartVM::IsRunningPrecompiledCode()) {
return {};
}
const auto elf_path =
fml::paths::JoinPaths({GetFixturesPath(), kAOTAppELFFileName});
if (!fml::IsFile(elf_path)) {
FML_LOG(ERROR) << "App AOT file does not exist for this fixture. Attempts "
"to launch the Dart VM with these AOT symbols will fail.";
return {};
}
ELFAOTSymbols symbols;
// Must not be freed.
const char* error = nullptr;
#if OS_FUCHSIA
// TODO(gw280): https://github.com/flutter/flutter/issues/50285
// Dart doesn't implement Dart_LoadELF on Fuchsia
auto loaded_elf = nullptr;
#else
auto loaded_elf =
Dart_LoadELF(elf_path.c_str(), // file path
0, // file offset
&error, // error (out)
&symbols.vm_snapshot_data, // vm snapshot data (out)
&symbols.vm_snapshot_instrs, // vm snapshot instrs (out)
&symbols.vm_isolate_data, // vm isolate data (out)
&symbols.vm_isolate_instrs // vm isolate instr (out)
);
#endif
if (loaded_elf == nullptr) {
FML_LOG(ERROR)
<< "Could not fetch AOT symbols from loaded ELF. Attempts "
"to launch the Dart VM with these AOT symbols will fail. Error: "
<< error;
return {};
}
symbols.loaded_elf.reset(loaded_elf);
return symbols;
}
bool PrepareSettingsForAOTWithSymbols(Settings& settings,
const ELFAOTSymbols& symbols) {
if (!DartVM::IsRunningPrecompiledCode()) {
return false;
}
settings.vm_snapshot_data = [&]() {
return std::make_unique<fml::NonOwnedMapping>(symbols.vm_snapshot_data, 0u);
};
settings.isolate_snapshot_data = [&]() {
return std::make_unique<fml::NonOwnedMapping>(symbols.vm_isolate_data, 0u);
};
settings.vm_snapshot_instr = [&]() {
return std::make_unique<fml::NonOwnedMapping>(symbols.vm_snapshot_instrs,
0u);
};
settings.isolate_snapshot_instr = [&]() {
return std::make_unique<fml::NonOwnedMapping>(symbols.vm_isolate_instrs,
0u);
};
return true;
}
} // namespace testing
} // namespace flutter