Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Classes | Functions | Variables
dart_runner Namespace Reference

Namespaces

namespace  testing
 

Classes

class  DartComponentController
 Starts a Dart component written in CFv2. More...
 
class  DartRunner
 
class  DartTestComponentController
 

Functions

void InitBuiltinLibrariesForIsolate (const std::string &script_uri, fdio_ns_t *namespc, int stdoutfd, int stderrfd, zx::channel directory_request, bool service_isolate)
 
bool IsTestProgram (const fuchsia::data::Dictionary &program_metadata)
 
Dart_Isolate CreateServiceIsolate (const char *uri, Dart_IsolateFlags *flags_unused, char **error)
 
Dart_Handle GetVMServiceAssetsArchiveCallback ()
 

Variables

constexpr char kArgsKey [] = "args"
 
uint8_t const *const vm_isolate_snapshot_buffer
 
uint8_t const *const isolate_snapshot_buffer
 

Function Documentation

◆ CreateServiceIsolate()

Dart_Isolate dart_runner::CreateServiceIsolate ( const char *  uri,
Dart_IsolateFlags flags_unused,
char **  error 
)

Definition at line 75 of file service_isolate.cc.

78 {
79 Dart_SetEmbedderInformationCallback(EmbedderInformationCallback);
80
81 const uint8_t *vmservice_data = nullptr, *vmservice_instructions = nullptr;
82
83#if defined(AOT_RUNTIME)
84 // The VM service was compiled as a separate app.
85 const char* snapshot_path = "/pkg/data/vmservice_snapshot.so";
86 if (elf_snapshot.Load(nullptr, snapshot_path)) {
87 vmservice_data = elf_snapshot.IsolateData();
88 vmservice_instructions = elf_snapshot.IsolateInstrs();
89 if (vmservice_data == nullptr || vmservice_instructions == nullptr) {
90 return nullptr;
91 }
92 } else {
93 // The VM service was compiled as a separate app.
94 const char* snapshot_data_path =
95 "/pkg/data/vmservice_isolate_snapshot_data.bin";
96 const char* snapshot_instructions_path =
97 "/pkg/data/vmservice_isolate_snapshot_instructions.bin";
98#else
99 // The VM service is embedded in the core snapshot.
100 const char* snapshot_data_path = "/pkg/data/isolate_core_snapshot_data.bin";
101 const char* snapshot_instructions_path =
102 "/pkg/data/isolate_core_snapshot_instructions.bin";
103#endif
104
106 nullptr, snapshot_data_path, mapped_isolate_snapshot_data)) {
107 *error = strdup("Failed to load snapshot for service isolate");
108 FML_LOG(ERROR) << *error;
109 return nullptr;
110 }
112 nullptr, snapshot_instructions_path,
113 mapped_isolate_snapshot_instructions, true /* executable */)) {
114 *error = strdup("Failed to load snapshot for service isolate");
115 FML_LOG(ERROR) << *error;
116 return nullptr;
117 }
118
119 vmservice_data = mapped_isolate_snapshot_data.address();
120 vmservice_instructions = mapped_isolate_snapshot_instructions.address();
121#if defined(AOT_RUNTIME)
122 }
123#endif
124
127 flags.null_safety = true;
128
129 auto state = new std::shared_ptr<tonic::DartState>(new tonic::DartState());
131 uri, DART_VM_SERVICE_ISOLATE_NAME, vmservice_data, vmservice_instructions,
132 &flags, state, state, error);
133 if (!isolate) {
134 FML_LOG(ERROR) << "Dart_CreateIsolateGroup failed: " << *error;
135 return nullptr;
136 }
137
138 state->get()->SetIsolate(isolate);
139
140 // Setup native entries.
141 service_natives = new tonic::DartLibraryNatives();
142 service_natives->Register({
143 {"VMServiceIO_NotifyServerState", NotifyServerState, 1, true},
144 {"VMServiceIO_Shutdown", Shutdown, 0, true},
145 });
146
148
149 Dart_Handle library =
150 Dart_LookupLibrary(Dart_NewStringFromCString("dart:vmservice_io"));
151 SHUTDOWN_ON_ERROR(library);
154 result = Dart_SetNativeResolver(library, GetNativeFunction, GetSymbol);
156
157 // _ip = '127.0.0.1'
159 Dart_NewStringFromCString("127.0.0.1"));
161
162 // _port = 0
164 Dart_NewInteger(0));
166
167 // _autoStart = true
168 result = Dart_SetField(library, Dart_NewStringFromCString("_autoStart"),
169 Dart_NewBoolean(true));
171
172 // _originCheckDisabled = false
173 result =
174 Dart_SetField(library, Dart_NewStringFromCString("_originCheckDisabled"),
175 Dart_NewBoolean(false));
177
178 // _authCodesDisabled = false
179 result =
180 Dart_SetField(library, Dart_NewStringFromCString("_authCodesDisabled"),
181 Dart_NewBoolean(false));
183
184 InitBuiltinLibrariesForIsolate(std::string(uri), nullptr, fileno(stdout),
185 fileno(stderr), zx::channel(), true);
186
187 // Make runnable.
191 if (*error != nullptr) {
192 FML_LOG(ERROR) << *error;
193 Dart_EnterIsolate(isolate);
195 return nullptr;
196 }
197 return isolate;
198} // namespace dart_runner
static bool LoadFromNamespace(fdio_ns_t *namespc, const std::string &path, MappedResource &resource, bool executable=false)
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 void Dart_IsolateFlagsInitialize(Dart_IsolateFlags *flags)
DART_EXPORT DART_WARN_UNUSED_RESULT char * Dart_IsolateMakeRunnable(Dart_Isolate isolate)
DART_EXPORT Dart_Handle Dart_SetNativeResolver(Dart_Handle library, Dart_NativeEntryResolver resolver, Dart_NativeEntrySymbol symbol)
DART_EXPORT void Dart_EnterScope(void)
DART_EXPORT void Dart_ExitScope(void)
DART_EXPORT void Dart_ShutdownIsolate(void)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
struct _Dart_Isolate * Dart_Isolate
Definition dart_api.h:88
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_SetField(Dart_Handle container, Dart_Handle name, Dart_Handle value)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
DART_EXPORT Dart_Handle Dart_NewBoolean(bool value)
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
#define DART_VM_SERVICE_ISOLATE_NAME
Definition dart_api.h:3831
DART_EXPORT void Dart_ExitIsolate(void)
DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library)
DART_EXPORT void Dart_SetEmbedderInformationCallback(Dart_EmbedderInformationCallback callback)
AtkStateType state
FlutterSemanticsFlag flags
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
#define FML_LOG(severity)
Definition logging.h:82
void NotifyServerState(Dart_NativeArguments args)
void InitBuiltinLibrariesForIsolate(const std::string &script_uri, fdio_ns_t *namespc, int stdoutfd, int stderrfd, zx::channel directory_request, bool service_isolate)
char * strdup(const char *str1)
#define SHUTDOWN_ON_ERROR(handle)
#define ERROR(message)

