OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/native_entry.h" | 5 #include "vm/native_entry.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
12 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
13 #include "vm/object_store.h" | 13 #include "vm/object_store.h" |
14 #include "vm/reusable_handles.h" | 14 #include "vm/reusable_handles.h" |
| 15 #include "vm/safepoint.h" |
15 #include "vm/stack_frame.h" | 16 #include "vm/stack_frame.h" |
16 #include "vm/symbols.h" | 17 #include "vm/symbols.h" |
17 #include "vm/tags.h" | 18 #include "vm/tags.h" |
18 | 19 |
19 | 20 |
20 namespace dart { | 21 namespace dart { |
21 | 22 |
22 DEFINE_FLAG(bool, trace_natives, false, | 23 DEFINE_FLAG(bool, trace_natives, false, |
23 "Trace invocation of natives (debug mode only)"); | 24 "Trace invocation of natives (debug mode only)"); |
24 | 25 |
25 | 26 |
26 NativeFunction NativeEntry::ResolveNative(const Library& library, | 27 NativeFunction NativeEntry::ResolveNative(const Library& library, |
27 const String& function_name, | 28 const String& function_name, |
28 int number_of_arguments, | 29 int number_of_arguments, |
29 bool* auto_setup_scope) { | 30 bool* auto_setup_scope) { |
30 // Now resolve the native function to the corresponding native entrypoint. | 31 // Now resolve the native function to the corresponding native entrypoint. |
31 if (library.native_entry_resolver() == 0) { | 32 if (library.native_entry_resolver() == 0) { |
32 // Native methods are not allowed in the library to which this | 33 // Native methods are not allowed in the library to which this |
33 // class belongs in. | 34 // class belongs in. |
34 return NULL; | 35 return NULL; |
35 } | 36 } |
36 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries. | 37 Dart_NativeFunction native_function = NULL; |
37 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); | 38 { |
38 Dart_NativeFunction native_function = | 39 Thread* T = Thread::Current(); |
39 resolver(Api::NewHandle(Thread::Current(), function_name.raw()), | 40 TransitionVMToNative transition(T); |
40 number_of_arguments, auto_setup_scope); | 41 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries. |
41 Dart_ExitScope(); // Exit the Dart API scope. | 42 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); |
| 43 native_function = resolver(Api::NewHandle(T, function_name.raw()), |
| 44 number_of_arguments, auto_setup_scope); |
| 45 Dart_ExitScope(); // Exit the Dart API scope. |
| 46 } |
42 return reinterpret_cast<NativeFunction>(native_function); | 47 return reinterpret_cast<NativeFunction>(native_function); |
43 } | 48 } |
44 | 49 |
45 | 50 |
46 const uint8_t* NativeEntry::ResolveSymbolInLibrary(const Library& library, | 51 const uint8_t* NativeEntry::ResolveSymbolInLibrary(const Library& library, |
47 uword pc) { | 52 uword pc) { |
48 Dart_NativeEntrySymbol symbol_resolver = | 53 Dart_NativeEntrySymbol symbol_resolver = |
49 library.native_entry_symbol_resolver(); | 54 library.native_entry_symbol_resolver(); |
50 if (symbol_resolver == 0) { | 55 if (symbol_resolver == 0) { |
51 // Cannot reverse lookup native entries. | 56 // Cannot reverse lookup native entries. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 /* Tell MemorySanitizer 'arguments' is initialized by generated code. */ | 99 /* Tell MemorySanitizer 'arguments' is initialized by generated code. */ |
95 MSAN_UNPOISON(arguments, sizeof(*arguments)); | 100 MSAN_UNPOISON(arguments, sizeof(*arguments)); |
96 Thread* thread = arguments->thread(); | 101 Thread* thread = arguments->thread(); |
97 Isolate* isolate = thread->isolate(); | 102 Isolate* isolate = thread->isolate(); |
98 | 103 |
99 ApiState* state = isolate->api_state(); | 104 ApiState* state = isolate->api_state(); |
100 ASSERT(state != NULL); | 105 ASSERT(state != NULL); |
101 ApiLocalScope* current_top_scope = thread->api_top_scope(); | 106 ApiLocalScope* current_top_scope = thread->api_top_scope(); |
102 ApiLocalScope* scope = thread->api_reusable_scope(); | 107 ApiLocalScope* scope = thread->api_reusable_scope(); |
103 TRACE_NATIVE_CALL("0x%" Px "", reinterpret_cast<uintptr_t>(func)); | 108 TRACE_NATIVE_CALL("0x%" Px "", reinterpret_cast<uintptr_t>(func)); |
| 109 TransitionGeneratedToNative transition(thread); |
104 if (scope == NULL) { | 110 if (scope == NULL) { |
105 scope = new ApiLocalScope(current_top_scope, | 111 scope = new ApiLocalScope(current_top_scope, |
106 thread->top_exit_frame_info()); | 112 thread->top_exit_frame_info()); |
107 ASSERT(scope != NULL); | 113 ASSERT(scope != NULL); |
108 } else { | 114 } else { |
109 scope->Reinit(thread, | 115 scope->Reinit(thread, |
110 current_top_scope, | 116 current_top_scope, |
111 thread->top_exit_frame_info()); | 117 thread->top_exit_frame_info()); |
112 thread->set_api_reusable_scope(NULL); | 118 thread->set_api_reusable_scope(NULL); |
113 } | 119 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 MSAN_UNPOISON(arguments, sizeof(*arguments)); | 172 MSAN_UNPOISON(arguments, sizeof(*arguments)); |
167 TRACE_NATIVE_CALL("%s", "LinkNative"); | 173 TRACE_NATIVE_CALL("%s", "LinkNative"); |
168 | 174 |
169 NativeFunction target_function = NULL; | 175 NativeFunction target_function = NULL; |
170 bool call_through_wrapper = false; | 176 bool call_through_wrapper = false; |
171 #ifdef USING_SIMULATOR | 177 #ifdef USING_SIMULATOR |
172 bool is_native_auto_setup_scope = false; | 178 bool is_native_auto_setup_scope = false; |
173 #endif | 179 #endif |
174 | 180 |
175 { | 181 { |
| 182 TransitionGeneratedToVM transition(arguments->thread()); |
176 StackZone zone(arguments->thread()); | 183 StackZone zone(arguments->thread()); |
177 | 184 |
178 DartFrameIterator iterator; | 185 DartFrameIterator iterator; |
179 StackFrame* caller_frame = iterator.NextFrame(); | 186 StackFrame* caller_frame = iterator.NextFrame(); |
180 | 187 |
181 const Code& code = Code::Handle(caller_frame->LookupDartCode()); | 188 const Code& code = Code::Handle(caller_frame->LookupDartCode()); |
182 const Function& func = Function::Handle(code.function()); | 189 const Function& func = Function::Handle(code.function()); |
183 #ifdef USING_SIMULATOR | 190 #ifdef USING_SIMULATOR |
184 is_native_auto_setup_scope = func.IsNativeAutoSetupScope(); | 191 is_native_auto_setup_scope = func.IsNativeAutoSetupScope(); |
185 #endif | 192 #endif |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 if (call_through_wrapper) { | 259 if (call_through_wrapper) { |
253 NativeEntry::NativeCallWrapper( | 260 NativeEntry::NativeCallWrapper( |
254 args, reinterpret_cast<Dart_NativeFunction>(target_function)); | 261 args, reinterpret_cast<Dart_NativeFunction>(target_function)); |
255 } else { | 262 } else { |
256 target_function(arguments); | 263 target_function(arguments); |
257 } | 264 } |
258 } | 265 } |
259 | 266 |
260 | 267 |
261 } // namespace dart | 268 } // namespace dart |
OLD | NEW |