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

#include <native_entry.h>

Inheritance diagram for dart::NativeEntry:
dart::AllStatic

Static Public Member Functions

static NativeFunction ResolveNative (const Library &library, const String &function_name, int number_of_arguments, bool *auto_setup_scope)
 
static const uint8_t * ResolveSymbolInLibrary (const Library &library, uword pc)
 
static const uint8_t * ResolveSymbol (uword pc)
 
static uword BootstrapNativeCallWrapperEntry ()
 
static void BootstrapNativeCallWrapper (Dart_NativeArguments args, Dart_NativeFunction func)
 
static uword NoScopeNativeCallWrapperEntry ()
 
static void NoScopeNativeCallWrapper (Dart_NativeArguments args, Dart_NativeFunction func)
 
static uword AutoScopeNativeCallWrapperEntry ()
 
static void AutoScopeNativeCallWrapper (Dart_NativeArguments args, Dart_NativeFunction func)
 
static uword LinkNativeCallEntry ()
 
static void LinkNativeCall (Dart_NativeArguments args)
 

Static Public Attributes

static constexpr intptr_t kNumArguments = 1
 
static constexpr intptr_t kNumCallWrapperArguments = 2
 

Detailed Description

Definition at line 96 of file native_entry.h.

Member Function Documentation

◆ AutoScopeNativeCallWrapper()

void dart::NativeEntry::AutoScopeNativeCallWrapper ( Dart_NativeArguments  args,
Dart_NativeFunction  func 
)
static

Definition at line 197 of file native_entry.cc.

198 {
200 AutoScopeNativeCallWrapperNoStackCheck(args, func);
201}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define CHECK_STACK_ALIGNMENT

◆ AutoScopeNativeCallWrapperEntry()

uword dart::NativeEntry::AutoScopeNativeCallWrapperEntry ( )
static

Definition at line 186 of file native_entry.cc.

186 {
187 uword entry =
189#if defined(USING_SIMULATOR)
193#endif
194 return entry;
195}
static void AutoScopeNativeCallWrapper(Dart_NativeArguments args, Dart_NativeFunction func)
static constexpr intptr_t kNumCallWrapperArguments
Definition: native_entry.h:99
static uword RedirectExternalReference(uword function, CallKind call_kind, int argument_count)
uintptr_t uword
Definition: globals.h:501

◆ BootstrapNativeCallWrapper()

void dart::NativeEntry::BootstrapNativeCallWrapper ( Dart_NativeArguments  args,
Dart_NativeFunction  func 
)
static

Definition at line 125 of file native_entry.cc.

126 {
128 if (func == LinkNativeCall) {
129 func(args);
130 return;
131 }
132
133 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
134 // Tell MemorySanitizer 'arguments' is initialized by generated code.
135 MSAN_UNPOISON(arguments, sizeof(*arguments));
136 {
137 Thread* thread = arguments->thread();
138 ASSERT(thread == Thread::Current());
139 TransitionGeneratedToVM transition(thread);
140 StackZone zone(thread);
141 // Be careful holding return_value_unsafe without a handle here.
142 // A return of Object::sentinel means the return value has already
143 // been set.
144 ObjectPtr return_value_unsafe = reinterpret_cast<BootstrapNativeFunction>(
145 reinterpret_cast<void*>(func))(thread, zone.GetZone(), arguments);
146 if (return_value_unsafe != Object::sentinel().ptr()) {
147 ASSERT(return_value_unsafe->IsDartInstance());
148 arguments->SetReturnUnsafe(return_value_unsafe);
149 }
151 }
152}
static void LinkNativeCall(Dart_NativeArguments args)
static Thread * Current()
Definition: thread.h:362
#define ASSERT(E)
#define MSAN_UNPOISON(ptr, len)
ObjectPtr(* BootstrapNativeFunction)(Thread *thread, Zone *zone, NativeArguments *arguments)
Definition: native_entry.h:35
#define DEOPTIMIZE_ALOT

◆ BootstrapNativeCallWrapperEntry()

uword dart::NativeEntry::BootstrapNativeCallWrapperEntry ( )
static

Definition at line 114 of file native_entry.cc.

114 {
115 uword entry =
117#if defined(USING_SIMULATOR)
121#endif
122 return entry;
123}
static void BootstrapNativeCallWrapper(Dart_NativeArguments args, Dart_NativeFunction func)

