OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 | 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/bootstrap.h" | 5 #include "vm/bootstrap.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/bootstrap_natives.h" | 9 #include "vm/bootstrap_natives.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
12 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
13 #include "vm/service_isolate.h" | 13 #include "vm/service_isolate.h" |
14 | 14 |
15 namespace dart { | 15 namespace dart { |
16 | 16 |
17 // Helper macros for declaring and defining native entries. | 17 // Helper macros for declaring and defining native entries. |
18 #define REGISTER_NATIVE_ENTRY(name, count) \ | 18 #define REGISTER_NATIVE_ENTRY(name, count) \ |
19 {"" #name, BootstrapNatives::DN_##name, count}, | 19 {"" #name, BootstrapNatives::DN_##name, count}, |
20 | 20 |
21 | |
22 // List all native functions implemented in the vm or core bootstrap dart | 21 // List all native functions implemented in the vm or core bootstrap dart |
23 // libraries so that we can resolve the native function to it's entry | 22 // libraries so that we can resolve the native function to it's entry |
24 // point. | 23 // point. |
25 static struct NativeEntries { | 24 static struct NativeEntries { |
26 const char* name_; | 25 const char* name_; |
27 Dart_NativeFunction function_; | 26 Dart_NativeFunction function_; |
28 int argument_count_; | 27 int argument_count_; |
29 } BootStrapEntries[] = {BOOTSTRAP_NATIVE_LIST(REGISTER_NATIVE_ENTRY) | 28 } BootStrapEntries[] = {BOOTSTRAP_NATIVE_LIST(REGISTER_NATIVE_ENTRY) |
30 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) | 29 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) |
31 MIRRORS_BOOTSTRAP_NATIVE_LIST(REGISTER_NATIVE_ENTRY) | 30 MIRRORS_BOOTSTRAP_NATIVE_LIST(REGISTER_NATIVE_ENTRY) |
32 #endif // !PRODUCT && !DART_PRECOMPILED_RUNTIME | 31 #endif // !PRODUCT && !DART_PRECOMPILED_RUNTIME |
33 }; | 32 }; |
34 | 33 |
35 | |
36 Dart_NativeFunction BootstrapNatives::Lookup(Dart_Handle name, | 34 Dart_NativeFunction BootstrapNatives::Lookup(Dart_Handle name, |
37 int argument_count, | 35 int argument_count, |
38 bool* auto_setup_scope) { | 36 bool* auto_setup_scope) { |
39 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); | 37 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); |
40 if (!obj.IsString()) { | 38 if (!obj.IsString()) { |
41 return NULL; | 39 return NULL; |
42 } | 40 } |
43 ASSERT(auto_setup_scope); | 41 ASSERT(auto_setup_scope); |
44 *auto_setup_scope = false; | 42 *auto_setup_scope = false; |
45 const char* function_name = obj.ToCString(); | 43 const char* function_name = obj.ToCString(); |
46 ASSERT(function_name != NULL); | 44 ASSERT(function_name != NULL); |
47 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries); | 45 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries); |
48 for (int i = 0; i < num_entries; i++) { | 46 for (int i = 0; i < num_entries; i++) { |
49 struct NativeEntries* entry = &(BootStrapEntries[i]); | 47 struct NativeEntries* entry = &(BootStrapEntries[i]); |
50 if ((strcmp(function_name, entry->name_) == 0) && | 48 if ((strcmp(function_name, entry->name_) == 0) && |
51 (entry->argument_count_ == argument_count)) { | 49 (entry->argument_count_ == argument_count)) { |
52 return reinterpret_cast<Dart_NativeFunction>(entry->function_); | 50 return reinterpret_cast<Dart_NativeFunction>(entry->function_); |
53 } | 51 } |
54 } | 52 } |
55 return NULL; | 53 return NULL; |
56 } | 54 } |
57 | 55 |
58 | |
59 const uint8_t* BootstrapNatives::Symbol(Dart_NativeFunction* nf) { | 56 const uint8_t* BootstrapNatives::Symbol(Dart_NativeFunction* nf) { |
60 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries); | 57 int num_entries = sizeof(BootStrapEntries) / sizeof(struct NativeEntries); |
61 for (int i = 0; i < num_entries; i++) { | 58 for (int i = 0; i < num_entries; i++) { |
62 struct NativeEntries* entry = &(BootStrapEntries[i]); | 59 struct NativeEntries* entry = &(BootStrapEntries[i]); |
63 if (reinterpret_cast<Dart_NativeFunction*>(entry->function_) == nf) { | 60 if (reinterpret_cast<Dart_NativeFunction*>(entry->function_) == nf) { |
64 return reinterpret_cast<const uint8_t*>(entry->name_); | 61 return reinterpret_cast<const uint8_t*>(entry->name_); |
65 } | 62 } |
66 } | 63 } |
67 return NULL; | 64 return NULL; |
68 } | 65 } |
69 | 66 |
70 | |
71 void Bootstrap::SetupNativeResolver() { | 67 void Bootstrap::SetupNativeResolver() { |
72 Library& library = Library::Handle(); | 68 Library& library = Library::Handle(); |
73 | 69 |
74 Dart_NativeEntryResolver resolver = | 70 Dart_NativeEntryResolver resolver = |
75 reinterpret_cast<Dart_NativeEntryResolver>(BootstrapNatives::Lookup); | 71 reinterpret_cast<Dart_NativeEntryResolver>(BootstrapNatives::Lookup); |
76 | 72 |
77 Dart_NativeEntrySymbol symbol_resolver = | 73 Dart_NativeEntrySymbol symbol_resolver = |
78 reinterpret_cast<Dart_NativeEntrySymbol>(BootstrapNatives::Symbol); | 74 reinterpret_cast<Dart_NativeEntrySymbol>(BootstrapNatives::Symbol); |
79 | 75 |
80 library = Library::AsyncLibrary(); | 76 library = Library::AsyncLibrary(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 ASSERT(!library.IsNull()); | 129 ASSERT(!library.IsNull()); |
134 library.set_native_entry_resolver(resolver); | 130 library.set_native_entry_resolver(resolver); |
135 library.set_native_entry_symbol_resolver(symbol_resolver); | 131 library.set_native_entry_symbol_resolver(symbol_resolver); |
136 | 132 |
137 library = Library::VMServiceLibrary(); | 133 library = Library::VMServiceLibrary(); |
138 ASSERT(!library.IsNull()); | 134 ASSERT(!library.IsNull()); |
139 library.set_native_entry_resolver(resolver); | 135 library.set_native_entry_resolver(resolver); |
140 library.set_native_entry_symbol_resolver(symbol_resolver); | 136 library.set_native_entry_symbol_resolver(symbol_resolver); |
141 } | 137 } |
142 | 138 |
143 | |
144 bool Bootstrap::IsBootstapResolver(Dart_NativeEntryResolver resolver) { | 139 bool Bootstrap::IsBootstapResolver(Dart_NativeEntryResolver resolver) { |
145 return (resolver == | 140 return (resolver == |
146 reinterpret_cast<Dart_NativeEntryResolver>(BootstrapNatives::Lookup)); | 141 reinterpret_cast<Dart_NativeEntryResolver>(BootstrapNatives::Lookup)); |
147 } | 142 } |
148 | 143 |
149 } // namespace dart | 144 } // namespace dart |
OLD | NEW |