Source code

Revision control

Copy as Markdown

Other Tools

# HG changeset patch
# User Toshihito Kikuchi <tkikuchi@mozilla.com>
# Date 1589672273 25200
# Sat May 16 16:37:53 2020 -0700
# Node ID c14ef8304c36fdc2570b77b63b36114cff2d070d
# Parent 90b5f63770f52fab163adaed1d5812b2887b335a
Use GetModuleHandle/GetProcAddress in ApplyMitigationsToCurrentThread. r=bobowen
This patch removes the use of base::ScopedNativeLibrary from
sandbox::ApplyMitigationsToCurrentThread because to avoid
new dependencies.
diff --git a/security/sandbox/chromium/sandbox/win/src/process_mitigations.cc b/security/sandbox/chromium/sandbox/win/src/process_mitigations.cc
--- a/security/sandbox/chromium/sandbox/win/src/process_mitigations.cc
+++ b/security/sandbox/chromium/sandbox/win/src/process_mitigations.cc
@@ -5,18 +5,16 @@
#include "sandbox/win/src/process_mitigations.h"
#include <stddef.h>
#include <windows.h>
#include <wow64apiset.h>
#include <algorithm>
-#include "base/files/file_path.h"
-#include "base/scoped_native_library.h"
#include "base/win/windows_version.h"
#include "build/build_config.h"
#include "sandbox/win/src/nt_internals.h"
#include "sandbox/win/src/restricted_token_utils.h"
#include "sandbox/win/src/sandbox_rand.h"
#include "sandbox/win/src/win_utils.h"
namespace {
@@ -321,22 +319,19 @@ bool ApplyMitigationsToCurrentThread(Mit
return true;
// Enable dynamic code per-thread policies.
if (flags & MITIGATION_DYNAMIC_CODE_OPT_OUT_THIS_THREAD) {
DWORD thread_policy = THREAD_DYNAMIC_CODE_ALLOW;
// NOTE: SetThreadInformation API only exists on >= Win8. Dynamically
// get function handle.
- base::ScopedNativeLibrary dll(base::FilePath(L"kernel32.dll"));
- if (!dll.is_valid())
- return false;
SetThreadInformationFunction set_thread_info_function =
- reinterpret_cast<SetThreadInformationFunction>(
- dll.GetFunctionPointer("SetThreadInformation"));
+ reinterpret_cast<SetThreadInformationFunction>(::GetProcAddress(
+ ::GetModuleHandleA("kernel32.dll"), "SetThreadInformation"));
if (!set_thread_info_function)
return false;
// NOTE: Must use the pseudo-handle here, a thread HANDLE won't work.
if (!set_thread_info_function(::GetCurrentThread(), ThreadDynamicCodePolicy,
&thread_policy, sizeof(thread_policy))) {
return false;
}