diff --git a/mozglue/misc/MozProcessMitigationDynamicCodePolicy.h b/mozglue/misc/MozProcessMitigationDynamicCodePolicy.h new file mode 100644 index 000000000000..c0fd11706737 --- /dev/null +++ b/mozglue/misc/MozProcessMitigationDynamicCodePolicy.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=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/. */ + +// This file is temporarily needed for bug 1766432. We plan to remove it +// afterwards. Do not add new definitions here. + +#ifndef mozglue_misc_MozProcessMitigationDynamicCodePolicy_h__ +#define mozglue_misc_MozProcessMitigationDynamicCodePolicy_h__ + +#include + +// See bug 1766432 comment 4. We currently need to use our own definition +// for PROCESS_MITIGATION_DYNAMIC_CODE_POLICY in MinGW builds. +#if defined(__MINGW32__) || defined(__MINGW64__) + +typedef struct _MOZ_PROCESS_MITIGATION_DYNAMIC_CODE_POLICY { + __C89_NAMELESS union { + DWORD Flags; + __C89_NAMELESS struct { + DWORD ProhibitDynamicCode : 1; + DWORD AllowThreadOptOut : 1; + DWORD AllowRemoteDowngrade : 1; + DWORD ReservedFlags : 29; + }; + }; +} MOZ_PROCESS_MITIGATION_DYNAMIC_CODE_POLICY; + +#else + +using MOZ_PROCESS_MITIGATION_DYNAMIC_CODE_POLICY = + PROCESS_MITIGATION_DYNAMIC_CODE_POLICY; + +#endif // defined(__MINGW32__) || defined(__MINGW64__) + +#endif // mozglue_misc_MozProcessMitigationDynamicCodePolicy_h__ diff --git a/mozglue/misc/WindowsProcessMitigations.cpp b/mozglue/misc/WindowsProcessMitigations.cpp index 79bc72ca8b85..bee281439bef 100644 --- a/mozglue/misc/WindowsProcessMitigations.cpp +++ b/mozglue/misc/WindowsProcessMitigations.cpp @@ -11,6 +11,11 @@ #include "mozilla/Assertions.h" #include "mozilla/DynamicallyLinkedFunctionPtr.h" +// See bug 1766432 comment 4. In the future, we should keep this static assert +// when we remove MOZ_PROCESS_MITIGATION_DYNAMIC_CODE_POLICY. +#include "mozilla/MozProcessMitigationDynamicCodePolicy.h" +static_assert(sizeof(MOZ_PROCESS_MITIGATION_DYNAMIC_CODE_POLICY) == 4); + #if (_WIN32_WINNT < 0x0602) BOOL WINAPI GetProcessMitigationPolicy( HANDLE hProcess, PROCESS_MITIGATION_POLICY MitigationPolicy, PVOID lpBuffer, @@ -60,7 +65,7 @@ MFBT_API bool IsDynamicCodeDisabled() { return false; } - PROCESS_MITIGATION_DYNAMIC_CODE_POLICY polInfo; + MOZ_PROCESS_MITIGATION_DYNAMIC_CODE_POLICY polInfo; if (!pGetProcessMitigationPolicy(::GetCurrentProcess(), ProcessDynamicCodePolicy, &polInfo, sizeof(polInfo))) { diff --git a/mozglue/misc/moz.build b/mozglue/misc/moz.build index 6179461052c9..1b79cbaf6a01 100644 --- a/mozglue/misc/moz.build +++ b/mozglue/misc/moz.build @@ -75,6 +75,7 @@ if CONFIG["OS_ARCH"] == "WINNT": EXPORTS.mozilla += [ "DynamicallyLinkedFunctionPtr.h", "ImportDir.h", + "MozProcessMitigationDynamicCodePolicy.h", "NativeNt.h", "WindowsDpiInitialization.h", "WindowsEnumProcessModules.h", diff --git a/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp b/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp index 0a569760274f..fff01e36ce06 100644 --- a/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp +++ b/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp @@ -21,6 +21,8 @@ #include "nsWindowsDllInterceptor.h" #include "nsWindowsHelpers.h" +#include "mozilla/MozProcessMitigationDynamicCodePolicy.h" + NTSTATUS NTAPI NtFlushBuffersFile(HANDLE, PIO_STATUS_BLOCK); NTSTATUS NTAPI NtReadFile(HANDLE, HANDLE, PIO_APC_ROUTINE, PVOID, PIO_STATUS_BLOCK, PVOID, ULONG, PLARGE_INTEGER, @@ -850,7 +852,7 @@ bool TestDynamicCodePolicy() { return true; } - PROCESS_MITIGATION_DYNAMIC_CODE_POLICY policy = {}; + MOZ_PROCESS_MITIGATION_DYNAMIC_CODE_POLICY policy = {}; policy.ProhibitDynamicCode = true; mozilla::DynamicallyLinkedFunctionPtr