Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: base/native_library_posix.cc

Issue 2277863002: Enable loading native libraries with RTLD_DEEPBIND (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/native_library_mac.mm ('k') | base/native_library_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 std::string NativeLibraryLoadError::ToString() const { 17 std::string NativeLibraryLoadError::ToString() const {
18 return message; 18 return message;
19 } 19 }
20 20
21 // static 21 // static
22 NativeLibrary LoadNativeLibrary(const FilePath& library_path, 22 NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path,
23 NativeLibraryLoadError* error) { 23 const NativeLibraryOptions& options,
24 NativeLibraryLoadError* error) {
24 // dlopen() opens the file off disk. 25 // dlopen() opens the file off disk.
25 ThreadRestrictions::AssertIOAllowed(); 26 ThreadRestrictions::AssertIOAllowed();
26 27
27 // We deliberately do not use RTLD_DEEPBIND. For the history why, please 28 // We deliberately do not use RTLD_DEEPBIND by default. For the history why,
28 // 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:
29 // 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,
30 // and http://crbug.com/40794. 31 // and http://crbug.com/40794.
31 void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY); 32 int flags = RTLD_LAZY;
33 #if defined(OS_ANDROID)
34 // Android dlopen() requires further investigation, as it might vary across
35 // versions. Crash here to warn developers that they're trying to rely on
36 // uncertain behavior.
37 CHECK(!options.prefer_own_symbols);
38 #else
39 if (options.prefer_own_symbols)
40 flags |= RTLD_DEEPBIND;
41 #endif
42 void* dl = dlopen(library_path.value().c_str(), flags);
32 if (!dl && error) 43 if (!dl && error)
33 error->message = dlerror(); 44 error->message = dlerror();
34 45
35 return dl; 46 return dl;
36 } 47 }
37 48
38 // static 49 // static
39 void UnloadNativeLibrary(NativeLibrary library) { 50 void UnloadNativeLibrary(NativeLibrary library) {
40 int ret = dlclose(library); 51 int ret = dlclose(library);
41 if (ret < 0) { 52 if (ret < 0) {
42 DLOG(ERROR) << "dlclose failed: " << dlerror(); 53 DLOG(ERROR) << "dlclose failed: " << dlerror();
43 NOTREACHED(); 54 NOTREACHED();
44 } 55 }
45 } 56 }
46 57
47 // static 58 // static
48 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, 59 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
49 StringPiece name) { 60 StringPiece name) {
50 return dlsym(library, name.data()); 61 return dlsym(library, name.data());
51 } 62 }
52 63
53 // static 64 // static
54 std::string GetNativeLibraryName(StringPiece name) { 65 std::string GetNativeLibraryName(StringPiece name) {
55 DCHECK(IsStringASCII(name)); 66 DCHECK(IsStringASCII(name));
56 return "lib" + name.as_string() + ".so"; 67 return "lib" + name.as_string() + ".so";
57 } 68 }
58 69
59 } // namespace base 70 } // namespace base
OLDNEW
« no previous file with comments | « base/native_library_mac.mm ('k') | base/native_library_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698