◆ LinkNativeCall()

void dart::NativeEntry::LinkNativeCall ( Dart_NativeArguments  args)
static

Definition at line 256 of file native_entry.cc.

256 {
258 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
259 // Tell MemorySanitizer 'arguments' is initialized by generated code.
260 MSAN_UNPOISON(arguments, sizeof(*arguments));
261 TRACE_NATIVE_CALL("%s", "LinkNative");
262
263 NativeFunction target_function = nullptr;
264 bool is_bootstrap_native = false;
265 bool is_auto_scope = true;
266
267 {
268 TransitionGeneratedToVM transition(arguments->thread());
269 StackZone stack_zone(arguments->thread());
270 Zone* zone = stack_zone.GetZone();
271
272 DartFrameIterator iterator(arguments->thread(),
274 StackFrame* caller_frame = iterator.NextFrame();
275
276 Code& code = Code::Handle(zone, caller_frame->LookupDartCode());
277 Function& func = Function::Handle(zone, code.function());
278
279 if (FLAG_trace_natives) {
280 THR_Print("Resolving native target for %s\n", func.ToCString());
281 }
282
283 target_function =
284 ResolveNativeFunction(arguments->thread()->zone(), func,
285 &is_bootstrap_native, &is_auto_scope);
286 ASSERT(target_function != nullptr);
287
288#if defined(DEBUG)
289 NativeFunction current_function = nullptr;
290 const Code& current_trampoline =
292 caller_frame->pc(), code, &current_function));
293 // Some other isolate(with code being shared in AOT) might have updated
294 // target function/trampoline already.
295 ASSERT(current_function ==
296 reinterpret_cast<NativeFunction>(LinkNativeCall) ||
297 current_function == target_function);
298 ASSERT(current_trampoline.ptr() == StubCode::CallBootstrapNative().ptr() ||
299 current_function == target_function);
300#endif
301
302 NativeFunction patch_target_function = target_function;
303 Code& trampoline = Code::Handle(zone);
304 if (is_bootstrap_native) {
305 trampoline = StubCode::CallBootstrapNative().ptr();
306 } else if (is_auto_scope) {
307 trampoline = StubCode::CallAutoScopeNative().ptr();
308 } else {
309 trampoline = StubCode::CallNoScopeNative().ptr();
310 }
311 CodePatcher::PatchNativeCallAt(caller_frame->pc(), code,
312 patch_target_function, trampoline);
313
314 if (FLAG_trace_natives) {
315 THR_Print(" -> %p (%s)\n", target_function,
316 is_bootstrap_native ? "bootstrap" : "non-bootstrap");
317 }
318 }
319
320 // Tail-call resolved target.
321 if (is_bootstrap_native) {
323 args, reinterpret_cast<Dart_NativeFunction>(target_function));
324 } else if (is_auto_scope) {
325 // Because this call is within a compilation unit, Clang doesn't respect
326 // the ABI alignment here.
327 NativeEntry::AutoScopeNativeCallWrapperNoStackCheck(
328 args, reinterpret_cast<Dart_NativeFunction>(target_function));
329 } else {
330 // Because this call is within a compilation unit, Clang doesn't respect
331 // the ABI alignment here.
332 NativeEntry::NoScopeNativeCallWrapperNoStackCheck(
333 args, reinterpret_cast<Dart_NativeFunction>(target_function));
334 }
335}
static CodePtr GetNativeCallAt(uword return_address, const Code &caller_code, NativeFunction *target)
static void PatchNativeCallAt(uword return_address, const Code &caller_code, NativeFunction target, const Code &trampoline)
static Object & Handle()
Definition: object.h:407
#define THR_Print(format,...)
Definition: log.h:20
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition: dart_api.h:3207
static NativeFunction ResolveNativeFunction(Zone *zone, const Function &func, bool *is_bootstrap_native, bool *is_auto_scope)
void(* NativeFunction)(NativeArguments *arguments)
#define TRACE_NATIVE_CALL(format, name)
Definition: native_entry.h:30

◆ LinkNativeCallEntry()

uword dart::NativeEntry::LinkNativeCallEntry ( )
static

Definition at line 251 of file native_entry.cc.

