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

Side by Side Diff: base/native_library_linux.cc

Issue 155558: linux: add flash workarounds (Closed)
Patch Set: Created 11 years, 5 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <set>
8 9
9 #include "base/file_path.h" 10 #include "base/file_path.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/singleton.h"
11 #include "base/string_util.h" 13 #include "base/string_util.h"
12 14
13 namespace base { 15 namespace base {
14 16
17 typedef std::set<FilePath> FilePathSet;
18 struct ShallowBindPathDifferentiatingType { };
19 typedef Singleton<FilePathSet,
20 DefaultSingletonTraits<FilePathSet>,
21 ShallowBindPathDifferentiatingType> ShallowBindPathSingleton;
22
23 void AddShallowBindPath(const FilePath& library_path) {
24 FilePathSet *file_path_set = ShallowBindPathSingleton::get();
25 file_path_set->insert(library_path);
26 }
27
28 bool IsShallowBindPath(const FilePath& library_path) {
29 FilePathSet *file_path_set = ShallowBindPathSingleton::get();
30 return file_path_set->find(library_path) != file_path_set->end();
31 }
32
15 // static 33 // static
16 NativeLibrary LoadNativeLibrary(const FilePath& library_path) { 34 NativeLibrary LoadNativeLibrary(const FilePath& library_path) {
17 void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY|RTLD_DEEPBIND); 35 int flags = RTLD_LAZY;
36 if (!IsShallowBindPath(library_path))
37 flags |= RTLD_DEEPBIND;
38 void* dl = dlopen(library_path.value().c_str(), flags);
18 if (!dl) { 39 if (!dl) {
19 LOG(ERROR) << "dlopen failed when trying to open " << library_path.value() 40 LOG(ERROR) << "dlopen failed when trying to open " << library_path.value()
20 << ": " << dlerror(); 41 << ": " << dlerror();
21 } 42 }
22 43
23 return dl; 44 return dl;
24 } 45 }
25 46
26 // static 47 // static
27 void UnloadNativeLibrary(NativeLibrary library) { 48 void UnloadNativeLibrary(NativeLibrary library) {
28 int ret = dlclose(library); 49 int ret = dlclose(library);
29 if (ret < 0) 50 if (ret < 0)
30 NOTREACHED() << "dlclose failed: " << dlerror(); 51 NOTREACHED() << "dlclose failed: " << dlerror();
31 } 52 }
32 53
33 // static 54 // static
34 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, 55 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
35 const char* name) { 56 const char* name) {
36 return dlsym(library, name); 57 return dlsym(library, name);
37 } 58 }
38 59
39 // static 60 // static
40 string16 GetNativeLibraryName(const string16& name) { 61 string16 GetNativeLibraryName(const string16& name) {
41 return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so"); 62 return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so");
42 } 63 }
43 64
44 } // namespace base 65 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698