Flutter Engine
The Flutter Engine
dart_embedder_api_impl.cc
Go to the documentation of this file.
1// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
6
7#include "bin/dartutils.h"
8#include "bin/eventhandler.h"
9#include "bin/isolate_data.h"
10#include "bin/process.h"
12#include "bin/thread.h"
13#include "bin/utils.h"
14#include "bin/vmservice_impl.h"
15
16namespace dart {
17namespace embedder {
18
19static char* MallocFormatedString(const char* format, ...) {
20 va_list measure_args;
21 va_start(measure_args, format);
22 intptr_t len = Utils::VSNPrint(nullptr, 0, format, measure_args);
23 va_end(measure_args);
24
25 char* buffer = reinterpret_cast<char*>(malloc(len + 1));
26 va_list print_args;
27 va_start(print_args, format);
28 Utils::VSNPrint(buffer, (len + 1), format, print_args);
29 va_end(print_args);
30 return buffer;
31}
32
33bool InitOnce(char** error) {
35 bin::OSError err;
36 *error = MallocFormatedString("Error determining current directory: %s\n",
37 err.message());
38 return false;
39 }
42#if !defined(DART_IO_SECURE_SOCKET_DISABLED)
44#endif
46 return true;
47}
48
49void Cleanup() {
51
53#if !defined(DART_IO_SECURE_SOCKET_DISABLED)
55#endif
57}
58
60 const uint8_t* buffer,
61 intptr_t buffer_size,
62 char** error) {
64 data.script_uri, data.main, buffer, buffer_size, data.flags,
65 data.isolate_group_data, data.isolate_data, error);
66 if (kernel_isolate == nullptr) {
67 return nullptr;
68 }
69
72 if (Dart_IsError(result)) {
76 return nullptr;
77 }
78 result = bin::DartUtils::PrepareForScriptLoading(/*is_service_isolate=*/false,
79 /*trace_loading=*/false);
82 return kernel_isolate;
83}
84
86 const VmServiceConfiguration& config,
87 const uint8_t* isolate_data,
88 const uint8_t* isolate_instr,
89 char** error) {
90 if (data.flags == nullptr) {
91 *error = Utils::StrDup("Expected non-null flags");
92 return nullptr;
93 }
94 data.flags->load_vmservice_library = true;
95
96 Dart_Isolate service_isolate = Dart_CreateIsolateGroup(
97 data.script_uri, data.main, isolate_data, isolate_instr, data.flags,
98 data.isolate_group_data, data.isolate_data, error);
99 if (service_isolate == nullptr) {
100 return nullptr;
101 }
102
104 // Load embedder specific bits and return.
105 if (!bin::VmService::Setup(config.ip, config.port, config.dev_mode,
106 config.disable_auth_codes,
108 /*trace_loading=*/false, config.deterministic,
109 /*enable_service_port_fallback=*/false,
110 /*wait_for_dds_to_advertise_service=*/false,
111 /*serve_devtools=*/false,
112 /*serve_observatory=*/true,
113 /*print_dtd=*/false)) {
115 return nullptr;
116 }
117
120 return service_isolate;
121}
122
125 const VmServiceConfiguration& config,
126 const uint8_t* kernel_buffer,
127 intptr_t kernel_buffer_size,
128 char** error) {
129 if (data.flags == nullptr) {
130 *error = Utils::StrDup("Expected non-null flags");
131 return nullptr;
132 }
133 data.flags->load_vmservice_library = true;
134
136 data.script_uri, data.main, kernel_buffer, kernel_buffer_size, data.flags,
137 data.isolate_group_data, data.isolate_data, error);
138 if (service_isolate == nullptr) {
139 return nullptr;
140 }
141
143 // Load embedder specific bits and return.
144 if (!bin::VmService::Setup(config.ip, config.port, config.dev_mode,
145 config.disable_auth_codes,
147 /*trace_loading=*/false, config.deterministic,
148 /*enable_service_port_fallback=*/false,
149 /*wait_for_dds_to_advertise_service=*/false,
150 /*serve_devtools=*/false,
151 /*serve_observatory=*/true,
152 /*print_dtd=*/false)) {
154 return nullptr;
155 }
156
159 return service_isolate;
160}
161
162} // namespace embedder
163} // namespace dart
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
static char * StrDup(const char *s)
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
static bool SetOriginalWorkingDirectory()
Definition: dartutils.cc:821
static Dart_Handle PrepareForScriptLoading(bool is_service_isolate, bool trace_loading)
Definition: dartutils.cc:570
char * message()
Definition: utils.h:36
static void Cleanup()
static void Init()
static void ClearAllSignalHandlers()
Definition: process.cc:70
static void InitOnce()
static const char * GetErrorMessage()
static bool Setup(const char *server_ip, intptr_t server_port, bool dev_mode_server, bool auth_codes_disabled, const char *write_service_info_filename, bool trace_loading, bool deterministic, bool enable_service_port_fallback, bool wait_for_dds_to_advertise_service, bool serve_devtools, bool serve_observatory, bool print_dtd)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
struct _Dart_Isolate * Dart_Isolate
Definition: dart_api.h:88
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
uint32_t uint32_t * format
va_start(args, format)
va_end(args)
static char * MallocFormatedString(const char *format,...)
bool InitOnce(char **error)
Dart_Isolate CreateVmServiceIsolateFromKernel(const IsolateCreationData &data, const VmServiceConfiguration &config, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size, char **error)
Dart_Isolate CreateKernelServiceIsolate(const IsolateCreationData &data, const uint8_t *buffer, intptr_t buffer_size, char **error)
Dart_Isolate CreateVmServiceIsolate(const IsolateCreationData &data, const VmServiceConfiguration &config, const uint8_t *isolate_data, const uint8_t *isolate_instr, char **error)
Definition: dart_vm.cc:33
DART_EXPORT void Dart_EnterScope()
void * malloc(size_t size)
Definition: allocation.cc:19
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT void Dart_ExitIsolate()
DART_EXPORT Dart_Isolate Dart_CreateIsolateGroup(const char *script_uri, const char *name, const uint8_t *snapshot_data, const uint8_t *snapshot_instructions, Dart_IsolateFlags *flags, void *isolate_group_data, void *isolate_data, char **error)
DART_EXPORT Dart_Isolate Dart_CreateIsolateGroupFromKernel(const char *script_uri, const char *name, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size, Dart_IsolateFlags *flags, void *isolate_group_data, void *isolate_data, char **error)
DART_EXPORT void Dart_ExitScope()
DART_EXPORT Dart_Handle Dart_LoadScriptFromKernel(const uint8_t *buffer, intptr_t buffer_size)
static int8_t data[kExtLength]
DART_EXPORT void Dart_ShutdownIsolate()
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
Definition: switches.h:126