251 {
252 uword entry = reinterpret_cast<uword>(NativeEntry::LinkNativeCall);
253 return entry;
254}

◆ NoScopeNativeCallWrapper()

void dart::NativeEntry::NoScopeNativeCallWrapper ( Dart_NativeArguments  args,
Dart_NativeFunction  func 
)
static

Definition at line 164 of file native_entry.cc.

165 {
167 NoScopeNativeCallWrapperNoStackCheck(args, func);
168}

◆ NoScopeNativeCallWrapperEntry()

uword dart::NativeEntry::NoScopeNativeCallWrapperEntry ( )
static

Definition at line 154 of file native_entry.cc.

154 {
155 uword entry = reinterpret_cast<uword>(NativeEntry::NoScopeNativeCallWrapper);
156#if defined(USING_SIMULATOR)
160#endif
161 return entry;
162}
static void NoScopeNativeCallWrapper(Dart_NativeArguments args, Dart_NativeFunction func)

◆ ResolveNative()

NativeFunction dart::NativeEntry::ResolveNative ( const Library library,
const String function_name,
int  number_of_arguments,
bool *  auto_setup_scope 
)
static

Definition at line 37 of file native_entry.cc.

40 {
41 // Now resolve the native function to the corresponding native entrypoint.
42 if (library.native_entry_resolver() == nullptr) {
43 // Native methods are not allowed in the library to which this
44 // class belongs in.
45 return nullptr;
46 }
47 Dart_NativeFunction native_function = nullptr;
48 {
49 Thread* T = Thread::Current();
50 Api::Scope api_scope(T);
51 Dart_Handle api_function_name = Api::NewHandle(T, function_name.ptr());
52 {
53 Dart_NativeEntryResolver resolver = library.native_entry_resolver();
54 TransitionVMToNative transition(T);
55 native_function =
56 resolver(api_function_name, number_of_arguments, auto_setup_scope);
57 }
58 }
59 return reinterpret_cast<NativeFunction>(native_function);
60}
static Dart_Handle NewHandle(Thread *thread, ObjectPtr raw)
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 char *const function_name
#define T
Definition: precompiler.cc:65

◆ ResolveSymbol()

const uint8_t * dart::NativeEntry::ResolveSymbol ( uword  pc)
static

Definition at line 73 of file native_entry.cc.

73 {
74 Thread* thread = Thread::Current();
76 GrowableObjectArray& libs = reused_growable_object_array_handle.Handle();
77 libs = thread->isolate_group()->object_store()->libraries();
78 ASSERT(!libs.IsNull());
79 intptr_t num_libs = libs.Length();
80 for (intptr_t i = 0; i < num_libs; i++) {
82 Library& lib = reused_library_handle.Handle();
83 lib ^= libs.At(i);
84 ASSERT(!lib.IsNull());
85 const uint8_t* r = ResolveSymbolInLibrary(lib, pc);
86 if (r != nullptr) {
87 return r;
88 }
89 }
90 return nullptr;
91}
static const uint8_t * ResolveSymbolInLibrary(const Library &library, uword pc)
Definition: native_entry.cc:62
#define REUSABLE_GROWABLE_OBJECT_ARRAY_HANDLESCOPE(thread)
#define REUSABLE_LIBRARY_HANDLESCOPE(thread)

◆ ResolveSymbolInLibrary()

const uint8_t * dart::NativeEntry::ResolveSymbolInLibrary ( const Library library,
uword  pc 
)
static

Definition at line 62 of file native_entry.cc.

63 {
64 Dart_NativeEntrySymbol symbol_resolver =
65 library.native_entry_symbol_resolver();
66 if (symbol_resolver == nullptr) {
67 // Cannot reverse lookup native entries.
68 return nullptr;
69 }
70 return symbol_resolver(reinterpret_cast<Dart_NativeFunction>(pc));
71}
const uint8_t *(* Dart_NativeEntrySymbol)(Dart_NativeFunction nf)
Definition: dart_api.h:3255

Member Data Documentation

◆ kNumArguments

constexpr intptr_t dart::NativeEntry::kNumArguments = 1
staticconstexpr

Definition at line 98 of file native_entry.h.

◆ kNumCallWrapperArguments

constexpr intptr_t dart::NativeEntry::kNumCallWrapperArguments = 2
staticconstexpr

Definition at line 99 of file native_entry.h.


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