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 #ifndef RUNTIME_VM_NATIVE_ENTRY_H_ | 5 #ifndef RUNTIME_VM_NATIVE_ENTRY_H_ |
6 #define RUNTIME_VM_NATIVE_ENTRY_H_ | 6 #define RUNTIME_VM_NATIVE_ENTRY_H_ |
7 | 7 |
8 #include "platform/memory_sanitizer.h" | 8 #include "platform/memory_sanitizer.h" |
9 | 9 |
10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 | 27 |
28 #define NATIVE_ENTRY_FUNCTION(name) BootstrapNatives::DN_##name | 28 #define NATIVE_ENTRY_FUNCTION(name) BootstrapNatives::DN_##name |
29 | 29 |
30 #ifdef DEBUG | 30 #ifdef DEBUG |
31 #define SET_NATIVE_RETVAL(args, value) \ | 31 #define SET_NATIVE_RETVAL(args, value) \ |
32 RawObject* retval = value; \ | 32 RawObject* retval = value; \ |
33 ASSERT(retval->IsDartInstance()); \ | 33 ASSERT(retval->IsDartInstance()); \ |
34 arguments->SetReturnUnsafe(retval); | 34 arguments->SetReturnUnsafe(retval); |
35 #else | 35 #else |
36 #define SET_NATIVE_RETVAL(arguments, value) \ | 36 #define SET_NATIVE_RETVAL(arguments, value) arguments->SetReturnUnsafe(value); |
37 arguments->SetReturnUnsafe(value); | |
38 #endif | 37 #endif |
39 | 38 |
40 #define DEFINE_NATIVE_ENTRY(name, argument_count) \ | 39 #define DEFINE_NATIVE_ENTRY(name, argument_count) \ |
41 static RawObject* DN_Helper##name(Isolate* isolate, \ | 40 static RawObject* DN_Helper##name(Isolate* isolate, Thread* thread, \ |
42 Thread* thread, \ | 41 Zone* zone, NativeArguments* arguments); \ |
43 Zone* zone, \ | |
44 NativeArguments* arguments); \ | |
45 void NATIVE_ENTRY_FUNCTION(name)(Dart_NativeArguments args) { \ | 42 void NATIVE_ENTRY_FUNCTION(name)(Dart_NativeArguments args) { \ |
46 CHECK_STACK_ALIGNMENT; \ | 43 CHECK_STACK_ALIGNMENT; \ |
47 VERIFY_ON_TRANSITION; \ | 44 VERIFY_ON_TRANSITION; \ |
48 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); \ | 45 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); \ |
49 /* Tell MemorySanitizer 'arguments' is initialized by generated code. */ \ | 46 /* Tell MemorySanitizer 'arguments' is initialized by generated code. */ \ |
50 MSAN_UNPOISON(arguments, sizeof(*arguments)); \ | 47 MSAN_UNPOISON(arguments, sizeof(*arguments)); \ |
51 ASSERT(arguments->NativeArgCount() == argument_count); \ | 48 ASSERT(arguments->NativeArgCount() == argument_count); \ |
52 TRACE_NATIVE_CALL("%s", ""#name); \ | 49 TRACE_NATIVE_CALL("%s", "" #name); \ |
53 { \ | 50 { \ |
54 Thread* thread = arguments->thread(); \ | 51 Thread* thread = arguments->thread(); \ |
55 ASSERT(thread == Thread::Current()); \ | 52 ASSERT(thread == Thread::Current()); \ |
56 Isolate* isolate = thread->isolate(); \ | 53 Isolate* isolate = thread->isolate(); \ |
57 TransitionGeneratedToVM transition(thread); \ | 54 TransitionGeneratedToVM transition(thread); \ |
58 StackZone zone(thread); \ | 55 StackZone zone(thread); \ |
59 SET_NATIVE_RETVAL(arguments, \ | 56 SET_NATIVE_RETVAL( \ |
60 DN_Helper##name(isolate, \ | 57 arguments, \ |
61 thread, \ | 58 DN_Helper##name(isolate, thread, zone.GetZone(), arguments)); \ |
62 zone.GetZone(), \ | |
63 arguments)); \ | |
64 DEOPTIMIZE_ALOT; \ | 59 DEOPTIMIZE_ALOT; \ |
65 } \ | 60 } \ |
66 VERIFY_ON_TRANSITION; \ | 61 VERIFY_ON_TRANSITION; \ |
67 } \ | 62 } \ |
68 static RawObject* DN_Helper##name(Isolate* isolate, \ | 63 static RawObject* DN_Helper##name(Isolate* isolate, Thread* thread, \ |
69 Thread* thread, \ | 64 Zone* zone, NativeArguments* arguments) |
70 Zone* zone, \ | |
71 NativeArguments* arguments) | |
72 | 65 |
73 | 66 |
74 // Helper that throws an argument exception. | 67 // Helper that throws an argument exception. |
75 void DartNativeThrowArgumentException(const Instance& instance); | 68 void DartNativeThrowArgumentException(const Instance& instance); |
76 | 69 |
77 // Natives should throw an exception if an illegal argument or null is passed. | 70 // Natives should throw an exception if an illegal argument or null is passed. |
78 // type name = value. | 71 // type name = value. |
79 #define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value) \ | 72 #define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value) \ |
80 const Instance& __##name##_instance__ = \ | 73 const Instance& __##name##_instance__ = \ |
81 Instance::CheckedHandle(zone, value); \ | 74 Instance::CheckedHandle(zone, value); \ |
(...skipping 29 matching lines...) Expand all Loading... |
111 int number_of_arguments, | 104 int number_of_arguments, |
112 bool* auto_setup_scope); | 105 bool* auto_setup_scope); |
113 static const uint8_t* ResolveSymbolInLibrary(const Library& library, | 106 static const uint8_t* ResolveSymbolInLibrary(const Library& library, |
114 uword pc); | 107 uword pc); |
115 static const uint8_t* ResolveSymbol(uword pc); | 108 static const uint8_t* ResolveSymbol(uword pc); |
116 | 109 |
117 static uword NativeCallWrapperEntry(); | 110 static uword NativeCallWrapperEntry(); |
118 static void NativeCallWrapper(Dart_NativeArguments args, | 111 static void NativeCallWrapper(Dart_NativeArguments args, |
119 Dart_NativeFunction func); | 112 Dart_NativeFunction func); |
120 | 113 |
121 // DBC does not support lazy native call linking. | 114 // DBC does not support lazy native call linking. |
122 #if !defined(TARGET_ARCH_DBC) | 115 #if !defined(TARGET_ARCH_DBC) |
123 static uword LinkNativeCallEntry(); | 116 static uword LinkNativeCallEntry(); |
124 static void LinkNativeCall(Dart_NativeArguments args); | 117 static void LinkNativeCall(Dart_NativeArguments args); |
125 #endif | 118 #endif |
126 | 119 |
127 private: | 120 private: |
128 static void NativeCallWrapperNoStackCheck(Dart_NativeArguments args, | 121 static void NativeCallWrapperNoStackCheck(Dart_NativeArguments args, |
129 Dart_NativeFunction func); | 122 Dart_NativeFunction func); |
130 | 123 |
131 static bool ReturnValueIsError(NativeArguments* arguments); | 124 static bool ReturnValueIsError(NativeArguments* arguments); |
132 static void PropagateErrors(NativeArguments* arguments); | 125 static void PropagateErrors(NativeArguments* arguments); |
133 }; | 126 }; |
134 | 127 |
135 } // namespace dart | 128 } // namespace dart |
136 | 129 |
137 #endif // RUNTIME_VM_NATIVE_ENTRY_H_ | 130 #endif // RUNTIME_VM_NATIVE_ENTRY_H_ |
OLD | NEW |