• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "third_party/base/win/win_util.h"
6 
7 #include <windows.h>
8 #include <processthreadsapi.h>
9 
10 namespace pdfium {
11 namespace base {
12 namespace win {
13 
IsUser32AndGdi32Available()14 bool IsUser32AndGdi32Available() {
15   static auto is_user32_and_gdi32_available = []() {
16     // If win32k syscalls aren't disabled, then user32 and gdi32 are available.
17 
18     typedef decltype(
19         GetProcessMitigationPolicy)* GetProcessMitigationPolicyType;
20     GetProcessMitigationPolicyType get_process_mitigation_policy_func =
21         reinterpret_cast<GetProcessMitigationPolicyType>(GetProcAddress(
22             GetModuleHandle(L"kernel32.dll"), "GetProcessMitigationPolicy"));
23 
24     if (!get_process_mitigation_policy_func)
25       return true;
26 
27     PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {};
28     if (get_process_mitigation_policy_func(GetCurrentProcess(),
29                                            ProcessSystemCallDisablePolicy,
30                                            &policy, sizeof(policy))) {
31       return policy.DisallowWin32kSystemCalls == 0;
32     }
33 
34     return true;
35   }();
36   return is_user32_and_gdi32_available;
37 }
38 
39 }  // namespace win
40 }  // namespace base
41 }  // namespace pdfium
42