| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/native_library.h" | 5 #include "base/native_library.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <mach-o/getsect.h> | 8 #include <mach-o/getsect.h> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 reinterpret_cast<const struct mach_header_64*>(info.dli_fbase), | 32 reinterpret_cast<const struct mach_header_64*>(info.dli_fbase), |
| 33 SEG_DATA, "__objc_imageinfo"); | 33 SEG_DATA, "__objc_imageinfo"); |
| 34 return section ? OBJC_PRESENT : OBJC_NOT_PRESENT; | 34 return section ? OBJC_PRESENT : OBJC_NOT_PRESENT; |
| 35 } | 35 } |
| 36 | 36 |
| 37 std::string NativeLibraryLoadError::ToString() const { | 37 std::string NativeLibraryLoadError::ToString() const { |
| 38 return message; | 38 return message; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // static | 41 // static |
| 42 NativeLibrary LoadNativeLibrary(const FilePath& library_path, | 42 NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path, |
| 43 NativeLibraryLoadError* error) { | 43 const NativeLibraryOptions& options, |
| 44 NativeLibraryLoadError* error) { |
| 44 // dlopen() etc. open the file off disk. | 45 // dlopen() etc. open the file off disk. |
| 45 if (library_path.Extension() == "dylib" || !DirectoryExists(library_path)) { | 46 if (library_path.Extension() == "dylib" || !DirectoryExists(library_path)) { |
| 46 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); | 47 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); |
| 47 if (!dylib) { | 48 if (!dylib) { |
| 48 if (error) | 49 if (error) |
| 49 error->message = dlerror(); | 50 error->message = dlerror(); |
| 50 return nullptr; | 51 return nullptr; |
| 51 } | 52 } |
| 52 NativeLibrary native_lib = new NativeLibraryStruct(); | 53 NativeLibrary native_lib = new NativeLibraryStruct(); |
| 53 native_lib->type = DYNAMIC_LIB; | 54 native_lib->type = DYNAMIC_LIB; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 return function_pointer; | 118 return function_pointer; |
| 118 } | 119 } |
| 119 | 120 |
| 120 // static | 121 // static |
| 121 std::string GetNativeLibraryName(StringPiece name) { | 122 std::string GetNativeLibraryName(StringPiece name) { |
| 122 DCHECK(IsStringASCII(name)); | 123 DCHECK(IsStringASCII(name)); |
| 123 return "lib" + name.as_string() + ".dylib"; | 124 return "lib" + name.as_string() + ".dylib"; |
| 124 } | 125 } |
| 125 | 126 |
| 126 } // namespace base | 127 } // namespace base |
| OLD | NEW |