33 {
34 if (executable) {
36 } else {
38 }
39}
40
41
42
43
44
45
46
47
48
49
50
51
53 const MappingCallback& embedder_mapping_callback,
54 const std::string& file_path,
55 const std::vector<std::string>& native_library_path,
56 const char* native_library_symbol_name,
57 bool is_executable) {
58
59
60 if (embedder_mapping_callback) {
61
62
63
64 if (auto mapping = embedder_mapping_callback()) {
65 return mapping;
66 }
67 }
68
69
70 if (!file_path.empty()) {
71 if (
auto file_mapping =
GetFileMapping(file_path, is_executable)) {
72 return file_mapping;
73 }
74 }
75
76
77 for (const std::string& path : native_library_path) {
79 auto symbol_mapping = std::make_unique<const fml::SymbolMapping>(
80 native_library, native_library_symbol_name);
81 if (symbol_mapping->GetMapping() != nullptr) {
82 return symbol_mapping;
83 }
84 }
85
86
87 {
89 auto symbol_mapping = std::make_unique<const fml::SymbolMapping>(
90 loaded_process, native_library_symbol_name);
91 if (symbol_mapping->GetMapping() != nullptr) {
92 return symbol_mapping;
93 }
94 }
95
96 return nullptr;
97}
98
99#endif
100
102 const Settings& settings) {
103#if DART_SNAPSHOT_STATIC_LINK
105 0,
106 nullptr,
107 true
108 );
109#else
114 DartSnapshot::kVMDataSymbol,
115 false
116 );
117#endif
118}
119
121 const Settings& settings) {
122#if DART_SNAPSHOT_STATIC_LINK
124 0,
125 nullptr,
126 true
127 );
128#else
133 DartSnapshot::kVMInstructionsSymbol,
134 true
135 );
136#endif
137}
138
140 const Settings& settings) {
141#if DART_SNAPSHOT_STATIC_LINK
143 0,
144 nullptr,
145 true
146 );
147#else
150 settings.isolate_snapshot_data_path,
152 DartSnapshot::kIsolateDataSymbol,
153 false
154 );
155#endif
156}
157
159 const Settings& settings) {
160#if DART_SNAPSHOT_STATIC_LINK
161 return std::make_unique<fml::NonOwnedMapping>(
163 0,
164 nullptr,
165 true
166 );
167#else
170 settings.isolate_snapshot_instr_path,
172 DartSnapshot::kIsolateInstructionsSymbol,
173 true
174 );
175#endif
176}
177
179 const Settings& settings) {
180 TRACE_EVENT0(
"flutter",
"DartSnapshot::VMSnapshotFromSettings");
181 auto snapshot =
184 );
185 if (snapshot->IsValid()) {
186 return snapshot;
187 }
188 return nullptr;
189}
190
192 const Settings& settings) {
193 TRACE_EVENT0(
"flutter",
"DartSnapshot::IsolateSnapshotFromSettings");
194 auto snapshot =
197 );
198 if (snapshot->IsValid()) {
199 return snapshot;
200 }
201 return nullptr;
202}
203
205 const std::shared_ptr<const fml::Mapping>& snapshot_data,
206 const std::shared_ptr<const fml::Mapping>& snapshot_instructions) {
207 auto snapshot =
208 fml::MakeRefCounted<DartSnapshot>(snapshot_data, snapshot_instructions);
209 if (snapshot->IsValid()) {
210 return snapshot;
211 }
212 return nullptr;
213}
214
216 const Settings& settings) {
217#if DART_SNAPSHOT_STATIC_LINK
218 return nullptr;
219#else
220 if (
settings.vmservice_snapshot_library_path.empty()) {
221 return nullptr;
222 }
223
224 std::shared_ptr<const fml::Mapping> snapshot_data =
226 DartSnapshot::kIsolateDataSymbol, false);
227 std::shared_ptr<const fml::Mapping> snapshot_instructions =
229 DartSnapshot::kIsolateInstructionsSymbol, true);
230 return IsolateSnapshotFromMappings(snapshot_data, snapshot_instructions);
231#endif
232}
233
234DartSnapshot::DartSnapshot(std::shared_ptr<const fml::Mapping> data,
235 std::shared_ptr<const fml::Mapping> instructions)
236 : data_(
std::move(
data)), instructions_(
std::move(instructions)) {}
237
238DartSnapshot::~DartSnapshot() = default;
239
240bool DartSnapshot::IsValid() const {
241 return static_cast<bool>(data_);
242}
243
244bool DartSnapshot::IsValidForAOT() const {
245 return data_ && instructions_;
246}
247
248const uint8_t* DartSnapshot::GetDataMapping() const {
249 return data_ ? data_->GetMapping() : nullptr;
250}
251
252const uint8_t* DartSnapshot::GetInstructionsMapping() const {
253 return instructions_ ? instructions_->GetMapping() : nullptr;
254}
255
256bool DartSnapshot::IsDontNeedSafe() const {
257 if (data_ && !data_->IsDontNeedSafe()) {
258 return false;
259 }
260 if (instructions_ && !instructions_->IsDontNeedSafe()) {
261 return false;
262 }
263 return true;
264}
265
266bool DartSnapshot::IsNullSafetyEnabled(
const fml::Mapping* kernel)
const {
267 return ::Dart_DetectNullSafety(
268 nullptr,
269 nullptr,
270 nullptr,
271 GetDataMapping(),
272 GetInstructionsMapping(),
274 kernel ? kernel->GetSize() : 0u
275 );
276}
277
278}
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 kDartVmSnapshotData[]
const uint8_t kDartVmSnapshotInstructions[]
const uint8_t kDartIsolateSnapshotData[]
const uint8_t kDartIsolateSnapshotInstructions[]
static std::shared_ptr< const fml::Mapping > ResolveIsolateData(const Settings &settings)
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)
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_path, const char *native_library_symbol_name, bool is_executable)
#define TRACE_EVENT0(category_group, name)