2015-01-17 02:34:47 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-01-17 02:34:47 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/ProcessHangMonitor.h"
|
|
|
|
#include "mozilla/ProcessHangMonitorIPC.h"
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
#include "jsapi.h"
|
2019-04-30 23:56:17 +00:00
|
|
|
#include "xpcprivate.h"
|
2016-07-22 23:36:45 +00:00
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
#include "mozilla/Atomics.h"
|
2016-10-19 18:33:13 +00:00
|
|
|
#include "mozilla/BackgroundHangMonitor.h"
|
2019-12-05 04:44:32 +00:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2019-04-30 23:31:36 +00:00
|
|
|
#include "mozilla/dom/CancelContentJSOptionsBinding.h"
|
2021-03-11 17:41:19 +00:00
|
|
|
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
2015-01-17 02:34:47 +00:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
2015-01-17 02:34:47 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2016-07-22 23:36:45 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2019-04-09 22:39:01 +00:00
|
|
|
#include "mozilla/dom/BrowserChild.h"
|
2019-04-09 21:38:15 +00:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2020-11-23 16:06:42 +00:00
|
|
|
#include "mozilla/ipc/Endpoint.h"
|
2017-02-28 22:22:02 +00:00
|
|
|
#include "mozilla/ipc/TaskFactory.h"
|
2015-01-17 02:34:47 +00:00
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2019-08-02 11:59:06 +00:00
|
|
|
#include "mozilla/StaticPrefs_browser.h"
|
2019-11-12 21:30:11 +00:00
|
|
|
#include "mozilla/StaticPrefs_dom.h"
|
2016-08-23 04:09:32 +00:00
|
|
|
#include "mozilla/Unused.h"
|
2017-07-28 08:55:16 +00:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2017-10-10 10:43:09 +00:00
|
|
|
#include "nsExceptionHandler.h"
|
2018-03-22 02:43:17 +00:00
|
|
|
#include "nsFrameLoader.h"
|
2015-01-17 02:34:47 +00:00
|
|
|
#include "nsIHangReport.h"
|
2019-04-09 20:59:37 +00:00
|
|
|
#include "nsIRemoteTab.h"
|
2019-04-30 23:31:36 +00:00
|
|
|
#include "nsNetUtil.h"
|
2018-03-22 02:43:17 +00:00
|
|
|
#include "nsQueryObject.h"
|
2015-01-17 02:34:47 +00:00
|
|
|
#include "nsPluginHost.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "base/task.h"
|
|
|
|
#include "base/thread.h"
|
|
|
|
|
2015-01-22 23:53:49 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// For IsDebuggerPresent()
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2017-01-05 20:54:52 +00:00
|
|
|
using namespace mozilla::ipc;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic architecture:
|
|
|
|
*
|
|
|
|
* Each process has its own ProcessHangMonitor singleton. This singleton exists
|
|
|
|
* as long as there is at least one content process in the system. Each content
|
|
|
|
* process has a HangMonitorChild and the chrome process has one
|
|
|
|
* HangMonitorParent per process. Each process (including the chrome process)
|
|
|
|
* runs a hang monitoring thread. The PHangMonitor actors are bound to this
|
|
|
|
* thread so that they never block on the main thread.
|
|
|
|
*
|
|
|
|
* When the content process detects a hang, it posts a task to its hang thread,
|
|
|
|
* which sends an IPC message to the hang thread in the parent. The parent
|
|
|
|
* cancels any ongoing CPOW requests and then posts a runnable to the main
|
|
|
|
* thread that notifies Firefox frontend code of the hang. The frontend code is
|
|
|
|
* passed an nsIHangReport, which can be used to terminate the hang.
|
|
|
|
*
|
|
|
|
* If the user chooses to terminate a script, a task is posted to the chrome
|
|
|
|
* process's hang monitoring thread, which sends an IPC message to the hang
|
|
|
|
* thread in the content process. That thread sets a flag to indicate that JS
|
|
|
|
* execution should be terminated the next time it hits the interrupt
|
|
|
|
* callback. A similar scheme is used for debugging slow scripts. If a content
|
|
|
|
* process or plug-in needs to be terminated, the chrome process does so
|
|
|
|
* directly, without messaging the content process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/* Child process objects */
|
|
|
|
|
|
|
|
class HangMonitorChild : public PProcessHangMonitorChild,
|
2018-07-16 03:45:32 +00:00
|
|
|
public BackgroundHangAnnotator {
|
2015-01-17 02:34:47 +00:00
|
|
|
public:
|
|
|
|
explicit HangMonitorChild(ProcessHangMonitor* aMonitor);
|
2016-11-15 11:09:07 +00:00
|
|
|
~HangMonitorChild() override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2017-01-05 20:54:52 +00:00
|
|
|
void Bind(Endpoint<PProcessHangMonitorChild>&& aEndpoint);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
typedef ProcessHangMonitor::SlowScriptAction SlowScriptAction;
|
2019-04-09 22:39:01 +00:00
|
|
|
SlowScriptAction NotifySlowScript(nsIBrowserChild* aBrowserChild,
|
2017-08-18 03:17:51 +00:00
|
|
|
const char* aFileName,
|
2020-07-24 00:01:57 +00:00
|
|
|
const nsString& aAddonId,
|
|
|
|
const double aDuration);
|
2015-01-17 02:34:47 +00:00
|
|
|
void NotifySlowScriptAsync(TabId aTabId, const nsCString& aFileName,
|
2020-07-24 00:01:57 +00:00
|
|
|
const nsString& aAddonId, const double aDuration);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
bool IsDebuggerStartupComplete();
|
|
|
|
|
|
|
|
void ClearHang();
|
2016-04-01 23:54:25 +00:00
|
|
|
void ClearHangAsync();
|
2018-07-30 13:24:50 +00:00
|
|
|
void ClearPaintWhileInterruptingJS(const LayersObserverEpoch& aEpoch);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2018-05-15 06:45:00 +00:00
|
|
|
// MaybeStartPaintWhileInterruptingJS will notify the background hang monitor
|
|
|
|
// of activity if this is the first time calling it since
|
|
|
|
// ClearPaintWhileInterruptingJS. It should be callable from any thread, but
|
2018-03-18 18:44:19 +00:00
|
|
|
// you must be holding mMonitor if using it off the main thread, since it
|
2018-05-15 06:45:00 +00:00
|
|
|
// could race with ClearPaintWhileInterruptingJS.
|
|
|
|
void MaybeStartPaintWhileInterruptingJS();
|
2018-03-18 18:44:19 +00:00
|
|
|
|
2021-04-05 16:00:09 +00:00
|
|
|
mozilla::ipc::IPCResult RecvTerminateScript() override;
|
2016-11-15 03:26:00 +00:00
|
|
|
mozilla::ipc::IPCResult RecvBeginStartingDebugger() override;
|
|
|
|
mozilla::ipc::IPCResult RecvEndStartingDebugger() override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2018-05-15 06:45:00 +00:00
|
|
|
mozilla::ipc::IPCResult RecvPaintWhileInterruptingJS(
|
2019-09-26 22:11:17 +00:00
|
|
|
const TabId& aTabId, const LayersObserverEpoch& aEpoch) override;
|
2016-07-22 23:36:45 +00:00
|
|
|
|
2019-04-30 23:56:17 +00:00
|
|
|
mozilla::ipc::IPCResult RecvCancelContentJSExecutionIfRunning(
|
2019-04-30 23:31:36 +00:00
|
|
|
const TabId& aTabId, const nsIRemoteTab::NavigationType& aNavigationType,
|
|
|
|
const int32_t& aNavigationIndex,
|
2019-04-30 23:31:46 +00:00
|
|
|
const mozilla::Maybe<nsCString>& aNavigationURI,
|
|
|
|
const int32_t& aEpoch) override;
|
2019-04-30 23:56:17 +00:00
|
|
|
|
2016-11-15 11:09:07 +00:00
|
|
|
void ActorDestroy(ActorDestroyReason aWhy) override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2019-05-07 21:56:58 +00:00
|
|
|
bool InterruptCallback();
|
2015-01-17 02:34:47 +00:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
static HangMonitorChild* Get() { return sInstance; }
|
|
|
|
|
2017-05-20 03:36:10 +00:00
|
|
|
void Dispatch(already_AddRefed<nsIRunnable> aRunnable) {
|
2018-05-30 19:15:35 +00:00
|
|
|
mHangMonitor->Dispatch(std::move(aRunnable));
|
2017-05-20 03:36:10 +00:00
|
|
|
}
|
|
|
|
bool IsOnThread() { return mHangMonitor->IsOnThread(); }
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2018-07-16 03:45:32 +00:00
|
|
|
void AnnotateHang(BackgroundHangAnnotations& aAnnotations) override;
|
|
|
|
|
2020-04-23 23:18:24 +00:00
|
|
|
protected:
|
|
|
|
friend class mozilla::ProcessHangMonitor;
|
|
|
|
static Maybe<Monitor> sMonitor;
|
|
|
|
|
|
|
|
static Atomic<bool, SequentiallyConsistent> sInitializing;
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
private:
|
|
|
|
void ShutdownOnThread();
|
|
|
|
|
2020-02-27 17:39:15 +00:00
|
|
|
static Atomic<HangMonitorChild*, SequentiallyConsistent> sInstance;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
const RefPtr<ProcessHangMonitor> mHangMonitor;
|
2015-01-17 02:34:47 +00:00
|
|
|
Monitor mMonitor;
|
|
|
|
|
|
|
|
// Main thread-only.
|
|
|
|
bool mSentReport;
|
|
|
|
|
|
|
|
// These fields must be accessed with mMonitor held.
|
|
|
|
bool mTerminateScript;
|
|
|
|
bool mStartDebugger;
|
|
|
|
bool mFinishedStartingDebugger;
|
2018-05-15 06:45:00 +00:00
|
|
|
bool mPaintWhileInterruptingJS;
|
|
|
|
TabId mPaintWhileInterruptingJSTab;
|
2018-07-30 13:24:50 +00:00
|
|
|
MOZ_INIT_OUTSIDE_CTOR LayersObserverEpoch mPaintWhileInterruptingJSEpoch;
|
2019-04-30 23:31:36 +00:00
|
|
|
bool mCancelContentJS;
|
|
|
|
TabId mCancelContentJSTab;
|
|
|
|
nsIRemoteTab::NavigationType mCancelContentJSNavigationType;
|
|
|
|
int32_t mCancelContentJSNavigationIndex;
|
|
|
|
mozilla::Maybe<nsCString> mCancelContentJSNavigationURI;
|
2019-04-30 23:31:46 +00:00
|
|
|
int32_t mCancelContentJSEpoch;
|
2016-07-22 23:36:45 +00:00
|
|
|
JSContext* mContext;
|
2015-01-17 02:34:47 +00:00
|
|
|
bool mShutdownDone;
|
|
|
|
|
|
|
|
// This field is only accessed on the hang thread.
|
|
|
|
bool mIPCOpen;
|
2018-03-18 18:44:19 +00:00
|
|
|
|
|
|
|
// Allows us to ensure we NotifyActivity only once, allowing
|
|
|
|
// either thread to do so.
|
2018-07-16 03:45:32 +00:00
|
|
|
Atomic<bool> mPaintWhileInterruptingJSActive;
|
2015-01-17 02:34:47 +00:00
|
|
|
};
|
|
|
|
|
2020-04-23 23:18:24 +00:00
|
|
|
Maybe<Monitor> HangMonitorChild::sMonitor;
|
|
|
|
|
|
|
|
Atomic<bool, SequentiallyConsistent> HangMonitorChild::sInitializing;
|
|
|
|
|
2020-02-27 17:39:15 +00:00
|
|
|
Atomic<HangMonitorChild*, SequentiallyConsistent> HangMonitorChild::sInstance;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
/* Parent process objects */
|
|
|
|
|
|
|
|
class HangMonitorParent;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class HangMonitoredProcess final : public nsIHangReport {
|
2015-01-17 02:34:47 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
|
|
|
HangMonitoredProcess(HangMonitorParent* aActor, ContentParent* aContentParent)
|
|
|
|
: mActor(aActor), mContentParent(aContentParent) {}
|
|
|
|
|
2018-04-27 03:36:10 +00:00
|
|
|
NS_DECL_NSIHANGREPORT
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-06-18 20:10:46 +00:00
|
|
|
// Called when a content process shuts down.
|
2015-06-11 17:25:45 +00:00
|
|
|
void Clear() {
|
|
|
|
mContentParent = nullptr;
|
|
|
|
mActor = nullptr;
|
|
|
|
}
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-07-05 11:39:37 +00:00
|
|
|
/**
|
|
|
|
* Sets the information associated with this hang: this includes the ID of
|
|
|
|
* the plugin which caused the hang as well as the content PID. The ID of
|
|
|
|
* a minidump taken during the hang can also be provided.
|
2016-06-24 12:25:08 +00:00
|
|
|
*
|
|
|
|
* @param aHangData The hang information
|
2016-07-05 11:39:37 +00:00
|
|
|
* @param aDumpId The ID of a minidump taken when the hang occurred
|
2016-06-24 12:25:08 +00:00
|
|
|
*/
|
2016-07-05 11:39:37 +00:00
|
|
|
void SetHangData(const HangData& aHangData, const nsAString& aDumpId) {
|
|
|
|
mHangData = aHangData;
|
|
|
|
mDumpId = aDumpId;
|
2015-06-11 17:25:45 +00:00
|
|
|
}
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-04-01 23:54:25 +00:00
|
|
|
void ClearHang() {
|
|
|
|
mHangData = HangData();
|
2016-06-24 12:25:08 +00:00
|
|
|
mDumpId.Truncate();
|
2016-04-01 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
private:
|
2016-11-14 09:40:37 +00:00
|
|
|
~HangMonitoredProcess() = default;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
// Everything here is main thread-only.
|
|
|
|
HangMonitorParent* mActor;
|
|
|
|
ContentParent* mContentParent;
|
|
|
|
HangData mHangData;
|
2016-06-24 12:25:08 +00:00
|
|
|
nsAutoString mDumpId;
|
2015-01-17 02:34:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class HangMonitorParent : public PProcessHangMonitorParent,
|
2020-07-23 14:51:46 +00:00
|
|
|
public SupportsWeakPtr {
|
2015-01-17 02:34:47 +00:00
|
|
|
public:
|
|
|
|
explicit HangMonitorParent(ProcessHangMonitor* aMonitor);
|
2016-11-15 11:09:07 +00:00
|
|
|
~HangMonitorParent() override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2017-01-05 20:54:52 +00:00
|
|
|
void Bind(Endpoint<PProcessHangMonitorParent>&& aEndpoint);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-11-15 03:26:00 +00:00
|
|
|
mozilla::ipc::IPCResult RecvHangEvidence(const HangData& aHangData) override;
|
|
|
|
mozilla::ipc::IPCResult RecvClearHang() override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-11-15 11:09:07 +00:00
|
|
|
void ActorDestroy(ActorDestroyReason aWhy) override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
void SetProcess(HangMonitoredProcess* aProcess) { mProcess = aProcess; }
|
|
|
|
|
|
|
|
void Shutdown();
|
|
|
|
|
2019-04-09 21:38:15 +00:00
|
|
|
void PaintWhileInterruptingJS(dom::BrowserParent* aBrowserParent,
|
2018-07-30 13:24:50 +00:00
|
|
|
const LayersObserverEpoch& aEpoch);
|
2019-04-30 23:31:36 +00:00
|
|
|
void CancelContentJSExecutionIfRunning(
|
|
|
|
dom::BrowserParent* aBrowserParent,
|
|
|
|
nsIRemoteTab::NavigationType aNavigationType,
|
|
|
|
const dom::CancelContentJSOptions& aCancelContentJSOptions);
|
2016-07-22 23:36:45 +00:00
|
|
|
|
2021-04-05 16:00:09 +00:00
|
|
|
void TerminateScript();
|
2015-01-17 02:34:47 +00:00
|
|
|
void BeginStartingDebugger();
|
|
|
|
void EndStartingDebugger();
|
2016-07-05 11:39:37 +00:00
|
|
|
|
2017-05-20 03:36:10 +00:00
|
|
|
void Dispatch(already_AddRefed<nsIRunnable> aRunnable) {
|
2018-05-30 19:15:35 +00:00
|
|
|
mHangMonitor->Dispatch(std::move(aRunnable));
|
2017-05-20 03:36:10 +00:00
|
|
|
}
|
|
|
|
bool IsOnThread() { return mHangMonitor->IsOnThread(); }
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-07-05 11:39:37 +00:00
|
|
|
private:
|
2017-03-06 20:55:36 +00:00
|
|
|
void SendHangNotification(const HangData& aHangData,
|
2021-04-06 19:28:17 +00:00
|
|
|
const nsString& aBrowserDumpId);
|
2017-03-06 20:55:36 +00:00
|
|
|
|
|
|
|
void ClearHangNotification();
|
|
|
|
|
2019-09-26 22:11:17 +00:00
|
|
|
void PaintWhileInterruptingJSOnThread(TabId aTabId,
|
2018-07-30 13:24:50 +00:00
|
|
|
const LayersObserverEpoch& aEpoch);
|
2019-04-30 23:31:36 +00:00
|
|
|
void CancelContentJSExecutionIfRunningOnThread(
|
|
|
|
TabId aTabId, nsIRemoteTab::NavigationType aNavigationType,
|
2019-04-30 23:31:46 +00:00
|
|
|
int32_t aNavigationIndex, nsIURI* aNavigationURI, int32_t aEpoch);
|
2016-07-22 23:36:45 +00:00
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
void ShutdownOnThread();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
const RefPtr<ProcessHangMonitor> mHangMonitor;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
// This field is only accessed on the hang thread.
|
|
|
|
bool mIPCOpen;
|
|
|
|
|
|
|
|
Monitor mMonitor;
|
|
|
|
|
|
|
|
// Must be accessed with mMonitor held.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<HangMonitoredProcess> mProcess;
|
2015-01-17 02:34:47 +00:00
|
|
|
bool mShutdownDone;
|
2015-06-11 17:25:45 +00:00
|
|
|
// Map from plugin ID to crash dump ID. Protected by
|
|
|
|
// mBrowserCrashDumpHashLock.
|
2021-03-10 10:47:47 +00:00
|
|
|
nsTHashMap<nsUint32HashKey, nsString> mBrowserCrashDumpIds;
|
2015-06-11 17:25:45 +00:00
|
|
|
Mutex mBrowserCrashDumpHashLock;
|
2017-02-28 22:22:02 +00:00
|
|
|
mozilla::ipc::TaskFactory<HangMonitorParent> mMainThreadTaskFactory;
|
2015-01-17 02:34:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/* HangMonitorChild implementation */
|
|
|
|
|
|
|
|
HangMonitorChild::HangMonitorChild(ProcessHangMonitor* aMonitor)
|
2018-04-13 13:01:28 +00:00
|
|
|
: mHangMonitor(aMonitor),
|
2020-02-27 17:39:15 +00:00
|
|
|
mMonitor("HangMonitorChild lock"),
|
2018-04-13 13:01:28 +00:00
|
|
|
mSentReport(false),
|
|
|
|
mTerminateScript(false),
|
|
|
|
mStartDebugger(false),
|
|
|
|
mFinishedStartingDebugger(false),
|
2018-05-15 06:45:00 +00:00
|
|
|
mPaintWhileInterruptingJS(false),
|
2019-04-30 23:31:36 +00:00
|
|
|
mCancelContentJS(false),
|
|
|
|
mCancelContentJSNavigationType(nsIRemoteTab::NAVIGATE_BACK),
|
|
|
|
mCancelContentJSNavigationIndex(0),
|
2019-04-30 23:31:46 +00:00
|
|
|
mCancelContentJSEpoch(0),
|
2018-04-13 13:01:28 +00:00
|
|
|
mShutdownDone(false),
|
2018-07-16 03:45:32 +00:00
|
|
|
mIPCOpen(true),
|
|
|
|
mPaintWhileInterruptingJSActive(false) {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2020-04-23 23:18:24 +00:00
|
|
|
MOZ_ASSERT(!sInstance);
|
2016-07-22 23:36:45 +00:00
|
|
|
mContext = danger::GetJSContext();
|
2018-07-16 03:45:32 +00:00
|
|
|
|
|
|
|
BackgroundHangMonitor::RegisterAnnotator(*this);
|
2020-04-23 23:18:24 +00:00
|
|
|
|
|
|
|
MOZ_ASSERT(!sMonitor.isSome());
|
|
|
|
sMonitor.emplace("HangMonitorChild::sMonitor");
|
|
|
|
MonitorAutoLock mal(*sMonitor);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!sInitializing);
|
|
|
|
sInitializing = true;
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HangMonitorChild::~HangMonitorChild() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(sInstance == this);
|
|
|
|
sInstance = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-05-07 21:56:58 +00:00
|
|
|
bool HangMonitorChild::InterruptCallback() {
|
2016-07-22 23:36:45 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2019-07-31 10:29:32 +00:00
|
|
|
// Don't start painting if we're not in a good place to run script. We run
|
|
|
|
// chrome script during layout and such, and it wouldn't be good to interrupt
|
|
|
|
// painting code from there.
|
|
|
|
if (!nsContentUtils::IsSafeToRunScript()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-15 06:45:00 +00:00
|
|
|
bool paintWhileInterruptingJS;
|
|
|
|
TabId paintWhileInterruptingJSTab;
|
2018-07-30 13:24:50 +00:00
|
|
|
LayersObserverEpoch paintWhileInterruptingJSEpoch;
|
2016-07-22 23:36:45 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2018-05-15 06:45:00 +00:00
|
|
|
paintWhileInterruptingJS = mPaintWhileInterruptingJS;
|
|
|
|
paintWhileInterruptingJSTab = mPaintWhileInterruptingJSTab;
|
|
|
|
paintWhileInterruptingJSEpoch = mPaintWhileInterruptingJSEpoch;
|
2016-07-22 23:36:45 +00:00
|
|
|
|
2018-05-15 06:45:00 +00:00
|
|
|
mPaintWhileInterruptingJS = false;
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 17:36:17 +00:00
|
|
|
if (paintWhileInterruptingJS) {
|
2019-04-09 22:39:01 +00:00
|
|
|
RefPtr<BrowserChild> browserChild =
|
|
|
|
BrowserChild::FindBrowserChild(paintWhileInterruptingJSTab);
|
|
|
|
if (browserChild) {
|
2017-01-12 00:04:40 +00:00
|
|
|
js::AutoAssertNoContentJS nojs(mContext);
|
2019-09-26 22:11:17 +00:00
|
|
|
browserChild->PaintWhileInterruptingJS(paintWhileInterruptingJSEpoch);
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-30 23:31:36 +00:00
|
|
|
|
2019-06-04 16:19:27 +00:00
|
|
|
// Only handle the interrupt for cancelling content JS if we have a
|
|
|
|
// non-privileged script (i.e. not part of Gecko or an add-on).
|
2019-05-07 21:56:58 +00:00
|
|
|
JS::RootedObject global(mContext, JS::CurrentGlobalOrNull(mContext));
|
2019-06-04 16:19:27 +00:00
|
|
|
nsIPrincipal* principal = xpc::GetObjectPrincipal(global);
|
|
|
|
if (principal && (principal->IsSystemPrincipal() ||
|
|
|
|
principal->GetIsAddonOrExpandedAddonPrincipal())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win = xpc::WindowOrNull(global);
|
2019-05-07 21:56:58 +00:00
|
|
|
if (!win) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cancelContentJS;
|
|
|
|
TabId cancelContentJSTab;
|
|
|
|
nsIRemoteTab::NavigationType cancelContentJSNavigationType;
|
|
|
|
int32_t cancelContentJSNavigationIndex;
|
|
|
|
mozilla::Maybe<nsCString> cancelContentJSNavigationURI;
|
|
|
|
int32_t cancelContentJSEpoch;
|
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
cancelContentJS = mCancelContentJS;
|
|
|
|
cancelContentJSTab = mCancelContentJSTab;
|
|
|
|
cancelContentJSNavigationType = mCancelContentJSNavigationType;
|
|
|
|
cancelContentJSNavigationIndex = mCancelContentJSNavigationIndex;
|
|
|
|
cancelContentJSNavigationURI = std::move(mCancelContentJSNavigationURI);
|
|
|
|
cancelContentJSEpoch = mCancelContentJSEpoch;
|
|
|
|
|
|
|
|
mCancelContentJS = false;
|
|
|
|
}
|
|
|
|
|
2019-04-30 23:31:36 +00:00
|
|
|
if (cancelContentJS) {
|
2019-06-04 16:19:27 +00:00
|
|
|
js::AutoAssertNoContentJS nojs(mContext);
|
2019-06-06 20:02:38 +00:00
|
|
|
|
|
|
|
RefPtr<BrowserChild> browserChild =
|
|
|
|
BrowserChild::FindBrowserChild(cancelContentJSTab);
|
|
|
|
RefPtr<BrowserChild> browserChildFromWin = BrowserChild::GetFrom(win);
|
|
|
|
if (!browserChild || !browserChildFromWin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabId tabIdFromWin = browserChildFromWin->GetTabId();
|
|
|
|
if (tabIdFromWin != cancelContentJSTab) {
|
2019-06-04 16:19:27 +00:00
|
|
|
// The currently-executing content JS doesn't belong to the tab that
|
|
|
|
// requested cancellation of JS. Just return and let the JS continue.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-06 20:02:38 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
if (cancelContentJSNavigationURI) {
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), cancelContentJSNavigationURI.value());
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return true;
|
2019-04-30 23:31:36 +00:00
|
|
|
}
|
2019-06-06 20:02:38 +00:00
|
|
|
}
|
2019-04-30 23:31:36 +00:00
|
|
|
|
2019-06-06 20:02:38 +00:00
|
|
|
bool canCancel;
|
|
|
|
rv = browserChild->CanCancelContentJS(cancelContentJSNavigationType,
|
|
|
|
cancelContentJSNavigationIndex, uri,
|
|
|
|
cancelContentJSEpoch, &canCancel);
|
|
|
|
if (NS_SUCCEEDED(rv) && canCancel) {
|
|
|
|
// Don't add this page to the BF cache, since we're cancelling its JS.
|
|
|
|
if (Document* doc = win->GetExtantDoc()) {
|
2021-03-26 19:13:22 +00:00
|
|
|
doc->DisallowBFCaching();
|
2019-04-30 23:31:36 +00:00
|
|
|
}
|
2019-06-06 20:02:38 +00:00
|
|
|
|
|
|
|
return false;
|
2019-04-30 23:31:36 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-07 21:56:58 +00:00
|
|
|
|
|
|
|
return true;
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 03:45:32 +00:00
|
|
|
void HangMonitorChild::AnnotateHang(BackgroundHangAnnotations& aAnnotations) {
|
2018-09-18 17:06:30 +00:00
|
|
|
if (mPaintWhileInterruptingJSActive) {
|
2018-07-16 03:45:32 +00:00
|
|
|
aAnnotations.AddAnnotation(u"PaintWhileInterruptingJS"_ns, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
void HangMonitorChild::Shutdown() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2019-01-07 17:02:59 +00:00
|
|
|
BackgroundHangMonitor::UnregisterAnnotator(*this);
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
while (!mShutdownDone) {
|
|
|
|
mMonitor.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorChild::ShutdownOnThread() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mShutdownDone = true;
|
|
|
|
mMonitor.Notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorChild::ActorDestroy(ActorDestroyReason aWhy) {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
mIPCOpen = false;
|
|
|
|
|
|
|
|
// We use a task here to ensure that IPDL is finished with this
|
|
|
|
// HangMonitorChild before it gets deleted on the main thread.
|
2017-06-12 19:34:10 +00:00
|
|
|
Dispatch(NewNonOwningRunnableMethod("HangMonitorChild::ShutdownOnThread",
|
|
|
|
this,
|
|
|
|
&HangMonitorChild::ShutdownOnThread));
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
2021-04-05 16:00:09 +00:00
|
|
|
mozilla::ipc::IPCResult HangMonitorChild::RecvTerminateScript() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2021-04-05 16:00:09 +00:00
|
|
|
mTerminateScript = true;
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult HangMonitorChild::RecvBeginStartingDebugger() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mStartDebugger = true;
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult HangMonitorChild::RecvEndStartingDebugger() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mFinishedStartingDebugger = true;
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 06:45:00 +00:00
|
|
|
mozilla::ipc::IPCResult HangMonitorChild::RecvPaintWhileInterruptingJS(
|
2019-09-26 22:11:17 +00:00
|
|
|
const TabId& aTabId, const LayersObserverEpoch& aEpoch) {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2016-07-22 23:36:45 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2018-05-15 06:45:00 +00:00
|
|
|
MaybeStartPaintWhileInterruptingJS();
|
|
|
|
mPaintWhileInterruptingJS = true;
|
|
|
|
mPaintWhileInterruptingJSTab = aTabId;
|
2018-07-30 13:24:50 +00:00
|
|
|
mPaintWhileInterruptingJSEpoch = aEpoch;
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_RequestInterruptCallback(mContext);
|
|
|
|
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 06:45:00 +00:00
|
|
|
void HangMonitorChild::MaybeStartPaintWhileInterruptingJS() {
|
2018-07-16 03:45:32 +00:00
|
|
|
mPaintWhileInterruptingJSActive = true;
|
2018-03-18 18:44:19 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 13:24:50 +00:00
|
|
|
void HangMonitorChild::ClearPaintWhileInterruptingJS(
|
|
|
|
const LayersObserverEpoch& aEpoch) {
|
2016-10-21 18:56:46 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsContentProcess());
|
2018-07-16 03:45:32 +00:00
|
|
|
mPaintWhileInterruptingJSActive = false;
|
2016-10-21 18:56:46 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 23:56:17 +00:00
|
|
|
mozilla::ipc::IPCResult HangMonitorChild::RecvCancelContentJSExecutionIfRunning(
|
2019-04-30 23:31:36 +00:00
|
|
|
const TabId& aTabId, const nsIRemoteTab::NavigationType& aNavigationType,
|
|
|
|
const int32_t& aNavigationIndex,
|
2019-04-30 23:31:46 +00:00
|
|
|
const mozilla::Maybe<nsCString>& aNavigationURI, const int32_t& aEpoch) {
|
2019-04-30 23:56:17 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
|
|
|
|
2019-04-30 23:31:36 +00:00
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mCancelContentJS = true;
|
|
|
|
mCancelContentJSTab = aTabId;
|
|
|
|
mCancelContentJSNavigationType = aNavigationType;
|
|
|
|
mCancelContentJSNavigationIndex = aNavigationIndex;
|
|
|
|
mCancelContentJSNavigationURI = aNavigationURI;
|
2019-04-30 23:31:46 +00:00
|
|
|
mCancelContentJSEpoch = aEpoch;
|
2019-04-30 23:31:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 23:56:17 +00:00
|
|
|
JS_RequestInterruptCallback(mContext);
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-01-05 20:54:52 +00:00
|
|
|
void HangMonitorChild::Bind(Endpoint<PProcessHangMonitorChild>&& aEndpoint) {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2020-04-23 23:18:24 +00:00
|
|
|
MonitorAutoLock mal(*sMonitor);
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_ASSERT(!sInstance);
|
|
|
|
sInstance = this;
|
|
|
|
|
2017-01-05 20:54:52 +00:00
|
|
|
DebugOnly<bool> ok = aEndpoint.Bind(this);
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_ASSERT(ok);
|
2020-04-23 23:18:24 +00:00
|
|
|
|
|
|
|
sInitializing = false;
|
|
|
|
mal.Notify();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorChild::NotifySlowScriptAsync(TabId aTabId,
|
2017-08-18 03:17:51 +00:00
|
|
|
const nsCString& aFileName,
|
2020-07-24 00:01:57 +00:00
|
|
|
const nsString& aAddonId,
|
|
|
|
const double aDuration) {
|
2015-01-17 02:34:47 +00:00
|
|
|
if (mIPCOpen) {
|
2020-07-24 00:01:57 +00:00
|
|
|
Unused << SendHangEvidence(
|
|
|
|
SlowScriptData(aTabId, aFileName, aAddonId, aDuration));
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HangMonitorChild::SlowScriptAction HangMonitorChild::NotifySlowScript(
|
2019-04-09 22:39:01 +00:00
|
|
|
nsIBrowserChild* aBrowserChild, const char* aFileName,
|
2020-07-24 00:01:57 +00:00
|
|
|
const nsString& aAddonId, const double aDuration) {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
mSentReport = true;
|
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
if (mTerminateScript) {
|
|
|
|
mTerminateScript = false;
|
|
|
|
return SlowScriptAction::Terminate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mStartDebugger) {
|
|
|
|
mStartDebugger = false;
|
|
|
|
return SlowScriptAction::StartDebugger;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TabId id;
|
2019-04-09 22:39:01 +00:00
|
|
|
if (aBrowserChild) {
|
|
|
|
RefPtr<BrowserChild> browserChild =
|
|
|
|
static_cast<BrowserChild*>(aBrowserChild);
|
|
|
|
id = browserChild->GetTabId();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
nsAutoCString filename(aFileName);
|
|
|
|
|
2020-07-24 00:01:57 +00:00
|
|
|
Dispatch(NewNonOwningRunnableMethod<TabId, nsCString, nsString, double>(
|
2017-06-12 19:34:10 +00:00
|
|
|
"HangMonitorChild::NotifySlowScriptAsync", this,
|
2020-07-24 00:01:57 +00:00
|
|
|
&HangMonitorChild::NotifySlowScriptAsync, id, filename, aAddonId,
|
|
|
|
aDuration));
|
2015-01-17 02:34:47 +00:00
|
|
|
return SlowScriptAction::Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HangMonitorChild::IsDebuggerStartupComplete() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
if (mFinishedStartingDebugger) {
|
|
|
|
mFinishedStartingDebugger = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorChild::ClearHang() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mSentReport) {
|
2016-04-01 23:54:25 +00:00
|
|
|
// bounce to background thread
|
2017-06-12 19:34:10 +00:00
|
|
|
Dispatch(NewNonOwningRunnableMethod("HangMonitorChild::ClearHangAsync",
|
|
|
|
this,
|
|
|
|
&HangMonitorChild::ClearHangAsync));
|
2016-04-01 23:54:25 +00:00
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mSentReport = false;
|
|
|
|
mTerminateScript = false;
|
|
|
|
mStartDebugger = false;
|
|
|
|
mFinishedStartingDebugger = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 23:54:25 +00:00
|
|
|
void HangMonitorChild::ClearHangAsync() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2016-04-01 23:54:25 +00:00
|
|
|
|
|
|
|
// bounce back to parent on background thread
|
|
|
|
if (mIPCOpen) {
|
|
|
|
Unused << SendClearHang();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
/* HangMonitorParent implementation */
|
|
|
|
|
|
|
|
HangMonitorParent::HangMonitorParent(ProcessHangMonitor* aMonitor)
|
|
|
|
: mHangMonitor(aMonitor),
|
|
|
|
mIPCOpen(true),
|
|
|
|
mMonitor("HangMonitorParent lock"),
|
2015-06-11 17:25:45 +00:00
|
|
|
mShutdownDone(false),
|
2017-02-28 22:22:02 +00:00
|
|
|
mBrowserCrashDumpHashLock("mBrowserCrashDumpIds lock"),
|
|
|
|
mMainThreadTaskFactory(this) {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
HangMonitorParent::~HangMonitorParent() {
|
2015-06-18 20:10:46 +00:00
|
|
|
MutexAutoLock lock(mBrowserCrashDumpHashLock);
|
2015-11-02 04:18:41 +00:00
|
|
|
|
2021-03-24 17:56:49 +00:00
|
|
|
for (const auto& crashId : mBrowserCrashDumpIds.Values()) {
|
2015-11-02 04:18:41 +00:00
|
|
|
if (!crashId.IsEmpty()) {
|
|
|
|
CrashReporter::DeleteMinidumpFilesForID(crashId);
|
|
|
|
}
|
|
|
|
}
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::Shutdown() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
if (mProcess) {
|
|
|
|
mProcess->Clear();
|
|
|
|
mProcess = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-06-12 19:34:10 +00:00
|
|
|
Dispatch(NewNonOwningRunnableMethod("HangMonitorParent::ShutdownOnThread",
|
|
|
|
this,
|
2017-05-20 03:36:10 +00:00
|
|
|
&HangMonitorParent::ShutdownOnThread));
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
while (!mShutdownDone) {
|
|
|
|
mMonitor.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::ShutdownOnThread() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
// mIPCOpen is only written from this thread, so need need to take the lock
|
|
|
|
// here. We'd be shooting ourselves in the foot, because ActorDestroy takes
|
|
|
|
// it.
|
|
|
|
if (mIPCOpen) {
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mShutdownDone = true;
|
|
|
|
mMonitor.Notify();
|
|
|
|
}
|
|
|
|
|
2018-05-15 06:45:00 +00:00
|
|
|
void HangMonitorParent::PaintWhileInterruptingJS(
|
2019-09-26 22:11:17 +00:00
|
|
|
dom::BrowserParent* aTab, const LayersObserverEpoch& aEpoch) {
|
2016-07-22 23:36:45 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2019-08-02 11:59:06 +00:00
|
|
|
if (StaticPrefs::browser_tabs_remote_force_paint()) {
|
2017-03-01 20:36:51 +00:00
|
|
|
TabId id = aTab->GetTabId();
|
2019-09-26 22:11:17 +00:00
|
|
|
Dispatch(NewNonOwningRunnableMethod<TabId, LayersObserverEpoch>(
|
2018-05-15 06:45:00 +00:00
|
|
|
"HangMonitorParent::PaintWhileInterruptingJSOnThread", this,
|
2019-09-26 22:11:17 +00:00
|
|
|
&HangMonitorParent::PaintWhileInterruptingJSOnThread, id, aEpoch));
|
2017-03-01 20:36:51 +00:00
|
|
|
}
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 06:45:00 +00:00
|
|
|
void HangMonitorParent::PaintWhileInterruptingJSOnThread(
|
2019-09-26 22:11:17 +00:00
|
|
|
TabId aTabId, const LayersObserverEpoch& aEpoch) {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2016-07-22 23:36:45 +00:00
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2019-09-26 22:11:17 +00:00
|
|
|
Unused << SendPaintWhileInterruptingJS(aTabId, aEpoch);
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 23:56:17 +00:00
|
|
|
void HangMonitorParent::CancelContentJSExecutionIfRunning(
|
2019-04-30 23:31:36 +00:00
|
|
|
dom::BrowserParent* aBrowserParent,
|
|
|
|
nsIRemoteTab::NavigationType aNavigationType,
|
|
|
|
const dom::CancelContentJSOptions& aCancelContentJSOptions) {
|
2019-04-30 23:56:17 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2020-09-21 10:05:21 +00:00
|
|
|
if (!aBrowserParent->CanCancelContentJS(aNavigationType,
|
|
|
|
aCancelContentJSOptions.mIndex,
|
|
|
|
aCancelContentJSOptions.mUri)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-30 23:56:17 +00:00
|
|
|
TabId id = aBrowserParent->GetTabId();
|
2019-04-30 23:31:36 +00:00
|
|
|
Dispatch(NewNonOwningRunnableMethod<TabId, nsIRemoteTab::NavigationType,
|
2019-04-30 23:31:46 +00:00
|
|
|
int32_t, nsIURI*, int32_t>(
|
2019-04-30 23:56:17 +00:00
|
|
|
"HangMonitorParent::CancelContentJSExecutionIfRunningOnThread", this,
|
2019-04-30 23:31:36 +00:00
|
|
|
&HangMonitorParent::CancelContentJSExecutionIfRunningOnThread, id,
|
|
|
|
aNavigationType, aCancelContentJSOptions.mIndex,
|
2019-04-30 23:31:46 +00:00
|
|
|
aCancelContentJSOptions.mUri, aCancelContentJSOptions.mEpoch));
|
2019-04-30 23:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::CancelContentJSExecutionIfRunningOnThread(
|
2019-04-30 23:31:36 +00:00
|
|
|
TabId aTabId, nsIRemoteTab::NavigationType aNavigationType,
|
2019-04-30 23:31:46 +00:00
|
|
|
int32_t aNavigationIndex, nsIURI* aNavigationURI, int32_t aEpoch) {
|
2019-04-30 23:56:17 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
|
|
|
|
2019-04-30 23:31:36 +00:00
|
|
|
mozilla::Maybe<nsCString> spec;
|
|
|
|
if (aNavigationURI) {
|
|
|
|
nsAutoCString tmp;
|
|
|
|
nsresult rv = aNavigationURI->GetSpec(tmp);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
spec.emplace(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 23:56:17 +00:00
|
|
|
if (mIPCOpen) {
|
2019-04-30 23:31:46 +00:00
|
|
|
Unused << SendCancelContentJSExecutionIfRunning(
|
|
|
|
aTabId, aNavigationType, aNavigationIndex, spec, aEpoch);
|
2019-04-30 23:56:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
void HangMonitorParent::ActorDestroy(ActorDestroyReason aWhy) {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
mIPCOpen = false;
|
|
|
|
}
|
|
|
|
|
2017-01-05 20:54:52 +00:00
|
|
|
void HangMonitorParent::Bind(Endpoint<PProcessHangMonitorParent>&& aEndpoint) {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2017-01-05 20:54:52 +00:00
|
|
|
DebugOnly<bool> ok = aEndpoint.Bind(this);
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_ASSERT(ok);
|
|
|
|
}
|
|
|
|
|
2017-03-06 20:55:36 +00:00
|
|
|
void HangMonitorParent::SendHangNotification(const HangData& aHangData,
|
2021-04-06 19:28:17 +00:00
|
|
|
const nsString& aBrowserDumpId) {
|
2017-03-06 20:55:36 +00:00
|
|
|
// chrome process, main thread
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2018-09-17 20:51:45 +00:00
|
|
|
nsString dumpId;
|
2021-04-06 19:28:12 +00:00
|
|
|
|
|
|
|
// We already have a full minidump; go ahead and use it.
|
|
|
|
dumpId = aBrowserDumpId;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2018-09-17 20:51:45 +00:00
|
|
|
mProcess->SetHangData(aHangData, dumpId);
|
2017-03-06 20:55:36 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
2018-09-17 20:51:45 +00:00
|
|
|
observerService->NotifyObservers(mProcess, "process-hang-report", nullptr);
|
2017-03-06 20:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::ClearHangNotification() {
|
|
|
|
// chrome process, main thread
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
observerService->NotifyObservers(mProcess, "clear-hang-report", nullptr);
|
2020-07-24 00:01:57 +00:00
|
|
|
|
|
|
|
mProcess->ClearHang();
|
2017-03-06 20:55:36 +00:00
|
|
|
}
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
mozilla::ipc::IPCResult HangMonitorParent::RecvHangEvidence(
|
|
|
|
const HangData& aHangData) {
|
2015-06-11 17:25:45 +00:00
|
|
|
// chrome process, background thread
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2019-11-12 21:30:11 +00:00
|
|
|
if (!StaticPrefs::dom_ipc_reportProcessHangs()) {
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 23:53:49 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Don't report hangs if we're debugging the process. You can comment this
|
|
|
|
// line out for testing purposes.
|
|
|
|
if (IsDebuggerPresent()) {
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2015-01-22 23:53:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-11 17:25:45 +00:00
|
|
|
// Before we wake up the browser main thread we want to take a
|
|
|
|
// browser minidump.
|
|
|
|
nsAutoString crashId;
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
mHangMonitor->InitiateCPOWTimeout();
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
2017-03-06 20:55:36 +00:00
|
|
|
NS_DispatchToMainThread(mMainThreadTaskFactory.NewRunnableMethod(
|
2021-04-06 19:28:17 +00:00
|
|
|
&HangMonitorParent::SendHangNotification, aHangData, crashId));
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
2016-04-01 23:54:25 +00:00
|
|
|
mozilla::ipc::IPCResult HangMonitorParent::RecvClearHang() {
|
|
|
|
// chrome process, background thread
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2016-04-01 23:54:25 +00:00
|
|
|
|
2019-11-12 21:30:11 +00:00
|
|
|
if (!StaticPrefs::dom_ipc_reportProcessHangs()) {
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2016-04-01 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mHangMonitor->InitiateCPOWTimeout();
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
2017-03-06 20:55:36 +00:00
|
|
|
NS_DispatchToMainThread(mMainThreadTaskFactory.NewRunnableMethod(
|
|
|
|
&HangMonitorParent::ClearHangNotification));
|
2016-04-01 23:54:25 +00:00
|
|
|
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2016-04-01 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
2021-04-05 16:00:09 +00:00
|
|
|
void HangMonitorParent::TerminateScript() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2021-04-05 16:00:09 +00:00
|
|
|
Unused << SendTerminateScript();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::BeginStartingDebugger() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2015-11-02 05:53:26 +00:00
|
|
|
Unused << SendBeginStartingDebugger();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::EndStartingDebugger() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2015-11-02 05:53:26 +00:00
|
|
|
Unused << SendEndStartingDebugger();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HangMonitoredProcess implementation */
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(HangMonitoredProcess, nsIHangReport)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetHangType(uint32_t* aHangType) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
switch (mHangData.type()) {
|
|
|
|
case HangData::TSlowScriptData:
|
|
|
|
*aHangType = SLOW_SCRIPT;
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-01 02:39:16 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected HangData type");
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2015-06-01 02:39:16 +00:00
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-07-24 00:01:57 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetHangDuration(double* aHangDuration) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
*aHangDuration = -1;
|
|
|
|
} else {
|
|
|
|
*aHangDuration = mHangData.get_SlowScriptData().duration();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
NS_IMETHODIMP
|
2018-04-27 03:36:10 +00:00
|
|
|
HangMonitoredProcess::GetScriptBrowser(Element** aBrowser) {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabId tabId = mHangData.get_SlowScriptData().tabId();
|
|
|
|
if (!mContentParent) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<PBrowserParent*> tabs;
|
|
|
|
mContentParent->ManagedPBrowserParent(tabs);
|
|
|
|
for (size_t i = 0; i < tabs.Length(); i++) {
|
2019-04-09 21:38:15 +00:00
|
|
|
BrowserParent* tp = BrowserParent::GetFrom(tabs[i]);
|
2015-01-17 02:34:47 +00:00
|
|
|
if (tp->GetTabId() == tabId) {
|
2018-04-27 03:36:10 +00:00
|
|
|
RefPtr<Element> node = tp->GetOwnerElement();
|
2015-01-17 02:34:47 +00:00
|
|
|
node.forget(aBrowser);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aBrowser = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetScriptFileName(nsACString& aFileName) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aFileName = mHangData.get_SlowScriptData().filename();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-08-18 03:17:51 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetAddonId(nsAString& aAddonId) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aAddonId = mHangData.get_SlowScriptData().addonId();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::TerminateScript() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2021-04-05 16:00:09 +00:00
|
|
|
ProcessHangMonitor::Get()->Dispatch(
|
|
|
|
NewNonOwningRunnableMethod("HangMonitorParent::TerminateScript", mActor,
|
|
|
|
&HangMonitorParent::TerminateScript));
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::BeginStartingDebugger() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2017-06-12 19:34:10 +00:00
|
|
|
ProcessHangMonitor::Get()->Dispatch(NewNonOwningRunnableMethod(
|
|
|
|
"HangMonitorParent::BeginStartingDebugger", mActor,
|
|
|
|
&HangMonitorParent::BeginStartingDebugger));
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::EndStartingDebugger() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2017-06-12 19:34:10 +00:00
|
|
|
ProcessHangMonitor::Get()->Dispatch(NewNonOwningRunnableMethod(
|
|
|
|
"HangMonitorParent::EndStartingDebugger", mActor,
|
|
|
|
&HangMonitorParent::EndStartingDebugger));
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2021-03-11 17:41:19 +00:00
|
|
|
HangMonitoredProcess::IsReportForBrowserOrChildren(nsFrameLoader* aFrameLoader,
|
|
|
|
bool* aResult) {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2021-03-11 17:41:19 +00:00
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
*aResult = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-04-06 22:32:25 +00:00
|
|
|
NS_ENSURE_STATE(aFrameLoader);
|
2018-03-22 02:43:17 +00:00
|
|
|
|
2021-03-11 17:41:19 +00:00
|
|
|
AutoTArray<RefPtr<BrowsingContext>, 10> bcs;
|
|
|
|
bcs.AppendElement(aFrameLoader->GetExtantBrowsingContext());
|
|
|
|
while (!bcs.IsEmpty()) {
|
|
|
|
RefPtr<BrowsingContext> bc = bcs[bcs.Length() - 1];
|
|
|
|
bcs.RemoveLastElement();
|
|
|
|
if (!bc) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mContentParent == bc->Canonical()->GetContentParent()) {
|
|
|
|
*aResult = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
bc->GetChildren(bcs);
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 17:41:19 +00:00
|
|
|
*aResult = false;
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-11 17:25:45 +00:00
|
|
|
NS_IMETHODIMP
|
2021-04-06 19:28:17 +00:00
|
|
|
HangMonitoredProcess::UserCanceled() { return NS_OK; }
|
2015-06-11 17:25:45 +00:00
|
|
|
|
2020-08-03 17:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetChildID(uint64_t* aChildID) {
|
|
|
|
if (!mContentParent) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
*aChildID = mContentParent->ChildID();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
static bool InterruptCallback(JSContext* cx) {
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
2019-05-07 21:56:58 +00:00
|
|
|
return child->InterruptCallback();
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
ProcessHangMonitor* ProcessHangMonitor::sInstance;
|
|
|
|
|
|
|
|
ProcessHangMonitor::ProcessHangMonitor() : mCPOWTimeout(false) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-07-04 01:29:00 +00:00
|
|
|
if (XRE_IsContentProcess()) {
|
2015-01-17 02:34:47 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
obs->AddObserver(this, "xpcom-shutdown", false);
|
|
|
|
}
|
|
|
|
|
2017-05-20 03:36:10 +00:00
|
|
|
if (NS_FAILED(NS_NewNamedThread("ProcessHangMon", getter_AddRefs(mThread)))) {
|
2015-01-17 02:34:47 +00:00
|
|
|
mThread = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessHangMonitor::~ProcessHangMonitor() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MOZ_ASSERT(sInstance == this);
|
|
|
|
sInstance = nullptr;
|
|
|
|
|
2017-05-20 03:36:10 +00:00
|
|
|
mThread->Shutdown();
|
|
|
|
mThread = nullptr;
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProcessHangMonitor* ProcessHangMonitor::GetOrCreate() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (!sInstance) {
|
|
|
|
sInstance = new ProcessHangMonitor();
|
|
|
|
}
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(ProcessHangMonitor, nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ProcessHangMonitor::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aData) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown")) {
|
2020-04-23 23:18:24 +00:00
|
|
|
if (HangMonitorChild::sMonitor) {
|
|
|
|
MonitorAutoLock mal(*HangMonitorChild::sMonitor);
|
|
|
|
if (HangMonitorChild::sInitializing) {
|
|
|
|
mal.Wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
|
|
|
child->Shutdown();
|
|
|
|
delete child;
|
|
|
|
}
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
2020-04-23 23:18:24 +00:00
|
|
|
HangMonitorChild::sMonitor.reset();
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2020-04-23 23:18:24 +00:00
|
|
|
obs->RemoveObserver(this, "xpcom-shutdown");
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessHangMonitor::SlowScriptAction ProcessHangMonitor::NotifySlowScript(
|
2019-04-09 22:39:01 +00:00
|
|
|
nsIBrowserChild* aBrowserChild, const char* aFileName,
|
2020-07-24 00:01:57 +00:00
|
|
|
const nsString& aAddonId, const double aDuration) {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2019-04-09 22:39:01 +00:00
|
|
|
return HangMonitorChild::Get()->NotifySlowScript(aBrowserChild, aFileName,
|
2020-07-24 00:01:57 +00:00
|
|
|
aAddonId, aDuration);
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessHangMonitor::IsDebuggerStartupComplete() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
return HangMonitorChild::Get()->IsDebuggerStartupComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessHangMonitor::ShouldTimeOutCPOWs() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mCPOWTimeout) {
|
|
|
|
mCPOWTimeout = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessHangMonitor::InitiateCPOWTimeout() {
|
2017-05-20 03:36:10 +00:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 02:34:47 +00:00
|
|
|
mCPOWTimeout = true;
|
|
|
|
}
|
|
|
|
|
2017-01-05 20:54:52 +00:00
|
|
|
static PProcessHangMonitorParent* CreateHangMonitorParent(
|
|
|
|
ContentParent* aContentParent,
|
|
|
|
Endpoint<PProcessHangMonitorParent>&& aEndpoint) {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
|
2016-11-14 09:35:58 +00:00
|
|
|
auto* parent = new HangMonitorParent(monitor);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-11-14 09:35:58 +00:00
|
|
|
auto* process = new HangMonitoredProcess(parent, aContentParent);
|
2015-01-17 02:34:47 +00:00
|
|
|
parent->SetProcess(process);
|
|
|
|
|
2017-06-12 19:34:10 +00:00
|
|
|
monitor->Dispatch(
|
|
|
|
NewNonOwningRunnableMethod<Endpoint<PProcessHangMonitorParent>&&>(
|
|
|
|
"HangMonitorParent::Bind", parent, &HangMonitorParent::Bind,
|
2018-05-30 19:15:35 +00:00
|
|
|
std::move(aEndpoint)));
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2017-01-05 20:54:52 +00:00
|
|
|
void mozilla::CreateHangMonitorChild(
|
|
|
|
Endpoint<PProcessHangMonitorChild>&& aEndpoint) {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
JSContext* cx = danger::GetJSContext();
|
|
|
|
JS_AddInterruptCallback(cx, InterruptCallback);
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
|
2016-11-14 09:35:58 +00:00
|
|
|
auto* child = new HangMonitorChild(monitor);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2017-06-12 19:34:10 +00:00
|
|
|
monitor->Dispatch(
|
|
|
|
NewNonOwningRunnableMethod<Endpoint<PProcessHangMonitorChild>&&>(
|
|
|
|
"HangMonitorChild::Bind", child, &HangMonitorChild::Bind,
|
2018-05-30 19:15:35 +00:00
|
|
|
std::move(aEndpoint)));
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 03:36:10 +00:00
|
|
|
void ProcessHangMonitor::Dispatch(already_AddRefed<nsIRunnable> aRunnable) {
|
2018-05-30 19:15:35 +00:00
|
|
|
mThread->Dispatch(std::move(aRunnable), nsIEventTarget::NS_DISPATCH_NORMAL);
|
2017-05-20 03:36:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessHangMonitor::IsOnThread() {
|
|
|
|
bool on;
|
|
|
|
return NS_SUCCEEDED(mThread->IsOnCurrentThread(&on)) && on;
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 22:05:29 +00:00
|
|
|
/* static */
|
|
|
|
PProcessHangMonitorParent* ProcessHangMonitor::AddProcess(
|
2015-01-17 02:34:47 +00:00
|
|
|
ContentParent* aContentParent) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2019-11-12 21:30:11 +00:00
|
|
|
if (!StaticPrefs::dom_ipc_processHangMonitor_AtStartup()) {
|
2017-01-05 20:54:52 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Endpoint<PProcessHangMonitorParent> parent;
|
|
|
|
Endpoint<PProcessHangMonitorChild> child;
|
|
|
|
nsresult rv;
|
|
|
|
rv = PProcessHangMonitor::CreateEndpoints(
|
|
|
|
base::GetCurrentProcId(), aContentParent->OtherPid(), &parent, &child);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_ASSERT(false, "PProcessHangMonitor::CreateEndpoints failed");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-30 19:15:35 +00:00
|
|
|
if (!aContentParent->SendInitProcessHangMonitor(std::move(child))) {
|
2017-01-05 20:54:52 +00:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return nullptr;
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
2017-01-05 20:54:52 +00:00
|
|
|
|
2018-05-30 19:15:35 +00:00
|
|
|
return CreateHangMonitorParent(aContentParent, std::move(parent));
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 22:05:29 +00:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::RemoveProcess(PProcessHangMonitorParent* aParent) {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
auto parent = static_cast<HangMonitorParent*>(aParent);
|
|
|
|
parent->Shutdown();
|
|
|
|
delete parent;
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:05:29 +00:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::ClearHang() {
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
|
|
|
child->ClearHang();
|
|
|
|
}
|
|
|
|
}
|
2016-07-22 23:36:45 +00:00
|
|
|
|
2019-02-25 22:05:29 +00:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::PaintWhileInterruptingJS(
|
2019-04-09 21:38:15 +00:00
|
|
|
PProcessHangMonitorParent* aParent, dom::BrowserParent* aBrowserParent,
|
2019-09-26 22:11:17 +00:00
|
|
|
const layers::LayersObserverEpoch& aEpoch) {
|
2016-07-22 23:36:45 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
auto parent = static_cast<HangMonitorParent*>(aParent);
|
2019-09-26 22:11:17 +00:00
|
|
|
parent->PaintWhileInterruptingJS(aBrowserParent, aEpoch);
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
2016-10-21 18:56:46 +00:00
|
|
|
|
2019-02-25 22:05:29 +00:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::ClearPaintWhileInterruptingJS(
|
2018-07-30 13:24:50 +00:00
|
|
|
const layers::LayersObserverEpoch& aEpoch) {
|
2016-10-21 18:56:46 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsContentProcess());
|
|
|
|
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
2018-07-30 13:24:50 +00:00
|
|
|
child->ClearPaintWhileInterruptingJS(aEpoch);
|
2016-10-21 18:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-18 18:44:19 +00:00
|
|
|
|
2019-02-25 22:05:29 +00:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::MaybeStartPaintWhileInterruptingJS() {
|
2018-03-18 18:44:19 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsContentProcess());
|
|
|
|
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
2018-05-15 06:45:00 +00:00
|
|
|
child->MaybeStartPaintWhileInterruptingJS();
|
2018-03-18 18:44:19 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-30 23:56:17 +00:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::CancelContentJSExecutionIfRunning(
|
2019-04-30 23:31:36 +00:00
|
|
|
PProcessHangMonitorParent* aParent, dom::BrowserParent* aBrowserParent,
|
|
|
|
nsIRemoteTab::NavigationType aNavigationType,
|
|
|
|
const dom::CancelContentJSOptions& aCancelContentJSOptions) {
|
2019-04-30 23:56:17 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
auto parent = static_cast<HangMonitorParent*>(aParent);
|
2019-04-30 23:31:36 +00:00
|
|
|
parent->CancelContentJSExecutionIfRunning(aBrowserParent, aNavigationType,
|
|
|
|
aCancelContentJSOptions);
|
2019-04-30 23:56:17 +00:00
|
|
|
}
|