32 {
33 if (executable) {
35 } else {
37 }
38}
39
40
41
42
43
44
45
46
47
48
49
50
52 const MappingCallback& embedder_mapping_callback,
53 const std::string& file_path,
54 const std::vector<std::string>& native_library_paths,
55 const char* native_library_symbol_name,
56 bool is_executable) {
57
58
59 if (embedder_mapping_callback) {
60
61
62
63 if (auto mapping = embedder_mapping_callback()) {
64 return mapping;
65 }
66 }
67
68
69 if (!file_path.empty()) {
70 if (
auto file_mapping =
GetFileMapping(file_path, is_executable)) {
71 return file_mapping;
72 }
73 }
74
75
76 for (const std::string& path : native_library_paths) {
78 auto symbol_mapping = std::make_unique<const fml::SymbolMapping>(
79 native_library, native_library_symbol_name);
80 if (symbol_mapping->GetMapping() != nullptr) {
81 return symbol_mapping;
82 }
83 }
84
85
86 {
88 auto symbol_mapping = std::make_unique<const fml::SymbolMapping>(
89 loaded_process, native_library_symbol_name);
90 if (symbol_mapping->GetMapping() != nullptr) {
91 return symbol_mapping;
92 }
93 }
94
95 return nullptr;
96}
97
98#endif
99
101 const Settings& settings) {
102#if DART_SNAPSHOT_STATIC_LINK
104 0,
105 nullptr,
106 true
107 );
108#else
110 settings.vm_snapshot_data,
111 settings.vm_snapshot_data_path,
112 settings.application_library_paths,
113 DartSnapshot::kVMDataSymbol,
114 false
115 );
116#endif
117}
118
120 const Settings& settings) {
121#if DART_SNAPSHOT_STATIC_LINK
123 0,
124 nullptr,
125 true
126 );
127#else
129 settings.vm_snapshot_instr,
130 settings.vm_snapshot_instr_path,
131 settings.application_library_paths,
132 DartSnapshot::kVMInstructionsSymbol,
133 true
134 );
135#endif
136}
137
139 const Settings& settings) {
140#if DART_SNAPSHOT_STATIC_LINK
142 0,
143 nullptr,
144 true
145 );
146#else
148 settings.isolate_snapshot_data,
149 settings.isolate_snapshot_data_path,
150 settings.application_library_paths,
151 DartSnapshot::kIsolateDataSymbol,
152 false
153 );
154#endif
155}
156
158 const Settings& settings) {
159#if DART_SNAPSHOT_STATIC_LINK
161 0,
162 nullptr,
163 true
164 );
165#else
167 settings.isolate_snapshot_instr,
168 settings.isolate_snapshot_instr_path,
169 settings.application_library_paths,
170 DartSnapshot::kIsolateInstructionsSymbol,
171 true
172 );
173#endif
174}
175
177 const Settings& settings) {
178 TRACE_EVENT0(
"flutter",
"DartSnapshot::VMSnapshotFromSettings");
179 auto snapshot =
182 );
183 if (snapshot->IsValid()) {
184 return snapshot;
185 }
186 return nullptr;
187}
188
190 const Settings& settings) {
191 TRACE_EVENT0(
"flutter",
"DartSnapshot::IsolateSnapshotFromSettings");
192 auto snapshot =
195 );
196 if (snapshot->IsValid()) {
197 return snapshot;
198 }
199 return nullptr;
200}
201
203 const std::shared_ptr<const fml::Mapping>& snapshot_data,
204 const std::shared_ptr<const fml::Mapping>& snapshot_instructions) {
205 auto snapshot =
206 fml::MakeRefCounted<DartSnapshot>(snapshot_data, snapshot_instructions);
207 if (snapshot->IsValid()) {
208 return snapshot;
209 }
210 return nullptr;
211
212}
213
215 const Settings& settings) {
216#if DART_SNAPSHOT_STATIC_LINK
217 return nullptr;
218#else
219 if (settings.vmservice_snapshot_library_path.empty()) {
220 return nullptr;
221 }
222
223 std::shared_ptr<const fml::Mapping> snapshot_data =
224 SearchMapping(
nullptr,
"", settings.vmservice_snapshot_library_path,
225 DartSnapshot::kIsolateDataSymbol, false);
226 std::shared_ptr<const fml::Mapping> snapshot_instructions =
227 SearchMapping(
nullptr,
"", settings.vmservice_snapshot_library_path,
228 DartSnapshot::kIsolateInstructionsSymbol, true);
229 return IsolateSnapshotFromMappings(snapshot_data, snapshot_instructions);
230#endif
231}
232
233DartSnapshot::DartSnapshot(std::shared_ptr<const fml::Mapping> data,
234 std::shared_ptr<const fml::Mapping> instructions)
235 : data_(
std::move(
data)), instructions_(
std::move(instructions)) {}
236
237DartSnapshot::~DartSnapshot() = default;
238
239bool DartSnapshot::IsValid() const {
240 return static_cast<bool>(data_);
241}
242
243bool DartSnapshot::IsValidForAOT() const {
244 return data_ && instructions_;
245}
246
247const uint8_t* DartSnapshot::GetDataMapping() const {
248 return data_ ? data_->GetMapping() : nullptr;
249}
250
251const uint8_t* DartSnapshot::GetInstructionsMapping() const {
252 return instructions_ ? instructions_->GetMapping() : nullptr;
253}
254
255bool DartSnapshot::IsDontNeedSafe() const {
256 if (data_ && !data_->IsDontNeedSafe()) {
257 return false;
258 }
259 if (instructions_ && !instructions_->IsDontNeedSafe()) {
260 return false;
261 }
262 return true;
263}
264
265bool DartSnapshot::IsNullSafetyEnabled(
const fml::Mapping* kernel)
const {
266 return ::Dart_DetectNullSafety(
267 nullptr,
268 nullptr,
269 nullptr,
270 GetDataMapping(),
271 GetInstructionsMapping(),
273 kernel ? kernel->GetSize() : 0u
274 );
275}
276
277}
static std::unique_ptr< FileMapping > CreateReadExecute(const std::string &path)
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
virtual const uint8_t * GetMapping() const =0
static fml::RefPtr< NativeLibrary > CreateForCurrentProcess()
static fml::RefPtr< NativeLibrary > Create(const char *path)
const uint8_t kDartSnapshotText[]
const uint8_t kDartSnapshotData[]
static std::shared_ptr< const fml::Mapping > ResolveIsolateData(const Settings &settings)
static std::shared_ptr< const fml::Mapping > SearchMapping(const MappingCallback &embedder_mapping_callback, const std::string &file_path, const std::vector< std::string > &native_library_paths, const char *native_library_symbol_name, bool is_executable)
static std::shared_ptr< const fml::Mapping > ResolveVMInstructions(const Settings &settings)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
static std::shared_ptr< const fml::Mapping > ResolveVMData(const Settings &settings)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
static std::unique_ptr< const fml::Mapping > GetFileMapping(const std::string &path, bool executable)
static std::shared_ptr< const fml::Mapping > ResolveIsolateInstructions(const Settings &settings)
#define TRACE_EVENT0(category_group, name)