Bug 1535704: Part 1 - Move IsWin32kLockedDown into mozglue; r=bobowen
authorAaron Klotz <aklotz@mozilla.com>
Mon, 22 Apr 2019 19:13:23 +0000
changeset 470389 74eb8e5f7143ed073a993df7a3abdce04b58f830
parent 470388 1362a0a6a7b27cd16c3e8caa0eb77ac198ddd5c2
child 470390 e3fc54ebcd15b682f7f9117c86a0d049fc28c6b0
push id35905
push userdvarga@mozilla.com
push dateTue, 23 Apr 2019 09:53:27 +0000
treeherdermozilla-central@831918f009f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbobowen
bugs1535704
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1535704: Part 1 - Move IsWin32kLockedDown into mozglue; r=bobowen Differential Revision: https://phabricator.services.mozilla.com/D27832
ipc/mscom/ProcessRuntime.cpp
ipc/mscom/ProcessRuntime.h
mozglue/misc/WindowsProcessMitigations.cpp
mozglue/misc/WindowsProcessMitigations.h
mozglue/misc/moz.build
--- a/ipc/mscom/ProcessRuntime.cpp
+++ b/ipc/mscom/ProcessRuntime.cpp
@@ -27,22 +27,16 @@
 #include <accctrl.h>
 #include <aclapi.h>
 #include <objbase.h>
 #include <objidl.h>
 
 // This API from oleaut32.dll is not declared in Windows SDK headers
 extern "C" void __cdecl SetOaNoCache(void);
 
-#if (_WIN32_WINNT < 0x0602)
-BOOL WINAPI GetProcessMitigationPolicy(
-    HANDLE hProcess, PROCESS_MITIGATION_POLICY MitigationPolicy, PVOID lpBuffer,
-    SIZE_T dwLength);
-#endif  // (_WIN32_WINNT < 0x0602)
-
 namespace mozilla {
 namespace mscom {
 
 ProcessRuntime::ProcessRuntime(GeckoProcessType aProcessType)
     : mInitResult(CO_E_NOTINITIALIZED),
       mIsParentProcess(aProcessType == GeckoProcessType_Default)
 #if defined(ACCESSIBILITY) && defined(MOZILLA_INTERNAL_API)
       ,
@@ -261,34 +255,10 @@ ProcessRuntime::InitializeSecurity() {
     return HRESULT_FROM_WIN32(::GetLastError());
   }
 
   return ::CoInitializeSecurity(
       &sd, -1, nullptr, nullptr, RPC_C_AUTHN_LEVEL_DEFAULT,
       RPC_C_IMP_LEVEL_IDENTIFY, nullptr, EOAC_NONE, nullptr);
 }
 
-#if defined(MOZILLA_INTERNAL_API)
-
-/* static */
-bool ProcessRuntime::IsWin32kLockedDown() {
-  static const DynamicallyLinkedFunctionPtr<decltype(
-      &::GetProcessMitigationPolicy)>
-      pGetProcessMitigationPolicy(L"kernel32.dll",
-                                  "GetProcessMitigationPolicy");
-  if (!pGetProcessMitigationPolicy) {
-    return false;
-  }
-
-  PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY polInfo;
-  if (!pGetProcessMitigationPolicy(::GetCurrentProcess(),
-                                   ProcessSystemCallDisablePolicy, &polInfo,
-                                   sizeof(polInfo))) {
-    return false;
-  }
-
-  return polInfo.DisallowWin32kSystemCalls;
-}
-
-#endif  // defined(MOZILLA_INTERNAL_API)
-
 }  // namespace mscom
 }  // namespace mozilla
--- a/ipc/mscom/ProcessRuntime.h
+++ b/ipc/mscom/ProcessRuntime.h
@@ -7,16 +7,17 @@
 #ifndef mozilla_mscom_ProcessRuntime_h
 #define mozilla_mscom_ProcessRuntime_h
 
 #include "mozilla/Attributes.h"
 #if defined(ACCESSIBILITY) && defined(MOZILLA_INTERNAL_API)
 #  include "mozilla/mscom/ActivationContext.h"
 #endif  // defined(ACCESSIBILITY) && defined(MOZILLA_INTERNAL_API)
 #include "mozilla/mscom/ApartmentRegion.h"
