5#include "flutter/runtime/dart_isolate.h"
11#include "flutter/fml/logging.h"
12#include "flutter/fml/posix_wrappers.h"
13#include "flutter/fml/trace_event.h"
14#include "flutter/lib/io/dart_io.h"
15#include "flutter/lib/ui/dart_runtime_hooks.h"
16#include "flutter/lib/ui/dart_ui.h"
17#include "flutter/lib/ui/window/platform_isolate.h"
18#include "flutter/runtime/dart_isolate_group_data.h"
19#include "flutter/runtime/dart_plugin_registrant.h"
20#include "flutter/runtime/dart_service_isolate.h"
21#include "flutter/runtime/dart_vm.h"
22#include "flutter/runtime/dart_vm_lifecycle.h"
23#include "flutter/runtime/isolate_configuration.h"
24#include "flutter/runtime/runtime_controller.h"
28#include "third_party/dart/runtime/include/bin/native_assets_api.h"
29#include "third_party/dart/runtime/include/dart_api.h"
30#include "third_party/dart/runtime/include/dart_tools_api.h"
47class DartErrorString {
55 char**
error() {
return &str_; }
56 const char* str()
const {
return str_; }
57 explicit operator bool()
const {
return str_ !=
nullptr; }
79 flags_.null_safety = enabled;
83 flags_.snapshot_is_dontneed_safe =
value;
98 std::optional<std::string> dart_entrypoint,
99 std::optional<std::string> dart_entrypoint_library,
100 const std::vector<std::string>& dart_entrypoint_args,
101 std::unique_ptr<IsolateConfiguration> isolate_configuration,
104 if (!isolate_snapshot) {
109 if (!isolate_configuration) {
115 isolate_configuration->IsNullSafetyEnabled(*isolate_snapshot));
122 isolate_create_callback,
123 isolate_shutdown_callback,
136 FML_DLOG(ERROR) <<
"Could not shutdown transient isolate.";
141 FML_LOG(
ERROR) <<
"Root isolate was created in an incorrect phase: "
142 <<
static_cast<int>(
isolate->GetPhase());
146 if (!isolate_configuration->PrepareIsolate(*
isolate.get())) {
152 FML_LOG(
ERROR) <<
"Root isolate not in the ready phase for Dart entrypoint "
157 if (
settings.root_isolate_create_callback) {
164 if (root_isolate_create_callback) {
165 root_isolate_create_callback();
168 if (!
isolate->RunFromLibrary(std::move(dart_entrypoint_library),
169 std::move(dart_entrypoint),
170 dart_entrypoint_args)) {
171 FML_LOG(
ERROR) <<
"Could not run the run main Dart entrypoint.";
175 if (
settings.root_isolate_shutdown_callback) {
176 isolate->AddIsolateShutdownCallback(
177 settings.root_isolate_shutdown_callback);
180 shutdown_on_error.Release();
185void DartIsolate::SpawnIsolateShutdownCallback(
186 std::shared_ptr<DartIsolateGroupData>* isolate_group_data,
187 std::shared_ptr<DartIsolate>* isolate_data) {
188 DartIsolate::DartIsolateShutdownCallback(isolate_group_data, isolate_data);
191std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
198 const UIDartState::Context& context,
199 const DartIsolate* spawning_isolate) {
200 TRACE_EVENT0(
"flutter",
"DartIsolate::CreateRootIsolate");
203 std::unique_ptr<std::shared_ptr<DartIsolateGroupData>> isolate_group_data;
205 auto isolate_data = std::make_unique<std::shared_ptr<DartIsolate>>(
206 std::shared_ptr<DartIsolate>(
new DartIsolate(
210 !!spawning_isolate)));
212 DartErrorString
error;
214 auto isolate_flags =
flags.Get();
216 IsolateMaker isolate_maker;
217 if (spawning_isolate) {
220 std::shared_ptr<DartIsolateGroupData>* isolate_group_data,
221 std::shared_ptr<DartIsolate>* isolate_data,
224 spawning_isolate->isolate(),
226 spawning_isolate->GetIsolateGroupData()
227 .GetAdvisoryScriptEntrypoint()
231 DartIsolate::SpawnIsolateShutdownCallback),
234 DartIsolateCleanupCallback),
242 std::make_unique<std::shared_ptr<DartIsolateGroupData>>(
243 std::shared_ptr<DartIsolateGroupData>(
new DartIsolateGroupData(
245 std::move(isolate_snapshot),
246 context.advisory_script_uri,
247 context.advisory_script_entrypoint,
249 isolate_create_callback,
250 isolate_shutdown_callback
252 isolate_maker = [](std::shared_ptr<DartIsolateGroupData>*
254 std::shared_ptr<DartIsolate>* isolate_data,
257 (*isolate_group_data)->GetAdvisoryScriptURI().c_str(),
258 (*isolate_group_data)->GetAdvisoryScriptEntrypoint().c_str(),
259 (*isolate_group_data)->GetIsolateSnapshot()->GetDataMapping(),
260 (*isolate_group_data)->GetIsolateSnapshot()->GetInstructionsMapping(),
261 flags, isolate_group_data, isolate_data,
error);
265 vm_isolate = CreateDartIsolateGroup(std::move(isolate_group_data),
266 std::move(isolate_data), &isolate_flags,
267 error.error(), isolate_maker);
273 if (vm_isolate ==
nullptr) {
277 std::shared_ptr<DartIsolate>* root_isolate_data =
283 return (*root_isolate_data)->GetWeakIsolatePtr();
291 std::shared_ptr<PlatformIsolateManager> platform_isolate_manager =
293 std::weak_ptr<PlatformIsolateManager> weak_platform_isolate_manager =
294 platform_isolate_manager;
295 if (platform_isolate_manager->HasShutdownMaybeFalseNegative()) {
298 FML_LOG(INFO) <<
"CreatePlatformIsolate called after shutdown";
310 auto isolate_group_data = std::shared_ptr<DartIsolateGroupData>(
311 *
static_cast<std::shared_ptr<DartIsolateGroupData>*
>(
321 settings.unhandled_exception_callback = [](
const std::string&
error,
322 const std::string& stack_trace) {
330 settings.task_observer_add = [old_task_observer_add, platform_task_runner,
331 weak_platform_isolate_manager](
333 platform_task_runner->
PostTask([old_task_observer_add,
334 weak_platform_isolate_manager,
key,
336 std::shared_ptr<PlatformIsolateManager> platform_isolate_manager =
337 weak_platform_isolate_manager.lock();
338 if (platform_isolate_manager ==
nullptr ||
339 platform_isolate_manager->HasShutdown()) {
342 FML_LOG(INFO) <<
"Shutdown before platform isolate task observer added";
352 isolate_group_data->GetAdvisoryScriptEntrypoint();
353 auto isolate_data = std::make_unique<std::shared_ptr<DartIsolate>>(
354 std::shared_ptr<DartIsolate>(
357 IsolateMaker isolate_maker =
359 std::shared_ptr<DartIsolateGroupData>* unused_isolate_group_data,
367 DartIsolate::SpawnIsolateShutdownCallback),
370 DartIsolateCleanupCallback),
375 nullptr, std::move(isolate_data),
nullptr,
error, isolate_maker);
383 if (!platform_isolate_manager->RegisterPlatformIsolate(platform_isolate)) {
387 FML_LOG(INFO) <<
"Shutdown during platform isolate creation";
397 platform_task_runner->
PostTask([entry_point_handle, platform_isolate,
398 weak_platform_isolate_manager]() {
399 std::shared_ptr<PlatformIsolateManager> platform_isolate_manager =
400 weak_platform_isolate_manager.lock();
401 if (platform_isolate_manager ==
nullptr ||
402 platform_isolate_manager->HasShutdown()) {
405 FML_LOG(INFO) <<
"Shutdown before platform isolate entry point";
427 return platform_isolate;
431 bool is_root_isolate,
433 bool is_spawning_in_group)
442 may_insecurely_connect_to_all_domains_(
443 settings.may_insecurely_connect_to_all_domains),
444 is_platform_isolate_(
false),
445 is_spawning_in_group_(is_spawning_in_group),
446 domain_network_policy_(
settings.domain_network_policy) {
450DartIsolate::DartIsolate(
452 const UIDartState::Context& context,
453 std::shared_ptr<PlatformIsolateManager> platform_isolate_manager)
454 : UIDartState(
settings.task_observer_add,
457 settings.unhandled_exception_callback,
459 DartVMRef::GetIsolateNameServer(),
462 may_insecurely_connect_to_all_domains_(
463 settings.may_insecurely_connect_to_all_domains),
464 is_platform_isolate_(
true),
465 is_spawning_in_group_(
false),
466 domain_network_policy_(
settings.domain_network_policy),
467 platform_isolate_manager_(
std::move(platform_isolate_manager)) {
483 std::string service_id(service_id_buf);
484 free(
const_cast<char*
>(service_id_buf));
488bool DartIsolate::Initialize(
Dart_Isolate dart_isolate) {
508 if (is_platform_isolate_) {
509 SetMessageHandlingTaskRunner(
GetTaskRunners().GetPlatformTaskRunner(),
512 SetMessageHandlingTaskRunner(
GetTaskRunners().GetUITaskRunner(),
false);
525 if (!UpdateThreadPoolNames()) {
534 return message_handling_task_runner_;
538 intptr_t loading_unit_id,
539 std::unique_ptr<const fml::Mapping> snapshot_data,
540 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
545 std::move(snapshot_data), std::move(snapshot_instructions));
548 loading_unit_id, dart_snapshot->GetDataMapping(),
549 dart_snapshot->GetInstructionsMapping());
555 loading_unit_snapshots_.insert(dart_snapshot);
560 const std::string& error_message,
564 loading_unit_id, error_message.c_str(), transient);
568void DartIsolate::SetMessageHandlingTaskRunner(
570 bool post_directly_to_runner) {
575 message_handling_task_runner_ = runner;
580 post_directly_to_runner =
true;
583 if (post_directly_to_runner) {
585 runner->
PostTask([task = std::move(task)]() {
593 task_queues->RegisterTask(
595 [task = std::move(task)]() {
596 TRACE_EVENT0(
"flutter",
"DartIsolate::HandleMessage");
609bool DartIsolate::UpdateThreadPoolNames()
const {
614 if (
auto task_runner = task_runners.GetRasterTaskRunner()) {
615 task_runner->PostTask(
616 [label = task_runners.GetLabel() + std::string{
".raster"}]() {
617 Dart_SetThreadName(label.c_str());
621 if (
auto task_runner = task_runners.GetUITaskRunner()) {
622 task_runner->PostTask(
623 [label = task_runners.GetLabel() + std::string{
".ui"}]() {
624 Dart_SetThreadName(label.c_str());
628 if (
auto task_runner = task_runners.GetIOTaskRunner()) {
629 task_runner->PostTask(
630 [label = task_runners.GetLabel() + std::string{
".io"}]() {
631 Dart_SetThreadName(label.c_str());
635 if (
auto task_runner = task_runners.GetPlatformTaskRunner()) {
636 task_runner->PostTask(
637 [label = task_runners.GetLabel() + std::string{
".platform"}]() {
638 Dart_SetThreadName(label.c_str());
645bool DartIsolate::LoadLibraries() {
654 domain_network_policy_);
663 if (!is_service_isolate) {
665 "ui", std::make_unique<tonic::DartClassProvider>(
this,
"dart:ui"));
673 TRACE_EVENT0(
"flutter",
"DartIsolate::PrepareForRunningFromPrecompiledCode");
684 if (!MarkIsolateRunnable()) {
690 return isolate->PrepareForRunningFromPrecompiledCode();
696 if (isolate_create_callback) {
697 isolate_create_callback();
704bool DartIsolate::LoadKernel(
const std::shared_ptr<const fml::Mapping>& mapping,
706 if (!
Dart_IsKernel(mapping->GetMapping(), mapping->GetSize())) {
732 const std::shared_ptr<const fml::Mapping>& mapping,
735 TRACE_EVENT0(
"flutter",
"DartIsolate::PrepareForRunningFromKernel");
746 if (!child_isolate && !is_spawning_in_group_) {
747 if (!mapping || mapping->GetSize() == 0) {
754 if (!LoadKernel(mapping, last_piece)) {
768 if (!MarkIsolateRunnable()) {
779 for (uint64_t
i = 0;
i < buffers.size();
i++) {
780 bool last_piece =
i + 1 == buffers.size();
781 const std::shared_ptr<const fml::Mapping>&
buffer = buffers.at(
i);
794 if (isolate_create_callback) {
795 isolate_create_callback();
804 std::vector<std::shared_ptr<const fml::Mapping>> kernels) {
805 const auto count = kernels.size();
810 for (
size_t i = 0;
i <
count; ++
i) {
811 bool last = (
i == (
count - 1));
822 std::vector<std::unique_ptr<const fml::Mapping>> kernels) {
823 std::vector<std::shared_ptr<const fml::Mapping>> shared_kernels;
824 shared_kernels.reserve(kernels.size());
825 for (
auto& kernel : kernels) {
826 shared_kernels.emplace_back(std::move(kernel));
831bool DartIsolate::MarkIsolateRunnable() {
832 TRACE_EVENT0(
"flutter",
"DartIsolate::MarkIsolateRunnable");
862 FML_LOG(
ERROR) <<
"Could not resolve main entrypoint function.";
868 "_getStartMainIsolateFunction", {});
871 FML_LOG(
ERROR) <<
"Could not resolve main entrypoint trampoline.";
877 {start_main_isolate_function, user_entrypoint_function,
args}))) {
878 FML_LOG(
ERROR) <<
"Could not invoke the main entrypoint.";
886 std::optional<std::string> entrypoint,
887 const std::vector<std::string>&
args) {
895 auto library_handle =
896 library_name.has_value() && !library_name.value().empty()
899 auto entrypoint_handle = entrypoint.has_value() && !entrypoint.value().empty()
910 auto user_entrypoint_function =
936 if (vm_isolate !=
nullptr) {
947Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate(
948 const char* package_root,
949 const char* package_config,
956 "Could not access VM data to initialize isolates. This may be because "
957 "the VM has initialized shutdown on another thread already.");
961 const auto&
settings = vm_data->GetSettings();
967 flags->load_vmservice_library =
true;
969#if (FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_DEBUG)
973 flags->null_safety = vm_data->GetServiceIsolateSnapshotNullSafety();
976 UIDartState::Context context(
981 std::weak_ptr<DartIsolate> weak_service_isolate =
982 DartIsolate::CreateRootIsolate(vm_data->GetSettings(),
983 vm_data->GetServiceIsolateSnapshot(),
990 std::shared_ptr<DartIsolate> service_isolate = weak_service_isolate.lock();
991 if (!service_isolate) {
1003 settings.disable_service_auth_codes,
1004 settings.enable_service_port_fallback,
1013 if (
auto callback = vm_data->GetSettings().service_isolate_create_callback) {
1018 service_protocol->ToggleHooks(
true);
1021 <<
"Could not acquire the service protocol handlers. This might be "
1022 "because the VM has already begun teardown on another thread.";
1025 return service_isolate->isolate();
1029 std::shared_ptr<DartIsolateGroupData>* isolate_group_data =
1030 static_cast<std::shared_ptr<DartIsolateGroupData>*
>(
1032 return **isolate_group_data;
1041Dart_Isolate DartIsolate::DartIsolateGroupCreateCallback(
1042 const char* advisory_script_uri,
1043 const char* advisory_script_entrypoint,
1044 const char* package_root,
1045 const char* package_config,
1047 std::shared_ptr<DartIsolate>* parent_isolate_data,
1049 TRACE_EVENT0(
"flutter",
"DartIsolate::DartIsolateGroupCreateCallback");
1050 if (parent_isolate_data ==
nullptr &&
1057 return DartCreateAndStartServiceIsolate(package_root,
1064 if (!parent_isolate_data) {
1068 DartIsolateGroupData& parent_group_data =
1069 (*parent_isolate_data)->GetIsolateGroupData();
1073 std::string error_msg =
1074 std::string(
"Unsupported isolate URI: ") + advisory_script_uri;
1079 auto isolate_group_data =
1080 std::make_unique<std::shared_ptr<DartIsolateGroupData>>(
1081 std::shared_ptr<DartIsolateGroupData>(
new DartIsolateGroupData(
1082 parent_group_data.GetSettings(),
1083 parent_group_data.GetIsolateSnapshot(), advisory_script_uri,
1084 advisory_script_entrypoint,
1085 parent_group_data.GetChildIsolatePreparer(),
1086 parent_group_data.GetIsolateCreateCallback(),
1087 parent_group_data.GetIsolateShutdownCallback())));
1089 TaskRunners null_task_runners(advisory_script_uri,
1095 UIDartState::Context context(null_task_runners);
1096 context.advisory_script_uri = advisory_script_uri;
1097 context.advisory_script_entrypoint = advisory_script_entrypoint;
1098 auto isolate_data = std::make_unique<std::shared_ptr<DartIsolate>>(
1099 std::shared_ptr<DartIsolate>(
1100 new DartIsolate((*isolate_group_data)->GetSettings(),
1105 std::move(isolate_group_data), std::move(isolate_data),
flags,
error,
1106 [](std::shared_ptr<DartIsolateGroupData>* isolate_group_data,
1110 (*isolate_group_data)->GetAdvisoryScriptURI().c_str(),
1111 (*isolate_group_data)->GetAdvisoryScriptEntrypoint().c_str(),
1112 (*isolate_group_data)->GetIsolateSnapshot()->GetDataMapping(),
1113 (*isolate_group_data)
1114 ->GetIsolateSnapshot()
1115 ->GetInstructionsMapping(),
1116 flags, isolate_group_data, isolate_data,
error);
1127bool DartIsolate::DartIsolateInitializeCallback(
void** child_callback_data,
1129 TRACE_EVENT0(
"flutter",
"DartIsolate::DartIsolateInitializeCallback");
1132 *
error =
fml::strdup(
"Isolate should be available in initialize callback.");
1137 auto* isolate_group_data =
1138 static_cast<std::shared_ptr<DartIsolateGroupData>*
>(
1141 TaskRunners null_task_runners((*isolate_group_data)->GetAdvisoryScriptURI(),
1147 UIDartState::Context context(null_task_runners);
1148 context.advisory_script_uri = (*isolate_group_data)->GetAdvisoryScriptURI();
1149 context.advisory_script_entrypoint =
1150 (*isolate_group_data)->GetAdvisoryScriptEntrypoint();
1151 auto embedder_isolate = std::make_unique<std::shared_ptr<DartIsolate>>(
1152 std::shared_ptr<DartIsolate>(
1153 new DartIsolate((*isolate_group_data)->GetSettings(),
1158 if (!InitializeIsolate(*embedder_isolate,
isolate,
error)) {
1164 *child_callback_data = embedder_isolate.release();
1170 auto* isolate_group_data =
1171 static_cast<std::shared_ptr<DartIsolateGroupData>*
>(
1173 const std::string& script_uri = (*isolate_group_data)->GetAdvisoryScriptURI();
1180 memset(&native_assets, 0,
sizeof(native_assets));
1191 std::unique_ptr<std::shared_ptr<DartIsolateGroupData>> isolate_group_data,
1192 std::unique_ptr<std::shared_ptr<DartIsolate>> isolate_data,
1195 const DartIsolate::IsolateMaker& make_isolate) {
1196 TRACE_EVENT0(
"flutter",
"DartIsolate::CreateDartIsolateGroup");
1200 make_isolate(isolate_group_data.get(), isolate_data.get(),
flags,
error);
1206 bool success =
false;
1211 std::shared_ptr<DartIsolate> embedder_isolate(*isolate_data);
1212 isolate_group_data.release();
1213 isolate_data.release();
1218 success = InitializeIsolate(embedder_isolate,
isolate,
error);
1230bool DartIsolate::InitializeIsolate(
1231 const std::shared_ptr<DartIsolate>& embedder_isolate,
1234 TRACE_EVENT0(
"flutter",
"DartIsolate::InitializeIsolate");
1235 if (!embedder_isolate->Initialize(
isolate)) {
1241 if (!embedder_isolate->LoadLibraries()) {
1243 "Embedder could not load libraries in the new Dart isolate.");
1252 if (!embedder_isolate->IsRootIsolate()) {
1253 auto child_isolate_preparer =
1254 embedder_isolate->GetIsolateGroupData().GetChildIsolatePreparer();
1256 if (!child_isolate_preparer(embedder_isolate.get())) {
1267void DartIsolate::DartIsolateShutdownCallback(
1268 std::shared_ptr<DartIsolateGroupData>* isolate_group_data,
1269 std::shared_ptr<DartIsolate>* isolate_data) {
1270 TRACE_EVENT0(
"flutter",
"DartIsolate::DartIsolateShutdownCallback");
1275 if (isolate_data ==
nullptr) {
1279 isolate_data->get()->OnShutdownCallback();
1283void DartIsolate::DartIsolateGroupCleanupCallback(
1284 std::shared_ptr<DartIsolateGroupData>* isolate_data) {
1285 TRACE_EVENT0(
"flutter",
"DartIsolate::DartIsolateGroupCleanupCallback");
1286 delete isolate_data;
1290void DartIsolate::DartIsolateCleanupCallback(
1291 std::shared_ptr<DartIsolateGroupData>* isolate_group_data,
1292 std::shared_ptr<DartIsolate>* isolate_data) {
1293 TRACE_EVENT0(
"flutter",
"DartIsolate::DartIsolateCleanupCallback");
1294 delete isolate_data;
1298 return std::static_pointer_cast<DartIsolate>(shared_from_this());
1302 shutdown_callbacks_.emplace_back(std::make_unique<AutoFireClosure>(
closure));
1305void DartIsolate::OnShutdownCallback() {
1307 if (
state !=
nullptr) {
1308 state->SetIsShuttingDown();
1319 if (is_platform_isolate_) {
1320 FML_DCHECK(platform_isolate_manager_ !=
nullptr);
1321 platform_isolate_manager_->RemovePlatformIsolate(
isolate());
1324 shutdown_callbacks_.clear();
1328 if (isolate_shutdown_callback) {
1329 isolate_shutdown_callback();
1333Dart_Handle DartIsolate::OnDartLoadLibrary(intptr_t loading_unit_id) {
1339 const std::string error_message =
1340 "Platform Configuration was null. Deferred library load request "
1341 "for loading unit id " +
1348 const std::shared_ptr<const fml::Mapping>& mapping) {
1353 auto* isolate_group_data =
1354 static_cast<std::shared_ptr<DartIsolateGroupData>*
>(
1357 (*isolate_group_data)->AddKernelBuffer(mapping);
1374DartIsolate::AutoFireClosure::~AutoFireClosure() {
static void * DlopenSystem(const char *path, char **error)
static void * DlopenExecutable(char **error)
static void * DlopenProcess(char **error)
static void * DlopenRelative(const char *path, const char *script_uri, char **error)
static void * Dlsym(void *handle, const char *symbol, char **error)
static void * DlopenAbsolute(const char *path, char **error)
static void InitForIsolate(bool may_insecurely_connect_to_all_domains, const std::string &domain_network_policy)
const fml::closure & GetIsolateShutdownCallback() const
void SetChildIsolatePreparer(const ChildIsolatePreparer &value)
const fml::closure & GetIsolateCreateCallback() const
void AddKernelBuffer(const std::shared_ptr< const fml::Mapping > &buffer)
Adds a kernel buffer mapping to the kernels loaded for this isolate group.
void SetNullSafetyEnabled(bool enabled)
void SetIsDontNeedSafe(bool value)
Dart_IsolateFlags Get() const
Represents an instance of a live isolate. An isolate is a separate Dart execution context....
bool PrepareForRunningFromKernel(const std::shared_ptr< const fml::Mapping > &kernel, bool child_isolate, bool last_piece)
Prepare the isolate for running for a a list of kernel files.
std::string GetServiceId()
Returns the ID for an isolate which is used to query the service protocol.
void LoadLoadingUnitError(intptr_t loading_unit_id, const std::string &error_message, bool transient)
std::weak_ptr< DartIsolate > GetWeakIsolatePtr()
A weak pointer to the Dart isolate instance. This instance may only be used on the task runner that c...
Dart_Isolate CreatePlatformIsolate(Dart_Handle entry_point, char **error) override
Creates a new isolate in the same group as this isolate, which runs on the platform thread....
static std::weak_ptr< DartIsolate > CreateRunningRootIsolate(const Settings &settings, const fml::RefPtr< const DartSnapshot > &isolate_snapshot, std::unique_ptr< PlatformConfiguration > platform_configuration, Flags flags, const fml::closure &root_isolate_create_callback, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, std::optional< std::string > dart_entrypoint, std::optional< std::string > dart_entrypoint_library, const std::vector< std::string > &dart_entrypoint_args, std::unique_ptr< IsolateConfiguration > isolate_configuration, const UIDartState::Context &context, const DartIsolate *spawning_isolate=nullptr)
Creates an instance of a root isolate and returns a weak pointer to the same. The isolate instance ma...
bool PrepareForRunningFromKernels(std::vector< std::shared_ptr< const fml::Mapping > > kernels)
Prepare the isolate for running for a a list of kernel files.
static Dart_Handle LoadLibraryFromKernel(const std::shared_ptr< const fml::Mapping > &mapping)
bool RunFromLibrary(std::optional< std::string > library_name, std::optional< std::string > entrypoint, const std::vector< std::string > &args)
Transition the root isolate to the Phase::Running phase and invoke the main entrypoint (the "main" me...
DartIsolateGroupData & GetIsolateGroupData()
void AddIsolateShutdownCallback(const fml::closure &closure)
Registers a callback that will be invoked in isolate scope just before the isolate transitions to the...
fml::RefPtr< fml::TaskRunner > GetMessageHandlingTaskRunner() const
The task runner on which the Dart code for the root isolate is running. For the root isolate,...
bool Shutdown()
Transition the isolate to the Phase::Shutdown phase. The only thing left to do is to collect the isol...
Phase GetPhase() const
The current phase of the isolate. The engine represents all dart isolates as being in one of the know...
bool PrepareForRunningFromPrecompiledCode()
Prepare the isolate for running for a precompiled code bundle. The Dart VM must be configured for run...
bool LoadLoadingUnit(intptr_t loading_unit_id, std::unique_ptr< const fml::Mapping > snapshot_data, std::unique_ptr< const fml::Mapping > snapshot_instructions)
Phase
The engine represents all dart isolates as being in one of the known phases. By invoking various meth...
static void Install(bool is_ui_isolate, const std::string &script_uri)
static bool Startup(const std::string &server_ip, intptr_t server_port, Dart_LibraryTagHandler embedder_tag_handler, bool disable_origin_check, bool disable_service_auth_codes, bool enable_service_port_fallback, char **error)
Start the service isolate. This call may only be made in the Dart VM initiated isolate creation callb...
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.
static void InitForIsolate(const Settings &settings)
static std::shared_ptr< ServiceProtocol > GetServiceProtocol()
static std::shared_ptr< const DartVMData > GetVMData()
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
PlatformConfiguration * platform_configuration() const
UnhandledExceptionCallback unhandled_exception_callback() const
bool IsRootIsolate() const
const TaskRunners & GetTaskRunners() const
std::shared_ptr< IsolateNameServer > GetIsolateNameServer() const
const std::string & GetAdvisoryScriptURI() const
static UIDartState * Current()
static MessageLoopTaskQueues * GetInstance()
Wraps a closure that is invoked in the destructor unless released by the caller.
virtual void PostTask(const fml::closure &task) override
virtual TaskQueueId GetTaskQueueId()
void add_provider(const std::string &library_name, std::unique_ptr< DartClassProvider > provider)
std::function< void(std::function< void(void)>)> TaskDispatcher
void Initialize(TaskDispatcher dispatcher)
void SetIsolate(Dart_Isolate isolate)
DartMessageHandler & message_handler()
static DartState * Current()
DartClassLibrary & class_library()
static Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
DART_EXPORT Dart_Isolate Dart_CreateIsolateGroup(const char *script_uri, const char *name, const uint8_t *isolate_snapshot_data, const uint8_t *isolate_snapshot_instructions, Dart_IsolateFlags *flags, void *isolate_group_data, void *isolate_data, char **error)
DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object)
DART_EXPORT void Dart_IsolateFlagsInitialize(Dart_IsolateFlags *flags)
DART_EXPORT Dart_Handle Dart_GetNonNullableType(Dart_Handle library, Dart_Handle class_name, intptr_t number_of_type_arguments, Dart_Handle *type_arguments)
DART_EXPORT DART_WARN_UNUSED_RESULT char * Dart_IsolateMakeRunnable(Dart_Isolate isolate)
void(* Dart_IsolateCleanupCallback)(void *isolate_group_data, void *isolate_data)
DART_EXPORT Dart_Handle Dart_SetDeferredLoadHandler(Dart_DeferredLoadHandler handler)
DART_EXPORT void Dart_ShutdownIsolate(void)
struct _Dart_Handle * Dart_Handle
DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object)
DART_EXPORT Dart_Isolate Dart_CreateIsolateInGroup(Dart_Isolate group_member, const char *name, Dart_IsolateShutdownCallback shutdown_callback, Dart_IsolateCleanupCallback cleanup_callback, void *child_isolate_data, char **error)
struct _Dart_Isolate * Dart_Isolate
DART_EXPORT bool Dart_IsFatalError(Dart_Handle handle)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_LoadLibraryFromKernel(const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_FinalizeLoading(bool complete_futures)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_SetField(Dart_Handle container, Dart_Handle name, Dart_Handle value)
DART_EXPORT Dart_Isolate Dart_CurrentIsolate(void)
DART_EXPORT bool Dart_IsKernel(const uint8_t *buffer, intptr_t buffer_size)
Dart_Handle Dart_PersistentHandle
DART_EXPORT Dart_Handle Dart_False(void)
DART_EXPORT Dart_Handle Dart_NewApiError(const char *error)
DART_EXPORT Dart_Handle Dart_Null(void)
void(* Dart_IsolateShutdownCallback)(void *isolate_group_data, void *isolate_data)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_DeferredLoadComplete(intptr_t loading_unit_id, const uint8_t *snapshot_data, const uint8_t *snapshot_instructions)
DART_EXPORT const char * Dart_IsolateServiceId(Dart_Isolate isolate)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
DART_EXPORT void * Dart_IsolateData(Dart_Isolate isolate)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
DART_EXPORT void * Dart_IsolateGroupData(Dart_Isolate isolate)
DART_EXPORT Dart_Handle Dart_GetStickyError(void)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name)
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
#define DART_VM_SERVICE_ISOLATE_NAME
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT void Dart_ExitIsolate(void)
DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate)
DART_EXPORT void * Dart_CurrentIsolateGroupData(void)
DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_DeferredLoadCompleteError(intptr_t loading_unit_id, const char *error_message, bool transient)
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler(Dart_LibraryTagHandler handler)
DART_EXPORT Dart_Handle Dart_RootLibrary(void)
DART_EXPORT void Dart_InitializeNativeAssetsResolver(NativeAssetsApi *native_assets_api)
DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library)
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
const uint8_t uint32_t uint32_t GError ** error
#define FML_DLOG(severity)
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Dart_NativeFunction function
static void * NativeAssetsDlopenRelative(const char *path, char **error)
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 void InitDartFFIForIsolateGroup()
std::function< void(intptr_t, fml::closure)> TaskObserverAdd
constexpr char kFileUriPrefix[]
bool InvokeDartPluginRegistrantIfAvailable(Dart_Handle library_handle)
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
bool FindAndInvokeDartPluginRegistrant()
static bool InvokeMainEntrypoint(Dart_Handle user_entrypoint_function, Dart_Handle args)
char * strdup(const char *str1)
std::function< void()> closure
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvokeVoid(Dart_Handle closure)
bool CheckAndHandleError(Dart_Handle handle)
Dart_Handle DartInvokeField(Dart_Handle target, const char *name, std::initializer_list< Dart_Handle > args)
static SkString to_string(int n)
Dart_NativeAssetsDlopenCallback dlopen_system
Dart_NativeAssetsDlopenCallback dlopen_absolute
Dart_NativeAssetsDlopenCallbackNoPath dlopen_process
Dart_NativeAssetsDlopenCallback dlopen_relative
Dart_NativeAssetsDlsymCallback dlsym
Dart_NativeAssetsDlopenCallbackNoPath dlopen_executable
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
std::string advisory_script_uri
std::string advisory_script_entrypoint
#define TRACE_EVENT0(category_group, name)