9#if defined(DART_HOST_OS_WINDOWS)
12#include <combaseapi.h>
26#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \
27 defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
33#if defined(USING_SIMULATOR) || (defined(DART_PRECOMPILER) && !defined(TESTING))
35DART_NORETURN
static void SimulatorUnsupported() {
36#if defined(USING_SIMULATOR)
38 "Not supported on simulated architectures.");
45 SimulatorUnsupported();
48 SimulatorUnsupported();
51 SimulatorUnsupported();
54 SimulatorUnsupported();
57 SimulatorUnsupported();
60 SimulatorUnsupported();
63 SimulatorUnsupported();
67 SimulatorUnsupported();
76 char**
error =
nullptr) {
77 char* utils_error =
nullptr;
79 if (utils_error !=
nullptr) {
80 if (
error !=
nullptr) {
82 nullptr,
"Failed to load dynamic library '%s': %s",
83 library_file !=
nullptr ? library_file :
"<process>", utils_error);
90#if defined(DART_HOST_OS_WINDOWS)
92const nullptr_t kWindowsDynamicLibraryProcessPtr =
nullptr;
94void* co_task_mem_allocated =
nullptr;
98void* LookupSymbolInProcess(
const char* symbol,
char**
error) {
100 if (co_task_mem_allocated ==
nullptr) {
101 co_task_mem_allocated = CoTaskMemAlloc(
sizeof(intptr_t));
102 CoTaskMemFree(co_task_mem_allocated);
106 OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
108 if (current_process ==
nullptr) {
117 for (intptr_t
i = 0;
i < (cb_needed /
sizeof(
HMODULE));
i++) {
119 reinterpret_cast<void*
>(GetProcAddress(
modules[
i], symbol))) {
120 CloseHandle(current_process);
125 CloseHandle(current_process);
129 "None of the loaded modules contained the requested symbol '%s'.",
138#if defined(DART_HOST_OS_WINDOWS)
139 if (handle == kWindowsDynamicLibraryProcessPtr) {
140 return LookupSymbolInProcess(symbol,
error);
147 char*
error =
nullptr;
148#if !defined(DART_HOST_OS_WINDOWS)
151 if (handle ==
nullptr) {
152 LookupSymbolInProcess(symbol, &
error);
157 if (
error !=
nullptr) {
167 char*
error =
nullptr;
169 if (
error !=
nullptr) {
178#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \
179 defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
192 if (dlib.IsClosed()) {
194 }
else if (!dlib.CanBeClosed()) {
196 String::New(
"DynamicLibrary.process() and DynamicLibrary.executable() "
197 "can't be closed."));
200 void* handle = dlib.GetHandle();
201 char*
error =
nullptr;
204 if (
error ==
nullptr) {
205 dlib.SetClosed(
true);
219 arguments->NativeArgAt(1));
221 if (dlib.IsClosed()) {
227 void* handle = dlib.GetHandle();
229 char*
error =
nullptr;
230 const uword pointer =
reinterpret_cast<uword>(
232 if (
error !=
nullptr) {
234 "Failed to lookup symbol '%s': %s", argSymbolName.ToCString(),
error));
244 intptr_t handle =
reinterpret_cast<intptr_t
>(dlib.GetHandle());
251 arguments->NativeArgAt(1));
253 void* handle = dlib.GetHandle();
259 const String& lib_url_str) {
279 "Couldn't resolve function: '%s'", symbol.
ToCString());
284#if defined(DART_TARGET_OS_WINDOWS)
286static void ReplaceBackSlashes(
char* cstr) {
287 const intptr_t
length = strlen(cstr);
289 cstr[
i] = cstr[
i] ==
'\\' ?
'/' : cstr[
i];
301#if defined(DART_TARGET_OS_WINDOWS)
304 const char* file_schema_slash =
"file:///";
305 const int file_schema_slash_length = 8;
307 if (strlen(
source->script_uri) > file_schema_slash_length &&
308 strncmp(
source->script_uri, file_schema_slash,
309 file_schema_slash_length) == 0) {
310 path = (
source->script_uri + file_schema_slash_length);
314 const intptr_t
len = strlen(
path);
337 const auto& native_assets_map =
339 if (!native_assets_map.IsNull()) {
342 if (!lookup.IsNull()) {
343 result = Array::Cast(lookup).ptr();
354 const auto& native_assets_map =
358 if (native_assets_map.IsNull()) {
359 buffer.Printf(
"No available native assets.");
362 buffer.Printf(
"Available native assets: ");
364 NativeAssetsMap::Iterator it(&
map);
366 while (it.MoveNext()) {
370 auto entry = it.Current();
371 asset_id ^=
map.GetKey(entry);
372 buffer.Printf(
"%s", asset_id.ToCString());
389 void* handle =
nullptr;
390 if (asset_type.
Equals(Symbols::absolute())) {
392 }
else if (asset_type.
Equals(Symbols::relative())) {
398 char* path_cstr =
path.ToMallocCString();
399#if defined(DART_TARGET_OS_WINDOWS)
400 ReplaceBackSlashes(path_cstr);
403 ResolveUri(path_cstr, platform_script_uri.ToCString());
408 "Failed to resolve '%s' relative to "
410 path.ToCString(), platform_script_uri.ToCString());
415 }
else if (asset_type.
Equals(Symbols::system())) {
418#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \
419 defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
420 handle = RTLD_DEFAULT;
422 handle = kWindowsDynamicLibraryProcessPtr;
424 }
else if (asset_type.
Equals(Symbols::executable())) {
429 if (*
error !=
nullptr) {
430 char* inner_error = *
error;
432 "Failed to load dynamic library '%s': %s",
433 path.ToCString(), inner_error);
437 if (*
error !=
nullptr) {
438 char* inner_error = *
error;
440 "Failed to lookup symbol '%s': %s",
458 const Array& asset_location,
463 const auto& asset_type =
466 const char* path_cstr =
nullptr;
467 if (asset_type.Equals(Symbols::absolute()) ||
468 asset_type.Equals(Symbols::relative()) ||
469 asset_type.Equals(Symbols::system())) {
471 path_cstr =
path.ToCString();
477 if (asset_type.Equals(Symbols::absolute())) {
483 }
else if (asset_type.Equals(Symbols::relative())) {
489 }
else if (asset_type.Equals(Symbols::system())) {
495 }
else if (asset_type.Equals(Symbols::executable())) {
510 if (*
error !=
nullptr) {
513 if (native_assets_api->
dlsym ==
nullptr) {
526 "Couldn't resolve native function '%s' in '%s' : %s.\n",
541 if (resolver !=
nullptr) {
543 thread, resolver, symbol, args_n,
error);
544 return reinterpret_cast<intptr_t
>(ffi_native_result);
548 const auto& asset_location =
550 if (!asset_location.IsNull()) {
552 return reinterpret_cast<intptr_t
>(asset_result);
556#if !defined(DART_HOST_OS_WINDOWS)
563 if (*
error !=
nullptr) {
566 char* process_lookup_error = *
error;
568 "No asset with id '%s' found. %s "
569 "Attempted to fallback to process lookup. %s",
571 process_lookup_error);
572 free(process_lookup_error);
575 return reinterpret_cast<intptr_t
>(
result);
584 auto*
const zone = thread->zone();
587 char*
error =
nullptr;
590 if (
error !=
nullptr) {
#define RELEASE_ASSERT(cond)
static const String & UnwrapStringHandle(const ReusableObjectHandleScope &reused, Dart_Handle object)
ObjectPtr At(intptr_t index) const
static const Bool & Get(bool value)
static DynamicLibraryPtr New(void *handle, bool canBeClosed, Heap::Space space=Heap::kNew)
static DART_NORETURN void ThrowStateError(const Instance &arg)
static DART_NORETURN void ThrowUnsupportedError(const char *msg)
static DART_NORETURN void ThrowArgumentError(const Instance &arg)
static IntegerPtr NewFromUint64(uint64_t value, Heap::Space space=Heap::kNew)
IsolateGroupSource * source() const
NativeAssetsApi * native_assets_api()
static LibraryPtr LookupLibrary(Thread *thread, const String &url)
Dart_FfiNativeResolver ffi_native_resolver() const
static char * SCreate(Zone *zone, const char *format,...) PRINTF_ATTRIBUTE(2
static ObjectPtr RawCast(ObjectPtr obj)
static PointerPtr New(uword native_address, Heap::Space space=Heap::kNew)
static StringPtr NewFormatted(const char *format,...) PRINTF_ATTRIBUTE(1
bool Equals(const String &str) const
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
static const char * ToCString(Thread *thread, StringPtr ptr)
static Thread * Current()
IsolateGroup * isolate_group() const
static void * LoadDynamicLibrary(const char *library_path, char **error=nullptr)
static void UnloadDynamicLibrary(void *library_handle, char **error=nullptr)
static void * ResolveSymbolInDynamicLibrary(void *library_handle, const char *symbol, char **error=nullptr)
struct _Dart_Handle * Dart_Handle
void *(* Dart_FfiNativeResolver)(const char *name, uintptr_t args_n)
#define DARTSCOPE(thread)
const uint8_t uint32_t uint32_t GError ** error
static ArrayPtr GetAssetLocation(Thread *const thread, const String &asset)
static Dart_FfiNativeResolver GetFfiNativeResolver(Thread *const thread, const String &lib_url_str)
static void * FfiResolveAsset(Thread *const thread, const Array &asset_location, const String &symbol, char **error)
void * malloc(size_t size)
static void * FfiResolveWithFfiNativeResolver(Thread *const thread, Dart_FfiNativeResolver resolver, const String &symbol, intptr_t args_n, char **error)
static char * AvailableAssetsToCString(Thread *const thread)
static void * FfiResolveAssetFallback(Thread *const thread, const String &asset_type, const String &path, const String &symbol, char **error)
static void ThrowFfiResolveError(const String &symbol, const String &asset, char *error)
static intptr_t FfiResolve(Dart_Handle asset_handle, Dart_Handle symbol_handle, uintptr_t args_n)
CStringUniquePtr ResolveUri(const char *ref_uri, const char *base_uri)
ArrayPtr GetNativeAssetsMap(Thread *thread)
static void * LoadDynamicLibrary(const char *library_file, char **error=nullptr)
const int file_schema_length
intptr_t FfiResolveInternal(const String &asset, const String &symbol, uintptr_t args_n, char **error)
DEFINE_NATIVE_ENTRY(List_allocate, 0, 2)
static StringPtr GetPlatformScriptPath(Thread *thread)
static bool SymbolExists(void *handle, const char *symbol)
static void * ResolveSymbol(void *handle, const char *symbol, char **error)
static zx_koid_t GetCurrentProcessId()
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
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
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
#define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value)
SKWASM_EXPORT SkPath * path_copy(SkPath *path)
static void process(const char *inPath, const char *lexer, const char *token, const char *hPath, const char *cppPath)
Dart_NativeAssetsDlopenCallback dlopen_system
Dart_NativeAssetsDlopenCallback dlopen_absolute
Dart_NativeAssetsDlopenCallbackNoPath dlopen_process
Dart_NativeAssetsDlopenCallback dlopen_relative
Dart_NativeAssetsDlsymCallback dlsym
Dart_NativeAssetsDlopenCallbackNoPath dlopen_executable