Flutter Engine
The Flutter Engine
bootstrap_natives.cc
Go to the documentation of this file.
1// Copyright (c) 2012, 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
5#include "vm/bootstrap.h"
6
7#include "include/dart_api.h"
8
10#include "vm/dart_api_impl.h"
11#include "vm/object.h"
12#include "vm/object_store.h"
13#include "vm/service_isolate.h"
14
15namespace dart {
16
17// Helper macros for declaring and defining native entries.
18#define REGISTER_NATIVE_ENTRY(name, count) \
19 {"" #name, reinterpret_cast<void*>(BootstrapNatives::DN_##name), count},
20
21// List all native functions implemented in the vm or core bootstrap dart
22// libraries so that we can resolve the native function to it's entry
23// point.
24static const struct NativeEntries {
25 const char* const name_;
26 void* const function_;
27 const int argument_count_;
29#if !defined(DART_PRECOMPILED_RUNTIME)
31#endif // !DART_PRECOMPILED_RUNTIME
32};
33
34#define REGISTER_FFI_NATIVE_ENTRY(name, return_type, argument_types) \
35 {"" #name, reinterpret_cast<void*>(BootstrapNatives::FN_##name)},
36
37static const struct FfiNativeEntries {
38 const char* const name_;
39 void* const function_;
42
45 bool* auto_setup_scope) {
46 Thread* thread = Thread::Current();
47 TransitionNativeToVM transition(thread);
48 const Object& obj = Object::Handle(thread->zone(), Api::UnwrapHandle(name));
49 if (!obj.IsString()) {
50 return nullptr;
51 }
52 ASSERT(auto_setup_scope);
53 *auto_setup_scope = false;
54 const char* function_name = obj.ToCString();
55 ASSERT(function_name != nullptr);
56 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries);
57 for (int i = 0; i < num_entries; i++) {
58 const struct NativeEntries* entry = &(BootStrapEntries[i]);
59 if ((strcmp(function_name, entry->name_) == 0) &&
60 (entry->argument_count_ == argument_count)) {
61 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
62 }
63 }
64 return nullptr;
65}
66
68 uintptr_t argument_count) {
69 int num_entries =
70 sizeof(BootStrapFfiEntries) / sizeof(struct FfiNativeEntries);
71 for (int i = 0; i < num_entries; i++) {
72 const struct FfiNativeEntries* entry = &(BootStrapFfiEntries[i]);
73 if (strcmp(name, entry->name_) == 0) {
74 return entry->function_;
75 }
76 }
77 return nullptr;
78}
79
81 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries);
82 for (int i = 0; i < num_entries; i++) {
83 const struct NativeEntries* entry = &(BootStrapEntries[i]);
84 if (reinterpret_cast<Dart_NativeFunction>(entry->function_) == nf) {
85 return reinterpret_cast<const uint8_t*>(entry->name_);
86 }
87 }
88 return nullptr;
89}
90
92 Library& library = Library::Handle();
93
95
96 Dart_FfiNativeResolver ffi_native_resolver =
98
100
101 library = Library::AsyncLibrary();
102 ASSERT(!library.IsNull());
103 library.set_native_entry_resolver(resolver);
104 library.set_native_entry_symbol_resolver(symbol_resolver);
105
106 library = Library::CollectionLibrary();
107 ASSERT(!library.IsNull());
108 library.set_native_entry_resolver(resolver);
109 library.set_native_entry_symbol_resolver(symbol_resolver);
110
111 library = Library::ConvertLibrary();
112 ASSERT(!library.IsNull());
113 library.set_native_entry_resolver(resolver);
114 library.set_native_entry_symbol_resolver(symbol_resolver);
115
116 library = Library::CoreLibrary();
117 ASSERT(!library.IsNull());
118 library.set_native_entry_resolver(resolver);
119 library.set_native_entry_symbol_resolver(symbol_resolver);
120
121 library = Library::DeveloperLibrary();
122 ASSERT(!library.IsNull());
123 library.set_native_entry_resolver(resolver);
124 library.set_native_entry_symbol_resolver(symbol_resolver);
125
126 library = Library::FfiLibrary();
127 ASSERT(!library.IsNull());
128 library.set_native_entry_resolver(resolver);
129 library.set_native_entry_symbol_resolver(symbol_resolver);
130 library.set_ffi_native_resolver(ffi_native_resolver);
131
132 library = Library::InternalLibrary();
133 ASSERT(!library.IsNull());
134 library.set_native_entry_resolver(resolver);
135 library.set_native_entry_symbol_resolver(symbol_resolver);
136 library.set_ffi_native_resolver(ffi_native_resolver);
137
138 library = Library::IsolateLibrary();
139 ASSERT(!library.IsNull());
140 library.set_native_entry_resolver(resolver);
141 library.set_native_entry_symbol_resolver(symbol_resolver);
142
143 library = Library::MathLibrary();
144 ASSERT(!library.IsNull());
145 library.set_native_entry_resolver(resolver);
146 library.set_native_entry_symbol_resolver(symbol_resolver);
147
148#if !defined(DART_PRECOMPILED_RUNTIME)
149 library = Library::MirrorsLibrary();
150 ASSERT(!library.IsNull());
151 library.set_native_entry_resolver(resolver);
152 library.set_native_entry_symbol_resolver(symbol_resolver);
153#endif
154
155 library = Library::TypedDataLibrary();
156 ASSERT(!library.IsNull());
157 library.set_native_entry_resolver(resolver);
158 library.set_native_entry_symbol_resolver(symbol_resolver);
159
160 library = Library::VMServiceLibrary();
161 ASSERT(!library.IsNull());
162 library.set_native_entry_resolver(resolver);
163 library.set_native_entry_symbol_resolver(symbol_resolver);
164}
165
167 return resolver == BootstrapNatives::Lookup;
168}
169
170} // namespace dart
#define REGISTER_FFI_NATIVE_ENTRY(name, return_type, argument_types)
#define REGISTER_NATIVE_ENTRY(name, count)
#define BOOTSTRAP_FFI_NATIVE_LIST(V)
#define MIRRORS_BOOTSTRAP_NATIVE_LIST(V)
#define BOOTSTRAP_NATIVE_LIST(V)
static ObjectPtr UnwrapHandle(Dart_Handle object)
static Dart_NativeFunction Lookup(Dart_Handle name, int argument_count, bool *auto_setup_scope)
static void * LookupFfiNative(const char *name, uintptr_t argument_count)
static const uint8_t * Symbol(Dart_NativeFunction nf)
static void SetupNativeResolver()
static bool IsBootstrapResolver(Dart_NativeEntryResolver resolver)
static LibraryPtr CoreLibrary()
Definition: object.cc:14787
static LibraryPtr VMServiceLibrary()
Definition: object.cc:14829
void set_native_entry_symbol_resolver(Dart_NativeEntrySymbol native_symbol_resolver) const
Definition: object.h:5242
static LibraryPtr MirrorsLibrary()
Definition: object.cc:14816
static LibraryPtr IsolateLibrary()
Definition: object.cc:14807
void set_native_entry_resolver(Dart_NativeEntryResolver value) const
Definition: object.h:5233
void set_ffi_native_resolver(Dart_FfiNativeResolver value) const
Definition: object.h:5254
static LibraryPtr ConvertLibrary()
Definition: object.cc:14783
static LibraryPtr CollectionLibrary()
Definition: object.cc:14791
static LibraryPtr AsyncLibrary()
Definition: object.cc:14779
static LibraryPtr InternalLibrary()
Definition: object.cc:14803
static LibraryPtr FfiLibrary()
Definition: object.cc:14799
static LibraryPtr MathLibrary()
Definition: object.cc:14811
static LibraryPtr DeveloperLibrary()
Definition: object.cc:14795
static LibraryPtr TypedDataLibrary()
Definition: object.cc:14825
virtual const char * ToCString() const
Definition: object.h:366
bool IsNull() const
Definition: object.h:363
static Object & Handle()
Definition: object.h:407
Zone * zone() const
Definition: thread_state.h:37
static Thread * Current()
Definition: thread.h:362
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
Dart_NativeFunction(* Dart_NativeEntryResolver)(Dart_Handle name, int num_of_arguments, bool *auto_setup_scope)
Definition: dart_api.h:3234
const uint8_t *(* Dart_NativeEntrySymbol)(Dart_NativeFunction nf)
Definition: dart_api.h:3255
void *(* Dart_FfiNativeResolver)(const char *name, uintptr_t args_n)
Definition: dart_api.h:3262
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition: dart_api.h:3207
#define ASSERT(E)
int argument_count
Definition: fuchsia.cc:52
Definition: dart_vm.cc:33
const char *const name
static const struct dart::FfiNativeEntries BootStrapFfiEntries[]
static const struct dart::NativeEntries BootStrapEntries[]
const char *const function_name
const char *const name_
const char *const name_