Bug 1797301 - Add lib with failure handling r=nika

Differential Revision: https://phabricator.services.mozilla.com/D160685
This commit is contained in:
Alexandre Lissy 2022-11-08 18:41:56 +00:00
Родитель e6edd38fd7
Коммит 5b97fe29cd
5 изменённых файлов: 57 добавлений и 10 удалений

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

@ -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<uint64_t> sandboxingKind = geckoargs::sSandboxingKind.Get(aArgc, aArgv);
if (sandboxingKind.isNothing()) {

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

@ -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<UtilityProcessChild> mUtility = UtilityProcessChild::GetSingleton();

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

@ -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<nsICrashReporter> crashreporter =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter) {
crashreporter->SetEnabled(false);
}
}
static void DeregisterEmpty_Test() {
DisableCrashReporter();

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

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

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

@ -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<nsICrashReporter> 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