| 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "platform/globals.h" | 6 #include "platform/globals.h" |
| 7 #if defined(TARGET_OS_MACOS) | 7 #if defined(TARGET_OS_MACOS) |
| 8 | 8 |
| 9 #include "bin/extensions.h" | 9 #include "bin/extensions.h" |
| 10 #include <dlfcn.h> // NOLINT | 10 #include <dlfcn.h> // NOLINT |
| 11 | 11 |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 namespace bin { | 14 namespace bin { |
| 15 | 15 |
| 16 const char* kPrecompiledLibraryName = "libprecompiled.dylib"; | 16 const char* kPrecompiledLibraryName = "libprecompiled.dylib"; |
| 17 const char* kPrecompiledSymbolName = "kInstructionsSnapshot"; | 17 const char* kPrecompiledSymbolName = "kInstructionsSnapshot"; |
| 18 | 18 |
| 19 Dart_Handle Extensions::LoadExtensionLibrary(const char* library_file, | 19 Dart_Handle Extensions::LoadExtensionLibrary(const char* library_file, |
| 20 void** library_handle) { | 20 void** library_handle) { |
| 21 ASSERT(library_handle != NULL); | 21 ASSERT(library_handle != NULL); |
| 22 *library_handle = dlopen(library_file, RTLD_LAZY); | 22 *library_handle = dlopen(library_file, RTLD_LAZY); |
| 23 if (*library_handle == NULL) { | 23 if (*library_handle == NULL) { |
| 24 return Dart_NewApiError(dlerror()); | 24 return Dart_NewApiError(dlerror()); |
| 25 } | 25 } |
| 26 return Dart_Null(); | 26 return Dart_Null(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void* Extensions::LoadExtensionLibrary(const char* library_file) { |
| 30 return dlopen(library_file, RTLD_LAZY); |
| 31 } |
| 32 |
| 29 Dart_Handle Extensions::ResolveSymbol(void* lib_handle, | 33 Dart_Handle Extensions::ResolveSymbol(void* lib_handle, |
| 30 const char* symbol, | 34 const char* symbol, |
| 31 void** init_function) { | 35 void** init_function) { |
| 32 ASSERT(init_function != NULL); | 36 ASSERT(init_function != NULL); |
| 33 dlerror(); | 37 dlerror(); |
| 34 *init_function = dlsym(lib_handle, symbol); | 38 *init_function = dlsym(lib_handle, symbol); |
| 35 char* err_str = dlerror(); | 39 char* err_str = dlerror(); |
| 36 if (err_str != NULL) { | 40 if (err_str != NULL) { |
| 37 return Dart_NewApiError(err_str); | 41 return Dart_NewApiError(err_str); |
| 38 } | 42 } |
| 39 return Dart_Null(); | 43 return Dart_Null(); |
| 40 } | 44 } |
| 41 | 45 |
| 46 void* Extensions::ResolveSymbol(void* lib_handle, const char* symbol) { |
| 47 dlerror(); |
| 48 void* result = dlsym(lib_handle, symbol); |
| 49 if (dlerror() != NULL) return NULL; |
| 50 return result; |
| 51 } |
| 52 |
| 42 } // namespace bin | 53 } // namespace bin |
| 43 } // namespace dart | 54 } // namespace dart |
| 44 | 55 |
| 45 #endif // defined(TARGET_OS_MACOS) | 56 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |