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