mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:17:55 +00:00
Wire up the stub native resolver for all libraries in gen_snapshot
Fixes https://github.com/flutter/flutter/issues/6952 BUG= R=rmacnak@google.com Review URL: https://codereview.chromium.org/2518233003 .
This commit is contained in:
parent
f98363b118
commit
2510646aaf
|
@ -22,6 +22,7 @@
|
|||
#include "bin/vmservice_impl.h"
|
||||
|
||||
#include "include/dart_api.h"
|
||||
#include "include/dart_tools_api.h"
|
||||
|
||||
#include "platform/hashmap.h"
|
||||
#include "platform/globals.h"
|
||||
|
@ -684,7 +685,8 @@ static const char StubNativeFunctionName[] = "StubNativeFunction";
|
|||
|
||||
void StubNativeFunction(Dart_NativeArguments arguments) {
|
||||
// This is a stub function for the resolver
|
||||
UNREACHABLE();
|
||||
Dart_SetReturnValue(
|
||||
arguments, Dart_NewApiError("<EMBEDDER DID NOT SETUP NATIVE RESOLVER>"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -735,6 +737,31 @@ static void SetupStubNativeResolver(size_t lib_index,
|
|||
}
|
||||
|
||||
|
||||
// Iterate over all libraries and setup the stub native lookup. This must be
|
||||
// run after |SetupStubNativeResolversForPrecompilation| because the former
|
||||
// loads some libraries.
|
||||
static void SetupStubNativeResolvers() {
|
||||
Dart_Handle library_ids = Dart_GetLibraryIds();
|
||||
intptr_t library_ids_length;
|
||||
Dart_ListLength(library_ids, &library_ids_length);
|
||||
for (intptr_t i = 0; i < library_ids_length; i++) {
|
||||
Dart_Handle library_id_handle = Dart_ListGetAt(library_ids, i);
|
||||
DART_CHECK_VALID(library_id_handle);
|
||||
int64_t library_id;
|
||||
Dart_IntegerToInt64(library_id_handle, &library_id);
|
||||
Dart_Handle library = Dart_GetLibraryFromId(library_id);
|
||||
DART_CHECK_VALID(library);
|
||||
Dart_NativeEntryResolver old_resolver = NULL;
|
||||
Dart_GetNativeResolver(library, &old_resolver);
|
||||
if (old_resolver == NULL) {
|
||||
Dart_Handle result =
|
||||
Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol);
|
||||
DART_CHECK_VALID(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void ImportNativeEntryPointLibrariesIntoRoot(
|
||||
const Dart_QualifiedFunctionName* entries) {
|
||||
if (entries == NULL) {
|
||||
|
@ -1306,6 +1333,8 @@ int main(int argc, char** argv) {
|
|||
|
||||
SetupStubNativeResolversForPrecompilation(entry_points);
|
||||
|
||||
SetupStubNativeResolvers();
|
||||
|
||||
if (!is_kernel_file) {
|
||||
// Load the specified script.
|
||||
library = LoadSnapshotCreationScript(app_script_name);
|
||||
|
|
|
@ -2703,6 +2703,30 @@ Dart_SetNativeResolver(Dart_Handle library,
|
|||
/* TODO(turnidge): Rename to Dart_LibrarySetNativeResolver? */
|
||||
|
||||
|
||||
/**
|
||||
* Returns the callback used to resolve native functions for a library.
|
||||
*
|
||||
* \param library A library.
|
||||
* \param resolver a pointer to a Dart_NativeEntryResolver
|
||||
*
|
||||
* \return A valid handle if the library was found.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_GetNativeResolver(Dart_Handle library, Dart_NativeEntryResolver* resolver);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the callback used to resolve native function symbols for a library.
|
||||
*
|
||||
* \param library A library.
|
||||
* \param resolver a pointer to a Dart_NativeEntrySymbol.
|
||||
*
|
||||
* \return A valid handle if the library was found.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_GetNativeSymbol(Dart_Handle library,
|
||||
Dart_NativeEntrySymbol* resolver);
|
||||
|
||||
|
||||
/*
|
||||
* =====================
|
||||
* Scripts and Libraries
|
||||
|
|
|
@ -5865,6 +5865,32 @@ Dart_SetNativeResolver(Dart_Handle library,
|
|||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle
|
||||
Dart_GetNativeResolver(Dart_Handle library,
|
||||
Dart_NativeEntryResolver* resolver) {
|
||||
*resolver = NULL;
|
||||
DARTSCOPE(Thread::Current());
|
||||
const Library& lib = Api::UnwrapLibraryHandle(Z, library);
|
||||
if (lib.IsNull()) {
|
||||
RETURN_TYPE_ERROR(Z, library, Library);
|
||||
}
|
||||
*resolver = lib.native_entry_resolver();
|
||||
return Api::Success();
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_GetNativeSymbol(Dart_Handle library,
|
||||
Dart_NativeEntrySymbol* resolver) {
|
||||
*resolver = NULL;
|
||||
DARTSCOPE(Thread::Current());
|
||||
const Library& lib = Api::UnwrapLibraryHandle(Z, library);
|
||||
if (lib.IsNull()) {
|
||||
RETURN_TYPE_ERROR(Z, library, Library);
|
||||
}
|
||||
*resolver = lib.native_entry_symbol_resolver();
|
||||
return Api::Success();
|
||||
}
|
||||
|
||||
// --- Peer support ---
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) {
|
||||
|
|
Loading…
Reference in a new issue