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

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, 4 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
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 if (options.prefer_own_symbols)
35 flags |= RTLD_DEEPBIND;
Primiano Tucci (use gerrit) 2016/08/24 22:14:09 are you sue you don't need also RTLD_GLOBAL? Can
Ken Rockot(use gerrit already) 2016/08/24 23:23:57 We may want this behavior but it might be worth ke
36 #endif
37 void* dl = dlopen(library_path.value().c_str(), flags);
32 if (!dl && error) 38 if (!dl && error)
33 error->message = dlerror(); 39 error->message = dlerror();
34 40
35 return dl; 41 return dl;
36 } 42 }
37 43
38 // static 44 // static
39 void UnloadNativeLibrary(NativeLibrary library) { 45 void UnloadNativeLibrary(NativeLibrary library) {
40 int ret = dlclose(library); 46 int ret = dlclose(library);
41 if (ret < 0) { 47 if (ret < 0) {
42 DLOG(ERROR) << "dlclose failed: " << dlerror(); 48 DLOG(ERROR) << "dlclose failed: " << dlerror();
43 NOTREACHED(); 49 NOTREACHED();
44 } 50 }
45 } 51 }
46 52
47 // static 53 // static
48 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, 54 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
49 StringPiece name) { 55 StringPiece name) {
50 return dlsym(library, name.data()); 56 return dlsym(library, name.data());
51 } 57 }
52 58
53 // static 59 // static
54 std::string GetNativeLibraryName(StringPiece name) { 60 std::string GetNativeLibraryName(StringPiece name) {
55 DCHECK(IsStringASCII(name)); 61 DCHECK(IsStringASCII(name));
56 return "lib" + name.as_string() + ".so"; 62 return "lib" + name.as_string() + ".so";
57 } 63 }
58 64
59 } // namespace base 65 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698