◆ GetVMServiceAssetsArchiveCallback()

Dart_Handle dart_runner::GetVMServiceAssetsArchiveCallback ( )

Definition at line 200 of file service_isolate.cc.

200 {
201 dart_utils::MappedResource vm_service_tar;
203 nullptr, "/pkg/data/observatory.tar", vm_service_tar)) {
204 FML_LOG(ERROR) << "Failed to load Observatory assets";
205 return nullptr;
206 }
207 // TODO(rmacnak): Should we avoid copying the tar? Or does the service
208 // library not hold onto it anyway?
210 reinterpret_cast<const uint8_t*>(vm_service_tar.address()),
211 vm_service_tar.size());
212}
const uint8_t * address() const

◆ InitBuiltinLibrariesForIsolate()

void dart_runner::InitBuiltinLibrariesForIsolate ( const std::string &  script_uri,
fdio_ns_t *  namespc,
int  stdoutfd,
int  stderrfd,
zx::channel  directory_request,
bool  service_isolate 
)

Definition at line 99 of file builtin_libraries.cc.

104 {
105 // dart:fuchsia --------------------------------------------------------------
106 // dart runner doesn't care about scenic view ref.
107 if (!service_isolate) {
108 fuchsia::dart::Initialize(std::move(directory_request), std::nullopt);
109 }
110
111 // dart:fuchsia.builtin ------------------------------------------------------
112
113 Dart_Handle builtin_lib = Dart_LookupLibrary(ToDart("dart:fuchsia.builtin"));
115 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, BuiltinNativeLookup,
116 BuiltinNativeSymbol);
118
119 // dart:io -------------------------------------------------------------------
120
121 Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io"));
126
127 // dart:zircon ---------------------------------------------------------------
128
129 Dart_Handle zircon_lib = Dart_LookupLibrary(ToDart("dart:zircon"));
131 // NativeResolver already set by fuchsia::dart::Initialize().
132
133 // Core libraries ------------------------------------------------------------
134
135 Dart_Handle async_lib = Dart_LookupLibrary(ToDart("dart:async"));
137
138 Dart_Handle core_lib = Dart_LookupLibrary(ToDart("dart:core"));
140
141 Dart_Handle internal_lib = Dart_LookupLibrary(ToDart("dart:_internal"));
143
144 Dart_Handle isolate_lib = Dart_LookupLibrary(ToDart("dart:isolate"));
146
147#if !defined(AOT_RUNTIME)
148 // AOT: These steps already happened at compile time in gen_snapshot.
149
150 // We need to ensure that all the scripts loaded so far are finalized
151 // as we are about to invoke some Dart code below to set up closures.
154#endif
155
156 // Setup the internal library's 'internalPrint' function.
158 Dart_Invoke(builtin_lib, ToDart("_getPrintClosure"), 0, nullptr);
160
161 result = Dart_SetField(internal_lib, ToDart("_printClosure"), print);
163
164 // Set up the 'scheduleImmediate' closure.
165 Dart_Handle schedule_immediate_closure;
166 if (service_isolate) {
167 // Running on dart::ThreadPool.
168 schedule_immediate_closure = Dart_Invoke(
169 isolate_lib, ToDart("_getIsolateScheduleImmediateClosure"), 0, nullptr);
170 } else {
171 // Running on async::Loop.
172 schedule_immediate_closure = Dart_Invoke(
173 builtin_lib, ToDart("_getScheduleMicrotaskClosure"), 0, nullptr);
174 }
175 FML_CHECK(!tonic::CheckAndHandleError(schedule_immediate_closure));
176
177 Dart_Handle schedule_args[1];
178 schedule_args[0] = schedule_immediate_closure;
179 result = Dart_Invoke(async_lib, ToDart("_setScheduleImmediateClosure"), 1,
180 schedule_args);
182
183 // Set up the namespace in dart:io.
184 Dart_Handle namespace_type =
185 Dart_GetNonNullableType(io_lib, ToDart("_Namespace"), 0, nullptr);
186 FML_CHECK(!tonic::CheckAndHandleError(namespace_type));
187
188 Dart_Handle namespace_args[1];
189 namespace_args[0] = ToDart(reinterpret_cast<intptr_t>(namespc));
190 result =
191 Dart_Invoke(namespace_type, ToDart("_setupNamespace"), 1, namespace_args);
193
194 // Set up the namespace in dart:zircon.
195 namespace_type =
196 Dart_GetNonNullableType(zircon_lib, ToDart("_Namespace"), 0, nullptr);
197 FML_CHECK(!tonic::CheckAndHandleError(namespace_type));
198
199 result = Dart_SetField(namespace_type, ToDart("_namespace"),
200 ToDart(reinterpret_cast<intptr_t>(namespc)));
202
203 // Set up stdout and stderr.
204 Dart_Handle stdio_args[3];
205 stdio_args[0] = Dart_NewInteger(0);
206 stdio_args[1] = Dart_NewInteger(stdoutfd);
207 stdio_args[2] = Dart_NewInteger(stderrfd);
208 result = Dart_Invoke(io_lib, ToDart("_setStdioFDs"), 3, stdio_args);
210
211 // Disable some dart:io operations.
212 Dart_Handle embedder_config_type =
213 Dart_GetNonNullableType(io_lib, ToDart("_EmbedderConfig"), 0, nullptr);
214 FML_CHECK(!tonic::CheckAndHandleError(embedder_config_type));
215
216 result =
217 Dart_SetField(embedder_config_type, ToDart("_mayExit"), Dart_False());
219
220 // Set the script location.
221 result = Dart_SetField(builtin_lib, ToDart("_rawScript"), ToDart(script_uri));
223
224 // Setup the uriBase with the base uri of the fidl app.
225 Dart_Handle uri_base =
226 Dart_Invoke(io_lib, ToDart("_getUriBaseClosure"), 0, nullptr);
228
229 result = Dart_SetField(core_lib, ToDart("_uriBaseClosure"), uri_base);
231
232 Dart_Handle setup_hooks = ToDart("_setupHooks");
233 result = Dart_Invoke(builtin_lib, setup_hooks, 0, nullptr);
235 result = Dart_Invoke(io_lib, setup_hooks, 0, nullptr);
237 result = Dart_Invoke(isolate_lib, setup_hooks, 0, nullptr);
239}
void print(void *str)
Definition bridge.cpp:126
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 Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_FinalizeLoading(bool complete_futures)
DART_EXPORT Dart_Handle Dart_False(void)
#define FML_CHECK(condition)
Definition logging.h:85
const uint8_t * IONativeSymbol(Dart_NativeFunction nf)
Dart_NativeFunction IONativeLookup(Dart_Handle name, int argument_count, bool *auto_setup_scope)
void Initialize(zx::channel directory_request, std::optional< zx::eventpair > view_ref)
Initializes Dart bindings for the Fuchsia application model.
Definition fuchsia.cc:103
Dart_Handle ToDart(const T &object)
bool CheckAndHandleError(Dart_Handle handle)
Definition dart_error.cc:33

