| 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 <ostream> |
| 8 |
| 7 #include <dlfcn.h> | 9 #include <dlfcn.h> |
| 8 #include <mach-o/getsect.h> | 10 #include <mach-o/getsect.h> |
| 9 | 11 |
| 10 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 35 SEG_DATA, "__objc_imageinfo"); | 37 SEG_DATA, "__objc_imageinfo"); |
| 36 #else | 38 #else |
| 37 const section* section = getsectbynamefromheader( | 39 const section* section = getsectbynamefromheader( |
| 38 reinterpret_cast<const struct mach_header*>(info.dli_fbase), | 40 reinterpret_cast<const struct mach_header*>(info.dli_fbase), |
| 39 SEG_OBJC, "__image_info"); | 41 SEG_OBJC, "__image_info"); |
| 40 #endif | 42 #endif |
| 41 return section == NULL ? OBJC_NOT_PRESENT : OBJC_PRESENT; | 43 return section == NULL ? OBJC_NOT_PRESENT : OBJC_PRESENT; |
| 42 } | 44 } |
| 43 | 45 |
| 44 // static | 46 // static |
| 47 // TODO(xhwang): Fill |error|. See http://crbug.com/353771 |
| 45 NativeLibrary LoadNativeLibrary(const base::FilePath& library_path, | 48 NativeLibrary LoadNativeLibrary(const base::FilePath& library_path, |
| 46 std::string* error) { | 49 NativeLibraryLoadError* /* error */) { |
| 47 // dlopen() etc. open the file off disk. | 50 // dlopen() etc. open the file off disk. |
| 48 if (library_path.Extension() == "dylib" || !DirectoryExists(library_path)) { | 51 if (library_path.Extension() == "dylib" || !DirectoryExists(library_path)) { |
| 49 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); | 52 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); |
| 50 if (!dylib) | 53 if (!dylib) |
| 51 return NULL; | 54 return NULL; |
| 52 NativeLibrary native_lib = new NativeLibraryStruct(); | 55 NativeLibrary native_lib = new NativeLibraryStruct(); |
| 53 native_lib->type = DYNAMIC_LIB; | 56 native_lib->type = DYNAMIC_LIB; |
| 54 native_lib->dylib = dylib; | 57 native_lib->dylib = dylib; |
| 55 native_lib->objc_status = OBJC_UNKNOWN; | 58 native_lib->objc_status = OBJC_UNKNOWN; |
| 56 return native_lib; | 59 return native_lib; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 library->objc_status = GetObjCStatusForImage(function_pointer); | 118 library->objc_status = GetObjCStatusForImage(function_pointer); |
| 116 | 119 |
| 117 return function_pointer; | 120 return function_pointer; |
| 118 } | 121 } |
| 119 | 122 |
| 120 // static | 123 // static |
| 121 string16 GetNativeLibraryName(const string16& name) { | 124 string16 GetNativeLibraryName(const string16& name) { |
| 122 return name + ASCIIToUTF16(".dylib"); | 125 return name + ASCIIToUTF16(".dylib"); |
| 123 } | 126 } |
| 124 | 127 |
| 128 // static |
| 129 std::ostream& operator<<(std::ostream& out, |
| 130 const NativeLibraryLoadError& error) { |
| 131 return out << error.message; |
| 132 } |
| 133 |
| 125 } // namespace base | 134 } // namespace base |
| OLD | NEW |