+#include "mozilla/WindowsProcessMitigations.h"
 #include "nsXULAppAPI.h"
 
 namespace mozilla {
 namespace mscom {
 
 class MOZ_NON_TEMPORARY_CLASS ProcessRuntime final {
  public:
 #if defined(MOZILLA_INTERNAL_API)
@@ -39,20 +40,16 @@ class MOZ_NON_TEMPORARY_CLASS ProcessRun
    *         otherwise contains the thread id of the calling thread.
    */
   static DWORD GetClientThreadId();
 
  private:
   void InitInsideApartment();
   HRESULT InitializeSecurity();
 
-#if defined(MOZILLA_INTERNAL_API)
-  static bool IsWin32kLockedDown();
-#endif  // defined(MOZILLA_INTERNAL_API)
-
   HRESULT mInitResult;
   bool mIsParentProcess;
 #if defined(ACCESSIBILITY) && defined(MOZILLA_INTERNAL_API)
   ActivationContextRegion mActCtxRgn;
 #endif  // defined(ACCESSIBILITY) && defined(MOZILLA_INTERNAL_API)
   ApartmentRegion mAptRegion;
 };
 
new file mode 100644
--- /dev/null
+++ b/mozglue/misc/WindowsProcessMitigations.cpp
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/DynamicallyLinkedFunctionPtr.h"
+#include "mozilla/WindowsProcessMitigations.h"
+
+#include <processthreadsapi.h>
+
+#if (_WIN32_WINNT < 0x0602)
+BOOL WINAPI GetProcessMitigationPolicy(
+    HANDLE hProcess, PROCESS_MITIGATION_POLICY MitigationPolicy, PVOID lpBuffer,
+    SIZE_T dwLength);
+#endif  // (_WIN32_WINNT < 0x0602)
+
+namespace mozilla {
+
+MFBT_API bool IsWin32kLockedDown() {
+  static const DynamicallyLinkedFunctionPtr<decltype(
+      &::GetProcessMitigationPolicy)>
+      pGetProcessMitigationPolicy(L"kernel32.dll",
+                                  "GetProcessMitigationPolicy");
+  if (!pGetProcessMitigationPolicy) {
+    return false;
+  }
+
+  PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY polInfo;
+  if (!pGetProcessMitigationPolicy(::GetCurrentProcess(),
+                                   ProcessSystemCallDisablePolicy, &polInfo,
+                                   sizeof(polInfo))) {
+    return false;
+  }
+
+  return polInfo.DisallowWin32kSystemCalls;
+}
+
+}  // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/mozglue/misc/WindowsProcessMitigations.h
@@ -0,0 +1,19 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_WindowsProcessMitigations_h
+#define mozilla_WindowsProcessMitigations_h
+
+#include "mozilla/Types.h"
+
+namespace mozilla {
+
+MFBT_API bool IsWin32kLockedDown();
+
+}  // namespace mozilla
+
+#endif  // mozilla_WindowsProcessMitigations_h
+
--- a/mozglue/misc/moz.build
+++ b/mozglue/misc/moz.build
@@ -43,20 +43,22 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     EXPORTS += [
         'nsWindowsDllInterceptor.h',
     ]
     EXPORTS.mozilla += [
         'DynamicallyLinkedFunctionPtr.h',
         'ImportDir.h',
         'NativeNt.h',
         'WindowsMapRemoteView.h',
+        'WindowsProcessMitigations.h',
     ]
     SOURCES += [
         'TimeStamp_windows.cpp',
         'WindowsMapRemoteView.cpp',
+        'WindowsProcessMitigations.cpp',
     ]
     OS_LIBS += ['dbghelp']
 elif CONFIG['HAVE_CLOCK_MONOTONIC']:
     SOURCES += [
         'TimeStamp_posix.cpp',
     ]
 elif CONFIG['OS_ARCH'] == 'Darwin':
     SOURCES += [