◆ IsTestProgram()

bool dart_runner::IsTestProgram ( const fuchsia::data::Dictionary &  program_metadata)

Parses the |args| field from the "program" field to determine if a test component is being executed.

Definition at line 167 of file dart_runner.cc.

167 {
168 for (const auto& entry : program_metadata.entries()) {
169 if (entry.key.compare(kArgsKey) != 0 || entry.value == nullptr) {
170 continue;
171 }
172 auto args = entry.value->str_vec();
173
174 // fml::CommandLine expects the first argument to be the name of the
175 // program, so we prepend a dummy argument so we can use fml::CommandLine to
176 // parse the arguments for us.
177 std::vector<std::string> command_line_args = {""};
178 command_line_args.insert(command_line_args.end(), args.begin(), args.end());
180 command_line_args.begin(), command_line_args.end());
181
182 std::string is_test_str;
183 return parsed_args.GetOptionValue("is_test", &is_test_str) &&
184 is_test_str == "true";
185 }
186 return false;
187}
bool GetOptionValue(std::string_view name, std::string *value) const
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static constexpr char kArgsKey[]
CommandLine CommandLineFromIterators(InputIterator first, InputIterator last)

Variable Documentation

◆ isolate_snapshot_buffer

uint8_t const* const dart_runner::isolate_snapshot_buffer
extern

◆ kArgsKey

constexpr char dart_runner::kArgsKey[] = "args"
constexpr

Definition at line 163 of file dart_runner.cc.

◆ vm_isolate_snapshot_buffer

uint8_t const* const dart_runner::vm_isolate_snapshot_buffer
extern