| 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 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const NativeLibraryOptions& options, | 23 const NativeLibraryOptions& options, |
| 24 NativeLibraryLoadError* error) { | 24 NativeLibraryLoadError* error) { |
| 25 // dlopen() opens the file off disk. | 25 // dlopen() opens the file off disk. |
| 26 ThreadRestrictions::AssertIOAllowed(); | 26 ThreadRestrictions::AssertIOAllowed(); |
| 27 | 27 |
| 28 // We deliberately do not use RTLD_DEEPBIND by default. For the history why, | 28 // We deliberately do not use RTLD_DEEPBIND by default. For the history why, |
| 29 // please refer to the bug tracker. Some useful bug reports to read include: | 29 // please refer to the bug tracker. Some useful bug reports to read include: |
| 30 // http://crbug.com/17943, http://crbug.com/17557, http://crbug.com/36892, | 30 // http://crbug.com/17943, http://crbug.com/17557, http://crbug.com/36892, |
| 31 // and http://crbug.com/40794. | 31 // and http://crbug.com/40794. |
| 32 int flags = RTLD_LAZY; | 32 int flags = RTLD_LAZY; |
| 33 #if defined(OS_ANDROID) | 33 #if defined(OS_ANDROID) || !defined(RTLD_DEEPBIND) |
| 34 // Android dlopen() requires further investigation, as it might vary across | 34 // Certain platforms don't define RTLD_DEEPBIND. Android dlopen() requires |
| 35 // versions. Crash here to warn developers that they're trying to rely on | 35 // further investigation, as it might vary across versions. Crash here to |
| 36 // uncertain behavior. | 36 // warn developers that they're trying to rely on uncertain behavior. |
| 37 CHECK(!options.prefer_own_symbols); | 37 CHECK(!options.prefer_own_symbols); |
| 38 #else | 38 #else |
| 39 if (options.prefer_own_symbols) | 39 if (options.prefer_own_symbols) |
| 40 flags |= RTLD_DEEPBIND; | 40 flags |= RTLD_DEEPBIND; |
| 41 #endif | 41 #endif |
| 42 void* dl = dlopen(library_path.value().c_str(), flags); | 42 void* dl = dlopen(library_path.value().c_str(), flags); |
| 43 if (!dl && error) | 43 if (!dl && error) |
| 44 error->message = dlerror(); | 44 error->message = dlerror(); |
| 45 | 45 |
| 46 return dl; | 46 return dl; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 return dlsym(library, name.data()); | 61 return dlsym(library, name.data()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // static | 64 // static |
| 65 std::string GetNativeLibraryName(StringPiece name) { | 65 std::string GetNativeLibraryName(StringPiece name) { |
| 66 DCHECK(IsStringASCII(name)); | 66 DCHECK(IsStringASCII(name)); |
| 67 return "lib" + name.as_string() + ".so"; | 67 return "lib" + name.as_string() + ".so"; |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace base | 70 } // namespace base |
| OLD | NEW |