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

Side by Side Diff: base/native_library.h

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 #ifndef BASE_NATIVE_LIBRARY_H_ 5 #ifndef BASE_NATIVE_LIBRARY_H_
6 #define BASE_NATIVE_LIBRARY_H_ 6 #define BASE_NATIVE_LIBRARY_H_
7 7
8 // This file defines a cross-platform "NativeLibrary" type which represents 8 // This file defines a cross-platform "NativeLibrary" type which represents
9 // a loadable module. 9 // a loadable module.
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // Returns a string representation of the load error. 58 // Returns a string representation of the load error.
59 std::string ToString() const; 59 std::string ToString() const;
60 60
61 #if defined(OS_WIN) 61 #if defined(OS_WIN)
62 DWORD code; 62 DWORD code;
63 #else 63 #else
64 std::string message; 64 std::string message;
65 #endif // OS_WIN 65 #endif // OS_WIN
66 }; 66 };
67 67
68 struct BASE_EXPORT NativeLibraryOptions {
Primiano Tucci (use gerrit) 2016/08/24 22:14:09 If there are no other use cases this IMHO should b
Ken Rockot(use gerrit already) 2016/08/24 23:23:57 I'd prefer to use a struct here only because it's
Primiano Tucci (use gerrit) 2016/08/25 10:20:44 I leave this to base owners, as I'm not an owner h
69 NativeLibraryOptions() {}
70
71 // If |true| the library will prefer its own symbols in lieu of symbols in the
72 // global scope. This is ignored on non-POSIX platforms. On POSIX the behavior
73 // when |true| corresponds to setting RTLD_DEEPBIND on dlopen().
Primiano Tucci (use gerrit) 2016/08/24 22:14:09 Interestingly it seems that on Mac OSX DEEPBIND is
Ken Rockot(use gerrit already) 2016/08/24 23:23:57 Added a note about this
74 bool prefer_own_symbols = false;
75 };
76
68 // Loads a native library from disk. Release it with UnloadNativeLibrary when 77 // Loads a native library from disk. Release it with UnloadNativeLibrary when
69 // you're done. Returns NULL on failure. 78 // you're done. Returns NULL on failure.
70 // If |error| is not NULL, it may be filled in on load error. 79 // If |error| is not NULL, it may be filled in on load error.
71 BASE_EXPORT NativeLibrary LoadNativeLibrary(const FilePath& library_path, 80 BASE_EXPORT NativeLibrary LoadNativeLibrary(const FilePath& library_path,
72 NativeLibraryLoadError* error); 81 NativeLibraryLoadError* error);
73 82
83 // Loads a native library from disk. Release it with UnloadNativeLibrary when
84 // you're done. Returns NULL on failure.
85 // If |error| is not NULL, it may be filled in on load error.
86 BASE_EXPORT NativeLibrary LoadNativeLibraryWithOptions(
87 const FilePath& library_path,
88 const NativeLibraryOptions& options,
89 NativeLibraryLoadError* error);
90
74 #if defined(OS_WIN) 91 #if defined(OS_WIN)
75 // Loads a native library from disk. Release it with UnloadNativeLibrary when 92 // Loads a native library from disk. Release it with UnloadNativeLibrary when
76 // you're done. 93 // you're done.
77 // This function retrieves the LoadLibrary function exported from kernel32.dll 94 // This function retrieves the LoadLibrary function exported from kernel32.dll
78 // and calls it instead of directly calling the LoadLibrary function via the 95 // and calls it instead of directly calling the LoadLibrary function via the
79 // import table. 96 // import table.
80 BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically( 97 BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically(
81 const FilePath& library_path); 98 const FilePath& library_path);
82 #endif // OS_WIN 99 #endif // OS_WIN
83 100
84 // Unloads a native library. 101 // Unloads a native library.
85 BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library); 102 BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library);
86 103
87 // Gets a function pointer from a native library. 104 // Gets a function pointer from a native library.
88 BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, 105 BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
89 StringPiece name); 106 StringPiece name);
90 107
91 // Returns the full platform specific name for a native library. 108 // Returns the full platform specific name for a native library.
92 // |name| must be ASCII. 109 // |name| must be ASCII.
93 // For example: 110 // For example:
94 // "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux, 111 // "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux,
95 // "libmylib.dylib" on Mac. 112 // "libmylib.dylib" on Mac.
96 BASE_EXPORT std::string GetNativeLibraryName(StringPiece name); 113 BASE_EXPORT std::string GetNativeLibraryName(StringPiece name);
97 114
98 } // namespace base 115 } // namespace base
99 116
100 #endif // BASE_NATIVE_LIBRARY_H_ 117 #endif // BASE_NATIVE_LIBRARY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698