Flutter Engine
The Flutter Engine
Static Public Member Functions | List of all members
dart::bin::Loader Class Reference

#include <loader.h>

Static Public Member Functions

static Dart_Handle InitForSnapshot (const char *snapshot_uri, IsolateData *isolate_data)
 
static Dart_Handle LibraryTagHandler (Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
 
static Dart_Handle DeferredLoadHandler (intptr_t loading_unit_id)
 
static void InitOnce ()
 

Detailed Description

Definition at line 18 of file loader.h.

Member Function Documentation

◆ DeferredLoadHandler()

Dart_Handle dart::bin::Loader::DeferredLoadHandler ( intptr_t  loading_unit_id)
static

Definition at line 144 of file loader.cc.

144 {
145 // A synchronous implementation. An asynchronous implementation would be
146 // better, but the standalone embedder only implements AOT for testing.
147
148 auto isolate_group_data =
149 reinterpret_cast<IsolateGroupData*>(Dart_CurrentIsolateGroupData());
150 char* unit_url = Utils::SCreate(
151 "%s-%" Pd ".part.so", isolate_group_data->script_url, loading_unit_id);
152
153 AppSnapshot* loading_unit_snapshot = Snapshot::TryReadAppSnapshot(unit_url);
155 if (loading_unit_snapshot != nullptr) {
156 isolate_group_data->AddLoadingUnit(loading_unit_snapshot);
157 const uint8_t* isolate_snapshot_data = nullptr;
158 const uint8_t* isolate_snapshot_instructions = nullptr;
159 const uint8_t* ignore_vm_snapshot_data;
160 const uint8_t* ignore_vm_snapshot_instructions;
161 loading_unit_snapshot->SetBuffers(
162 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions,
166 if (Dart_IsApiError(result)) {
167 result =
169 /*transient*/ false);
170 }
171 } else {
172 char* error_message = Utils::SCreate("Failed to load %s", unit_url);
173 result = Dart_DeferredLoadCompleteError(loading_unit_id, error_message,
174 /*transient*/ false);
175 free(error_message);
176 }
177
178 free(unit_url);
179 return result;
180}
static char * SCreate(const char *format,...) PRINTF_ATTRIBUTE(1
Definition: utils.cc:231
static AppSnapshot * TryReadAppSnapshot(const char *script_uri, bool force_load_elf_from_memory=false, bool decode_uri=true)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
GAsyncResult * result
const uint8_t * isolate_snapshot_data
Definition: gen_snapshot.cc:69
const uint8_t * isolate_snapshot_instructions
Definition: gen_snapshot.cc:70
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_DeferredLoadCompleteError(intptr_t loading_unit_id, const char *error_message, bool transient)
DART_EXPORT void * Dart_CurrentIsolateGroupData()
DART_EXPORT Dart_Handle Dart_DeferredLoadComplete(intptr_t loading_unit_id, const uint8_t *snapshot_data, const uint8_t *snapshot_instructions)
DART_EXPORT bool Dart_IsApiError(Dart_Handle object)
#define Pd
Definition: globals.h:408

◆ InitForSnapshot()

Dart_Handle dart::bin::Loader::InitForSnapshot ( const char *  snapshot_uri,
IsolateData isolate_data 
)
static

Definition at line 28 of file loader.cc.

29 {
30 ASSERT(isolate_data != nullptr);
31
32 return Loader::Init(isolate_data->packages_file(),
34}
static const char * original_working_directory
Definition: dartutils.h:288
#define ASSERT(E)

◆ InitOnce()

void dart::bin::Loader::InitOnce ( )
static

Definition at line 182 of file loader.cc.

182{}

◆ LibraryTagHandler()

Dart_Handle dart::bin::Loader::LibraryTagHandler ( Dart_LibraryTag  tag,
Dart_Handle  library,
Dart_Handle  url 
)
static

Definition at line 69 of file loader.cc.

71 {
72 const char* url_string = nullptr;
73 Dart_Handle result = Dart_StringToCString(url, &url_string);
74 if (Dart_IsError(result)) {
75 return result;
76 }
77 if (tag == Dart_kCanonicalizeUrl) {
78 Dart_Handle library_url = Dart_LibraryUrl(library);
79 if (Dart_IsError(library_url)) {
80 return library_url;
81 }
82 const char* library_url_string = nullptr;
83 result = Dart_StringToCString(library_url, &library_url_string);
84 if (Dart_IsError(result)) {
85 return result;
86 }
87 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string);
88 bool is_dart_library = DartUtils::IsDartSchemeURL(library_url_string);
89 if (is_dart_scheme_url || is_dart_library) {
90 return url;
91 }
92 const char* url_cstr;
93 result = Dart_StringToCString(url, &url_cstr);
94 if (Dart_IsError(result)) {
95 return result;
96 }
97 CStringUniquePtr resolved_uri = ResolveUri(url_cstr, library_url_string);
98 if (!resolved_uri) {
99 return DartUtils::NewError("%s: Unable to canonicalize uri '%s'.",
100 __FUNCTION__, url_cstr);
101 }
102 result = Dart_NewStringFromCString(resolved_uri.get());
103 return result;
104 }
105#if !defined(DART_PRECOMPILED_RUNTIME)
106 if (tag == Dart_kKernelTag) {
107 uint8_t* kernel_buffer = nullptr;
108 intptr_t kernel_buffer_size = 0;
109 if (!dfe.TryReadKernelFile(url_string, nullptr, &kernel_buffer,
110 &kernel_buffer_size)) {
111 return DartUtils::NewError("'%s' is not a kernel file", url_string);
112 }
113 return WrapMallocedKernelBuffer(kernel_buffer, kernel_buffer_size);
114 }
116 (tag == Dart_kImportTag)) {
117 // E.g., IsolateMirror.loadUri.
118 char* error = nullptr;
119 int exit_code = 0;
120 uint8_t* kernel_buffer = nullptr;
121 intptr_t kernel_buffer_size = -1;
122 dfe.CompileAndReadScript(url_string, &kernel_buffer, &kernel_buffer_size,
123 &error, &exit_code, nullptr,
124 /*for_snapshot=*/false, /*embed_sources=*/true);
125 if (exit_code == 0) {
126 return Dart_LoadLibrary(
127 WrapMallocedKernelBuffer(kernel_buffer, kernel_buffer_size));
128 } else if (exit_code == kCompilationErrorExitCode) {
130 free(error);
131 return result;
132 } else {
134 free(error);
135 return result;
136 }
137 }
138 return DartUtils::NewError("Invalid tag : %d '%s'", tag, url_string);
139#else // !defined(DART_PRECOMPILED_RUNTIME)
140 return DartUtils::NewError("Unimplemented tag : %d '%s'", tag, url_string);
141#endif // !defined(DART_PRECOMPILED_RUNTIME)
142}
bool TryReadKernelFile(const char *script_uri, const AppSnapshot *app_snapshot, uint8_t **kernel_buffer, intptr_t *kernel_buffer_size, bool decode_uri=true, std::shared_ptr< uint8_t > *kernel_blob_ptr=nullptr)
Definition: dfe.cc:437
void CompileAndReadScript(const char *script_uri, uint8_t **kernel_buffer, intptr_t *kernel_buffer_size, char **error, int *exit_code, const char *package_config, bool for_snapshot, bool embed_sources)
Definition: dfe.cc:204
bool CanUseDartFrontend() const
Definition: dfe.cc:143
bool UseDartFrontend() const
Definition: dfe.h:42
static Dart_Handle NewError(const char *format,...)
Definition: dartutils.cc:766
static bool IsDartSchemeURL(const char *url_name)
Definition: dartutils.cc:215
@ Dart_kImportTag
Definition: dart_api.h:3421
@ Dart_kCanonicalizeUrl
Definition: dart_api.h:3420
@ Dart_kKernelTag
Definition: dart_api.h:3422
const uint8_t uint32_t uint32_t GError ** error
constexpr int kCompilationErrorExitCode
Definition: error_exit.h:16
DFE dfe
Definition: dfe.cc:59
static Dart_Handle WrapMallocedKernelBuffer(uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
Definition: loader.cc:57
CAllocUniquePtr< char > CStringUniquePtr
Definition: utils.h:31
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
CStringUniquePtr ResolveUri(const char *ref_uri, const char *base_uri)
Definition: uri.cc:432
DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle kernel_buffer)
DART_EXPORT Dart_Handle Dart_NewApiError(const char *error)
DART_EXPORT Dart_Handle Dart_NewCompilationError(const char *error)
DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library)
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, const char **cstr)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)

The documentation for this class was generated from the following files: