5#include "flutter/runtime/dart_snapshot.h"
9#include "flutter/fml/native_library.h"
10#include "flutter/fml/paths.h"
11#include "flutter/fml/trace_event.h"
12#include "flutter/lib/snapshot/snapshot.h"
13#include "flutter/runtime/dart_vm.h"
14#include "third_party/dart/runtime/include/dart_api.h"
22 "kDartIsolateSnapshotInstructions";
27#define DART_SNAPSHOT_STATIC_LINK \
28 ((FML_OS_WIN || FML_OS_ANDROID) && FLUTTER_JIT_RUNTIME)
30#if !DART_SNAPSHOT_STATIC_LINK
33 const std::string&
path,
55 const std::string& file_path,
56 const std::vector<std::string>& native_library_path,
57 const char* native_library_symbol_name,
61 if (embedder_mapping_callback) {
65 if (
auto mapping = embedder_mapping_callback()) {
71 if (!file_path.empty()) {
72 if (
auto file_mapping =
GetFileMapping(file_path, is_executable)) {
78 for (
const std::string&
path : native_library_path) {
80 auto symbol_mapping = std::make_unique<const fml::SymbolMapping>(
81 native_library, native_library_symbol_name);
82 if (symbol_mapping->GetMapping() !=
nullptr) {
83 return symbol_mapping;
90 auto symbol_mapping = std::make_unique<const fml::SymbolMapping>(
91 loaded_process, native_library_symbol_name);
92 if (symbol_mapping->GetMapping() !=
nullptr) {
93 return symbol_mapping;
104#if DART_SNAPSHOT_STATIC_LINK
123#if DART_SNAPSHOT_STATIC_LINK
142#if DART_SNAPSHOT_STATIC_LINK
151 settings.isolate_snapshot_data_path,
161#if DART_SNAPSHOT_STATIC_LINK
162 return std::make_unique<fml::NonOwnedMapping>(
171 settings.isolate_snapshot_instr_path,
181 TRACE_EVENT0(
"flutter",
"DartSnapshot::VMSnapshotFromSettings");
186 if (snapshot->IsValid()) {
194 TRACE_EVENT0(
"flutter",
"DartSnapshot::IsolateSnapshotFromSettings");
199 if (snapshot->IsValid()) {
206 const std::shared_ptr<const fml::Mapping>& snapshot_data,
207 const std::shared_ptr<const fml::Mapping>& snapshot_instructions) {
209 fml::MakeRefCounted<DartSnapshot>(snapshot_data, snapshot_instructions);
210 if (snapshot->IsValid()) {
218#if DART_SNAPSHOT_STATIC_LINK
221 if (
settings.vmservice_snapshot_library_path.empty()) {
225 std::shared_ptr<const fml::Mapping> snapshot_data =
228 std::shared_ptr<const fml::Mapping> snapshot_instructions =
235DartSnapshot::DartSnapshot(std::shared_ptr<const fml::Mapping>
data,
236 std::shared_ptr<const fml::Mapping> instructions)
237 : data_(
std::move(
data)), instructions_(
std::move(instructions)) {}
239DartSnapshot::~DartSnapshot() =
default;
242 return static_cast<bool>(data_);
246 return data_ && instructions_;
250 return data_ ? data_->GetMapping() :
nullptr;
254 return instructions_ ? instructions_->GetMapping() :
nullptr;
258 if (data_ && !data_->IsDontNeedSafe()) {
261 if (instructions_ && !instructions_->IsDontNeedSafe()) {
275 kernel ? kernel->
GetSize() : 0u
bool IsNullSafetyEnabled(const fml::Mapping *application_kernel_mapping) const
bool IsValidForAOT() const
Determines if this snapshot contains both the heap and instructions components. This is only useful w...
static fml::RefPtr< DartSnapshot > VMServiceIsolateSnapshotFromSettings(const Settings &settings)
Create an isolate snapshot specialized for launching the service isolate. Returns nullptr if no such ...
static fml::RefPtr< const DartSnapshot > VMSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the core snapshot.
static fml::RefPtr< DartSnapshot > IsolateSnapshotFromMappings(const std::shared_ptr< const fml::Mapping > &snapshot_data, const std::shared_ptr< const fml::Mapping > &snapshot_instructions)
Create an isolate snapshot from existing fml::Mappings.
bool IsValid() const
Determines if this snapshot contains a heap component. Since the instructions component is optional,...
const uint8_t * GetInstructionsMapping() const
Get a pointer to the read-execute mapping to the instructions snapshot.
static const char * kIsolateDataSymbol
static const char * kVMDataSymbol
const uint8_t * GetDataMapping() const
Get a pointer to the read-only mapping to the heap snapshot.
static const char * kIsolateInstructionsSymbol
bool IsDontNeedSafe() const
Returns whether both the data and instructions mappings are safe to use with madvise(DONTNEED).
static fml::RefPtr< const DartSnapshot > IsolateSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the isolate snapshot.
static const char * kVMInstructionsSymbol
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
virtual size_t GetSize() const =0
static fml::RefPtr< NativeLibrary > CreateForCurrentProcess()
static fml::RefPtr< NativeLibrary > Create(const char *path)
DART_EXPORT bool Dart_DetectNullSafety(const char *script_uri, const char *package_config, const char *original_working_directory, const uint8_t *snapshot_data, const uint8_t *snapshot_instructions, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
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
std::function< std::unique_ptr< fml::Mapping >(void)> MappingCallback
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)