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/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 reinterpret_cast<const struct mach_header_64*>(info.dli_fbase), | 34 reinterpret_cast<const struct mach_header_64*>(info.dli_fbase), |
35 SEG_DATA, "__objc_imageinfo"); | 35 SEG_DATA, "__objc_imageinfo"); |
36 #else | 36 #else |
37 const section* section = getsectbynamefromheader( | 37 const section* section = getsectbynamefromheader( |
38 reinterpret_cast<const struct mach_header*>(info.dli_fbase), | 38 reinterpret_cast<const struct mach_header*>(info.dli_fbase), |
39 SEG_OBJC, "__image_info"); | 39 SEG_OBJC, "__image_info"); |
40 #endif | 40 #endif |
41 return section == NULL ? OBJC_NOT_PRESENT : OBJC_PRESENT; | 41 return section == NULL ? OBJC_NOT_PRESENT : OBJC_PRESENT; |
42 } | 42 } |
43 | 43 |
| 44 std::string NativeLibraryLoadError::ToString() const { |
| 45 return message; |
| 46 } |
| 47 |
44 // static | 48 // static |
| 49 // TODO(xhwang): Fill |error|. See http://crbug.com/353771 |
45 NativeLibrary LoadNativeLibrary(const base::FilePath& library_path, | 50 NativeLibrary LoadNativeLibrary(const base::FilePath& library_path, |
46 std::string* error) { | 51 NativeLibraryLoadError* /* error */) { |
47 // dlopen() etc. open the file off disk. | 52 // dlopen() etc. open the file off disk. |
48 if (library_path.Extension() == "dylib" || !DirectoryExists(library_path)) { | 53 if (library_path.Extension() == "dylib" || !DirectoryExists(library_path)) { |
49 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); | 54 void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY); |
50 if (!dylib) | 55 if (!dylib) |
51 return NULL; | 56 return NULL; |
52 NativeLibrary native_lib = new NativeLibraryStruct(); | 57 NativeLibrary native_lib = new NativeLibraryStruct(); |
53 native_lib->type = DYNAMIC_LIB; | 58 native_lib->type = DYNAMIC_LIB; |
54 native_lib->dylib = dylib; | 59 native_lib->dylib = dylib; |
55 native_lib->objc_status = OBJC_UNKNOWN; | 60 native_lib->objc_status = OBJC_UNKNOWN; |
56 return native_lib; | 61 return native_lib; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 121 |
117 return function_pointer; | 122 return function_pointer; |
118 } | 123 } |
119 | 124 |
120 // static | 125 // static |
121 string16 GetNativeLibraryName(const string16& name) { | 126 string16 GetNativeLibraryName(const string16& name) { |
122 return name + ASCIIToUTF16(".dylib"); | 127 return name + ASCIIToUTF16(".dylib"); |
123 } | 128 } |
124 | 129 |
125 } // namespace base | 130 } // namespace base |
OLD | NEW |