diff --git a/ipc/glue/UtilityProcessImpl.cpp b/ipc/glue/UtilityProcessImpl.cpp index 0baa0e07edaf..b2f1e1399082 100644 --- a/ipc/glue/UtilityProcessImpl.cpp +++ b/ipc/glue/UtilityProcessImpl.cpp @@ -22,6 +22,16 @@ namespace mozilla::ipc { UtilityProcessImpl::~UtilityProcessImpl() = default; +#if defined(XP_WIN) +/* static */ +void UtilityProcessImpl::LoadLibraryOrCrash(LPCWSTR aLib) { + HMODULE module = ::LoadLibraryW(aLib); + if (!module) { + MOZ_CRASH("Unable to preload module"); + } +} +#endif // defined(XP_WIN) + bool UtilityProcessImpl::Init(int aArgc, char* aArgv[]) { Maybe sandboxingKind = geckoargs::sSandboxingKind.Get(aArgc, aArgv); if (sandboxingKind.isNothing()) { diff --git a/ipc/glue/UtilityProcessImpl.h b/ipc/glue/UtilityProcessImpl.h index 3e0b73cbc507..9b42cd5f7430 100644 --- a/ipc/glue/UtilityProcessImpl.h +++ b/ipc/glue/UtilityProcessImpl.h @@ -26,6 +26,10 @@ class UtilityProcessImpl final : public ipc::ProcessChild { bool Init(int aArgc, char* aArgv[]) override; void CleanUp() override; +#if defined(XP_WIN) + static void LoadLibraryOrCrash(LPCWSTR aLib); +#endif // defined(XP_WIN) + private: RefPtr mUtility = UtilityProcessChild::GetSingleton(); diff --git a/ipc/glue/test/gtest/TestAsyncBlockers.cpp b/ipc/glue/test/gtest/TestAsyncBlockers.cpp index 7b9348abe52a..ad066f26c8b7 100644 --- a/ipc/glue/test/gtest/TestAsyncBlockers.cpp +++ b/ipc/glue/test/gtest/TestAsyncBlockers.cpp @@ -8,11 +8,10 @@ #include "mozilla/SpinEventLoopUntil.h" #include "mozilla/ipc/AsyncBlockers.h" -#include "nsServiceManagerUtils.h" #include "nsCOMPtr.h" #include "nsITimer.h" #include "nsINamed.h" -#include "nsICrashReporter.h" +#include "TestUtils.h" using namespace mozilla; using namespace mozilla::ipc; @@ -158,14 +157,6 @@ TEST_F(TestAsyncBlockers, Register_WaitUntilClear_0s) { #if defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED) && !defined(ANDROID) && \ !(defined(XP_DARWIN) && !defined(MOZ_DEBUG)) -static void DisableCrashReporter() { - nsCOMPtr crashreporter = - do_GetService("@mozilla.org/toolkit/crash-reporter;1"); - if (crashreporter) { - crashreporter->SetEnabled(false); - } -} - static void DeregisterEmpty_Test() { DisableCrashReporter(); diff --git a/ipc/glue/test/gtest/TestUtilityProcess.cpp b/ipc/glue/test/gtest/TestUtilityProcess.cpp index 72c8ca5bc388..f0c091c21e90 100644 --- a/ipc/glue/test/gtest/TestUtilityProcess.cpp +++ b/ipc/glue/test/gtest/TestUtilityProcess.cpp @@ -13,6 +13,11 @@ # include "nsServiceManagerUtils.h" #endif // defined(MOZ_WIDGET_ANDROID) || defined(XP_MACOSX) +#if defined(XP_WIN) +# include "TestUtils.h" +# include "mozilla/ipc/UtilityProcessImpl.h" +#endif // defined(XP_WIN) + #ifdef MOZ_WIDGET_ANDROID # define NS_APPSHELLSERVICE_CONTRACTID "@mozilla.org/widget/appshell/android;1" #endif // MOZ_WIDGET_ANDROID @@ -134,4 +139,17 @@ TEST_F(UtilityProcess, DestroyProcess) { WAIT_FOR_EVENTS; } +#if defined(XP_WIN) +static void LoadLibraryCrash_Test() { + DisableCrashReporter(); + // Just a uuidgen name to have something random + UtilityProcessImpl::LoadLibraryOrCrash( + L"2b49036e-6ba3-400c-a297-38fa1f6c5255.dll"); +} + +TEST_F(UtilityProcess, LoadLibraryCrash) { + ASSERT_DEATH_IF_SUPPORTED(LoadLibraryCrash_Test(), ""); +} +#endif // defined(XP_WIN) + #undef WAIT_FOR_EVENTS diff --git a/ipc/glue/test/gtest/TestUtils.h b/ipc/glue/test/gtest/TestUtils.h new file mode 100644 index 000000000000..52099b16bbc2 --- /dev/null +++ b/ipc/glue/test/gtest/TestUtils.h @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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 GTEST_UTILITY_TEST_UTILS_H +#define GTEST_UTILITY_TEST_UTILS_H + +#include "nsServiceManagerUtils.h" +#include "nsICrashReporter.h" + +#if defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED) && !defined(ANDROID) && \ + !(defined(XP_DARWIN) && !defined(MOZ_DEBUG)) +static void DisableCrashReporter() { + nsCOMPtr crashreporter = + do_GetService("@mozilla.org/toolkit/crash-reporter;1"); + if (crashreporter) { + crashreporter->SetEnabled(false); + } +} +#endif // defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED) && !defined(ANDROID) && + // !(defined(XP_DARWIN) && !defined(MOZ_DEBUG)) + +#endif // GTEST_UTILITY_TEST_UTILS_H