1 // Copyright 2024 The PDFium Authors 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 "core/fxcrt/win/win_util.h" 6 7 #include <windows.h> 8 #include <processthreadsapi.h> 9 10 namespace pdfium { 11 IsUser32AndGdi32Available()12bool IsUser32AndGdi32Available() { 13 static auto is_user32_and_gdi32_available = []() { 14 // If win32k syscalls aren't disabled, then user32 and gdi32 are available. 15 16 typedef decltype( 17 GetProcessMitigationPolicy)* GetProcessMitigationPolicyType; 18 GetProcessMitigationPolicyType get_process_mitigation_policy_func = 19 reinterpret_cast<GetProcessMitigationPolicyType>(GetProcAddress( 20 GetModuleHandle(L"kernel32.dll"), "GetProcessMitigationPolicy")); 21 22 if (!get_process_mitigation_policy_func) 23 return true; 24 25 PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {}; 26 if (get_process_mitigation_policy_func(GetCurrentProcess(), 27 ProcessSystemCallDisablePolicy, 28 &policy, sizeof(policy))) { 29 return policy.DisallowWin32kSystemCalls == 0; 30 } 31 32 return true; 33 }(); 34 return is_user32_and_gdi32_available; 35 } 36 37 } // namespace pdfium 38