Bug 1766432 - Part 1: Use a custom definition for PROCESS_MITIGATION_DYNAMIC_CODE_POLICY in MinGW builds. r=bobowen

Differential Revision: https://phabricator.services.mozilla.com/D157903
This commit is contained in:
Yannis Juglaret 2022-09-29 15:29:14 +00:00
Родитель 8ac36b7f65
Коммит fe80a53950
4 изменённых файлов: 48 добавлений и 2 удалений

Просмотреть файл

@ -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 <winnt.h>
// 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__

Просмотреть файл

@ -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))) {

Просмотреть файл

@ -75,6 +75,7 @@ if CONFIG["OS_ARCH"] == "WINNT":
EXPORTS.mozilla += [
"DynamicallyLinkedFunctionPtr.h",
"ImportDir.h",
"MozProcessMitigationDynamicCodePolicy.h",
"NativeNt.h",
"WindowsDpiInitialization.h",
"WindowsEnumProcessModules.h",

Просмотреть файл

@ -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<decltype(&SetProcessMitigationPolicy)>