Native Library improvements
This change adds LoadSystemLibrary to NativeLibrary to allow usage of
the NativeLibrary abstraction when loading system dlls and prevent dll
loading attacks. This change also moves ScopedNativeLibrary to base off
of ScopedGeneric so that the scoped class gets all the benefits of
ScopedGeneric without having to re-invent.
Bug: 1551709
Change-Id: I17a14678687bd7d167ab0dad1cff5dbce53c3313
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1560294
Commit-Queue: Cliff Smolinsky <[email protected]>
Reviewed-by: Antoine Labour <[email protected]>
Reviewed-by: Joe Downing <[email protected]>
Reviewed-by: Xiaohan Wang <[email protected]>
Reviewed-by: Brandon Jones <[email protected]>
Reviewed-by: Greg Thompson <[email protected]>
Reviewed-by: François Doray <[email protected]>
Cr-Commit-Position: refs/heads/master@{#650522}
diff --git a/base/native_library.h b/base/native_library.h
index 04356d96..4a65ffe 100644
--- a/base/native_library.h
+++ b/base/native_library.h
@@ -11,6 +11,7 @@
#include <string>
#include "base/base_export.h"
+#include "base/files/file_path.h"
#include "base/strings/string_piece.h"
#include "build/build_config.h"
@@ -22,8 +23,6 @@
namespace base {
-class FilePath;
-
#if defined(OS_WIN)
using NativeLibrary = HMODULE;
#elif defined(OS_MACOSX)
@@ -83,6 +82,15 @@
BASE_EXPORT NativeLibrary LoadNativeLibrary(const FilePath& library_path,
NativeLibraryLoadError* error);
+#if defined(OS_WIN)
+// Loads a native library from the system directory using the appropriate flags.
+// The function first checks to see if the library is already loaded and will
+// get a handle if so. Blocking may occur if the library is not loaded and
+// LoadLibrary must be called.
+BASE_EXPORT NativeLibrary LoadSystemLibrary(FilePath::StringPieceType name,
+ NativeLibraryLoadError* error);
+#endif
+
// Loads a native library from disk. Release it with UnloadNativeLibrary when
// you're done. Returns NULL on failure.
// If |error| is not NULL, it may be filled in on load error.