Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1722)

Side by Side Diff: runtime/vm/native_entry.cc

Issue 2944483003: Fail more helpfully when invoking a null native function. (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 21 matching lines...) Expand all
32 __args__.SetAt(0, instance); 32 __args__.SetAt(0, instance);
33 Exceptions::ThrowByType(Exceptions::kArgument, __args__); 33 Exceptions::ThrowByType(Exceptions::kArgument, __args__);
34 } 34 }
35 35
36 36
37 NativeFunction NativeEntry::ResolveNative(const Library& library, 37 NativeFunction NativeEntry::ResolveNative(const Library& library,
38 const String& function_name, 38 const String& function_name,
39 int number_of_arguments, 39 int number_of_arguments,
40 bool* auto_setup_scope) { 40 bool* auto_setup_scope) {
41 // Now resolve the native function to the corresponding native entrypoint. 41 // Now resolve the native function to the corresponding native entrypoint.
42 if (library.native_entry_resolver() == 0) { 42 if (library.native_entry_resolver() == NULL) {
43 // Native methods are not allowed in the library to which this 43 // Native methods are not allowed in the library to which this
44 // class belongs in. 44 // class belongs in.
45 return NULL; 45 return NULL;
46 } 46 }
47 Dart_NativeFunction native_function = NULL; 47 Dart_NativeFunction native_function = NULL;
48 { 48 {
49 Thread* T = Thread::Current(); 49 Thread* T = Thread::Current();
50 TransitionVMToNative transition(T); 50 TransitionVMToNative transition(T);
51 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries. 51 Dart_EnterScope(); // Enter a new Dart API scope as we invoke API entries.
52 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); 52 Dart_NativeEntryResolver resolver = library.native_entry_resolver();
53 native_function = resolver(Api::NewHandle(T, function_name.raw()), 53 native_function = resolver(Api::NewHandle(T, function_name.raw()),
54 number_of_arguments, auto_setup_scope); 54 number_of_arguments, auto_setup_scope);
55 Dart_ExitScope(); // Exit the Dart API scope. 55 Dart_ExitScope(); // Exit the Dart API scope.
56 } 56 }
57 return reinterpret_cast<NativeFunction>(native_function); 57 return reinterpret_cast<NativeFunction>(native_function);
58 } 58 }
59 59
60 60
61 const uint8_t* NativeEntry::ResolveSymbolInLibrary(const Library& library, 61 const uint8_t* NativeEntry::ResolveSymbolInLibrary(const Library& library,
62 uword pc) { 62 uword pc) {
63 Dart_NativeEntrySymbol symbol_resolver = 63 Dart_NativeEntrySymbol symbol_resolver =
64 library.native_entry_symbol_resolver(); 64 library.native_entry_symbol_resolver();
65 if (symbol_resolver == 0) { 65 if (symbol_resolver == NULL) {
66 // Cannot reverse lookup native entries. 66 // Cannot reverse lookup native entries.
67 return NULL; 67 return NULL;
68 } 68 }
69 return symbol_resolver(reinterpret_cast<Dart_NativeFunction>(pc)); 69 return symbol_resolver(reinterpret_cast<Dart_NativeFunction>(pc));
70 } 70 }
71 71
72 72
73 const uint8_t* NativeEntry::ResolveSymbol(uword pc) { 73 const uint8_t* NativeEntry::ResolveSymbol(uword pc) {
74 Thread* thread = Thread::Current(); 74 Thread* thread = Thread::Current();
75 REUSABLE_GROWABLE_OBJECT_ARRAY_HANDLESCOPE(thread); 75 REUSABLE_GROWABLE_OBJECT_ARRAY_HANDLESCOPE(thread);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 const Class& cls = Class::Handle(zone, func.Owner()); 225 const Class& cls = Class::Handle(zone, func.Owner());
226 const Library& library = Library::Handle(zone, cls.library()); 226 const Library& library = Library::Handle(zone, cls.library());
227 227
228 *is_bootstrap_native = 228 *is_bootstrap_native =
229 Bootstrap::IsBootstapResolver(library.native_entry_resolver()); 229 Bootstrap::IsBootstapResolver(library.native_entry_resolver());
230 230
231 const String& native_name = String::Handle(zone, func.native_name()); 231 const String& native_name = String::Handle(zone, func.native_name());
232 ASSERT(!native_name.IsNull()); 232 ASSERT(!native_name.IsNull());
233 233
234 const int num_params = NativeArguments::ParameterCountForResolution(func); 234 const int num_params = NativeArguments::ParameterCountForResolution(func);
235 return NativeEntry::ResolveNative(library, native_name, num_params, 235 NativeFunction native_function = NativeEntry::ResolveNative(
236 is_auto_scope); 236 library, native_name, num_params, is_auto_scope);
237 if (native_function == NULL) {
238 FATAL2("Failed to resolve native function '%s' in '%s'\n",
239 native_name.ToCString(), func.ToQualifiedCString());
240 }
241 return native_function;
237 } 242 }
238 243
239 244
240 uword NativeEntry::LinkNativeCallEntry() { 245 uword NativeEntry::LinkNativeCallEntry() {
241 uword entry = reinterpret_cast<uword>(NativeEntry::LinkNativeCall); 246 uword entry = reinterpret_cast<uword>(NativeEntry::LinkNativeCall);
242 #if defined(USING_SIMULATOR) 247 #if defined(USING_SIMULATOR)
243 entry = Simulator::RedirectExternalReference( 248 entry = Simulator::RedirectExternalReference(
244 entry, Simulator::kBootstrapNativeCall, NativeEntry::kNumArguments); 249 entry, Simulator::kBootstrapNativeCall, NativeEntry::kNumArguments);
245 #endif 250 #endif
246 return entry; 251 return entry;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // Because this call is within a compilation unit, Clang doesn't respect 344 // Because this call is within a compilation unit, Clang doesn't respect
340 // the ABI alignment here. 345 // the ABI alignment here.
341 NativeEntry::NoScopeNativeCallWrapperNoStackCheck( 346 NativeEntry::NoScopeNativeCallWrapperNoStackCheck(
342 args, reinterpret_cast<Dart_NativeFunction>(target_function)); 347 args, reinterpret_cast<Dart_NativeFunction>(target_function));
343 } 348 }
344 } 349 }
345 #endif // !defined(TARGET_ARCH_DBC) 350 #endif // !defined(TARGET_ARCH_DBC)
346 351
347 352
348 } // namespace dart 353 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698