зеркало из https://github.com/mozilla/gecko-dev.git
Backout changesets 7ff3cd713466, f8ec5977a454 and c7c37390b46b (bug 977026) for b2g bustage on a CLOSED TREE.
This commit is contained in:
Родитель
af7fc07366
Коммит
9424087517
|
@ -1,248 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=2 autoindent cindent expandtab: */
|
||||
/* 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 "nsXULAppAPI.h"
|
||||
#include "application.ini.h"
|
||||
#include "nsXPCOMGlue.h"
|
||||
#include "nsStringGlue.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFile.h"
|
||||
#include "BinaryPath.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
|
||||
|
||||
#define ASSERT(x) if (!(x)) { MOZ_CRASH(); }
|
||||
|
||||
|
||||
// Functions being loaded by XPCOMGlue
|
||||
XRE_ProcLoaderServiceRunType XRE_ProcLoaderServiceRun;
|
||||
XRE_ProcLoaderClientInitType XRE_ProcLoaderClientInit;
|
||||
XRE_ProcLoaderPreloadType XRE_ProcLoaderPreload;
|
||||
extern XRE_CreateAppDataType XRE_CreateAppData;
|
||||
extern XRE_GetFileFromPathType XRE_GetFileFromPath;
|
||||
|
||||
static const nsDynamicFunctionLoad kXULFuncs[] = {
|
||||
{ "XRE_ProcLoaderServiceRun", (NSFuncPtr*) &XRE_ProcLoaderServiceRun },
|
||||
{ "XRE_ProcLoaderClientInit", (NSFuncPtr*) &XRE_ProcLoaderClientInit },
|
||||
{ "XRE_ProcLoaderPreload", (NSFuncPtr*) &XRE_ProcLoaderPreload },
|
||||
{ "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
|
||||
{ "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
static int
|
||||
GetDirnameSlash(const char *aPath, char *aOutDir, int aMaxLen)
|
||||
{
|
||||
char *lastSlash = strrchr(aPath, XPCOM_FILE_PATH_SEPARATOR[0]);
|
||||
if (lastSlash == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
int cpsz = lastSlash - aPath + 1; // include slash
|
||||
if (aMaxLen <= cpsz) {
|
||||
return 0;
|
||||
}
|
||||
strncpy(aOutDir, aPath, cpsz);
|
||||
aOutDir[cpsz] = 0;
|
||||
return cpsz;
|
||||
}
|
||||
|
||||
static bool
|
||||
GetXPCOMPath(const char *aProgram, char *aOutPath, int aMaxLen)
|
||||
{
|
||||
nsAutoArrayPtr<char> progBuf(new char[aMaxLen]);
|
||||
nsresult rv = mozilla::BinaryPath::Get(aProgram, progBuf);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
int len = GetDirnameSlash(progBuf, aOutPath, aMaxLen);
|
||||
NS_ENSURE_TRUE(!!len, false);
|
||||
|
||||
NS_ENSURE_TRUE((len + sizeof(XPCOM_DLL)) < aMaxLen, false);
|
||||
char *afterSlash = aOutPath + len;
|
||||
strcpy(afterSlash, XPCOM_DLL);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
LoadLibxul(const char *aXPCOMPath)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
XPCOMGlueEnablePreload();
|
||||
rv = XPCOMGlueStartup(aXPCOMPath);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if |arg| matches the given argument name.
|
||||
*/
|
||||
static bool
|
||||
IsArg(const char* arg, const char* s)
|
||||
{
|
||||
if (*arg == '-') {
|
||||
if (*++arg == '-') {
|
||||
++arg;
|
||||
}
|
||||
return !strcasecmp(arg, s);
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
if (*arg == '/') {
|
||||
return !strcasecmp(++arg, s);
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static already_AddRefed<nsIFile>
|
||||
GetAppIni(int argc, const char *argv[])
|
||||
{
|
||||
nsCOMPtr<nsIFile> appini;
|
||||
nsresult rv;
|
||||
|
||||
// Allow firefox.exe to launch XULRunner apps via -app <application.ini>
|
||||
// Note that -app must be the *first* argument.
|
||||
const char *appDataFile = getenv("XUL_APP_FILE");
|
||||
if (appDataFile && *appDataFile) {
|
||||
rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini));
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
} else if (argc > 1 && IsArg(argv[1], "app")) {
|
||||
if (argc == 2) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini));
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
char appEnv[MAXPATHLEN];
|
||||
snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
|
||||
if (putenv(appEnv)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return appini.forget();
|
||||
}
|
||||
|
||||
static bool
|
||||
LoadStaticData(int argc, const char *argv[])
|
||||
{
|
||||
char xpcomPath[MAXPATHLEN];
|
||||
bool ok = GetXPCOMPath(argv[0], xpcomPath, MAXPATHLEN);
|
||||
NS_ENSURE_TRUE(ok, false);
|
||||
|
||||
ok = LoadLibxul(xpcomPath);
|
||||
NS_ENSURE_TRUE(ok, false);
|
||||
|
||||
char progDir[MAXPATHLEN];
|
||||
ok = GetDirnameSlash(xpcomPath, progDir, MAXPATHLEN);
|
||||
NS_ENSURE_TRUE(ok, false);
|
||||
|
||||
nsCOMPtr<nsIFile> appini = GetAppIni(argc, argv);
|
||||
const nsXREAppData *appData;
|
||||
if (appini) {
|
||||
nsresult rv =
|
||||
XRE_CreateAppData(appini, const_cast<nsXREAppData**>(&appData));
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
} else {
|
||||
appData = &sAppData;
|
||||
}
|
||||
|
||||
XRE_ProcLoaderPreload(progDir, appData);
|
||||
|
||||
if (appini) {
|
||||
XRE_FreeAppData(const_cast<nsXREAppData*>(appData));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fork and run parent and child process.
|
||||
*
|
||||
* The parent is the b2g process and child for Nuwa.
|
||||
*/
|
||||
static int
|
||||
RunProcesses(int argc, const char *argv[])
|
||||
{
|
||||
/*
|
||||
* The original main() of the b2g process. It is renamed to
|
||||
* b2g_main() for the b2g loader.
|
||||
*/
|
||||
int b2g_main(int argc, const char *argv[]);
|
||||
|
||||
int ipcSockets[2] = {-1, -1};
|
||||
int r = socketpair(AF_LOCAL, SOCK_STREAM, 0, ipcSockets);
|
||||
ASSERT(r == 0);
|
||||
int parentSock = ipcSockets[0];
|
||||
int childSock = ipcSockets[1];
|
||||
|
||||
r = fcntl(parentSock, F_SETFL, O_NONBLOCK);
|
||||
ASSERT(r != -1);
|
||||
r = fcntl(childSock, F_SETFL, O_NONBLOCK);
|
||||
ASSERT(r != -1);
|
||||
|
||||
pid_t pid = fork();
|
||||
ASSERT(pid >= 0);
|
||||
bool isChildProcess = pid == 0;
|
||||
|
||||
close(isChildProcess ? parentSock : childSock);
|
||||
|
||||
if (isChildProcess) {
|
||||
/* The Nuwa process */
|
||||
/* This provides the IPC service of loading Nuwa at the process.
|
||||
* The b2g process would send a IPC message of loading Nuwa
|
||||
* as the replacement of forking and executing plugin-container.
|
||||
*/
|
||||
return XRE_ProcLoaderServiceRun(getppid(), childSock, argc, argv);
|
||||
}
|
||||
|
||||
// The b2g process
|
||||
int childPid = pid;
|
||||
XRE_ProcLoaderClientInit(childPid, parentSock);
|
||||
return b2g_main(argc, argv);
|
||||
}
|
||||
|
||||
/**
|
||||
* B2G Loader is responsible for loading the b2g process and the
|
||||
* Nuwa process. It forks into the parent process, for the b2g
|
||||
* process, and the child process, for the Nuwa process.
|
||||
*
|
||||
* The loader loads libxul and performs initialization of static data
|
||||
* before forking, so relocation of libxul and static data can be
|
||||
* shared between the b2g process, the Nuwa process, and the content
|
||||
* processes.
|
||||
*/
|
||||
int
|
||||
main(int argc, const char* argv[])
|
||||
{
|
||||
const char *program = argv[0];
|
||||
/*
|
||||
* Before fork(), libxul and static data of Gecko are loaded for
|
||||
* sharing.
|
||||
*/
|
||||
bool ok = LoadStaticData(argc, argv);
|
||||
if (!ok) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
return RunProcesses(argc, argv);
|
||||
}
|
|
@ -9,11 +9,6 @@ if not CONFIG['LIBXUL_SDK']:
|
|||
PROGRAM = CONFIG['MOZ_APP_NAME'] + "-bin"
|
||||
else:
|
||||
PROGRAM = CONFIG['MOZ_APP_NAME']
|
||||
if CONFIG['MOZ_B2G_LOADER']:
|
||||
SOURCES += [
|
||||
'B2GLoader.cpp',
|
||||
]
|
||||
|
||||
SOURCES += [
|
||||
'nsBrowserApp.cpp',
|
||||
]
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFile.h"
|
||||
|
@ -164,22 +163,9 @@ static int do_main(int argc, char* argv[])
|
|||
return XRE_main(argc, argv, &sAppData, 0);
|
||||
}
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
/*
|
||||
* The main() in B2GLoader.cpp is the new main function instead of the
|
||||
* main() here if it is enabled. So, rename it to b2g_man().
|
||||
*/
|
||||
#define main b2g_main
|
||||
#define _CONST const
|
||||
#else
|
||||
#define _CONST
|
||||
#endif
|
||||
|
||||
int main(int argc, _CONST char* argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#ifndef MOZ_B2G_LOADER
|
||||
char exePath[MAXPATHLEN];
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
// This creates a ThreadPool for binder ipc. A ThreadPool is necessary to
|
||||
|
@ -189,9 +175,7 @@ int main(int argc, _CONST char* argv[])
|
|||
android::ProcessState::self()->startThreadPool();
|
||||
#endif
|
||||
|
||||
nsresult rv;
|
||||
#ifndef MOZ_B2G_LOADER
|
||||
rv = mozilla::BinaryPath::Get(argv[0], exePath);
|
||||
nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath);
|
||||
if (NS_FAILED(rv)) {
|
||||
Output("Couldn't calculate the application directory.\n");
|
||||
return 255;
|
||||
|
@ -202,7 +186,6 @@ int main(int argc, _CONST char* argv[])
|
|||
return 255;
|
||||
|
||||
strcpy(++lastSlash, XPCOM_DLL);
|
||||
#endif // MOZ_B2G_LOADER
|
||||
|
||||
#if defined(XP_UNIX)
|
||||
// If the b2g app is launched from adb shell, then the shell will wind
|
||||
|
@ -226,9 +209,6 @@ int main(int argc, _CONST char* argv[])
|
|||
DllBlocklist_Initialize();
|
||||
#endif
|
||||
|
||||
// B2G loader has already initialized Gecko so we can't initialize
|
||||
// it again here.
|
||||
#ifndef MOZ_B2G_LOADER
|
||||
// We do this because of data in bug 771745
|
||||
XPCOMGlueEnablePreload();
|
||||
|
||||
|
@ -239,7 +219,6 @@ int main(int argc, _CONST char* argv[])
|
|||
}
|
||||
// Reset exePath so that it is the directory name and not the xpcom dll name
|
||||
*lastSlash = 0;
|
||||
#endif // MOZ_B2G_LOADER
|
||||
|
||||
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -274,25 +253,7 @@ int main(int argc, _CONST char* argv[])
|
|||
int result;
|
||||
{
|
||||
ScopedLogging log;
|
||||
char **_argv;
|
||||
|
||||
/*
|
||||
* Duplicate argument vector to conform non-const argv of
|
||||
* do_main() since XRE_main() is very stupid with non-const argv.
|
||||
*/
|
||||
_argv = new char *[argc + 1];
|
||||
for (int i = 0; i < argc; i++) {
|
||||
_argv[i] = strdup(argv[i]);
|
||||
MOZ_ASSERT(_argv[i] != nullptr);
|
||||
}
|
||||
_argv[argc] = nullptr;
|
||||
|
||||
result = do_main(argc, _argv);
|
||||
|
||||
for (int i = 0; i < argc; i++) {
|
||||
free(_argv[i]);
|
||||
}
|
||||
delete[] _argv;
|
||||
result = do_main(argc, argv);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -59,7 +59,6 @@ MOZ_B2G=1
|
|||
|
||||
if test "$OS_TARGET" = "Android"; then
|
||||
MOZ_NUWA_PROCESS=1
|
||||
MOZ_B2G_LOADER=1
|
||||
fi
|
||||
MOZ_FOLD_LIBS=1
|
||||
|
||||
|
|
|
@ -8631,14 +8631,6 @@ if test "$MOZ_WIDGET_TOOLKIT" = gonk -a -n "$MOZ_NUWA_PROCESS"; then
|
|||
AC_DEFINE(MOZ_NUWA_PROCESS)
|
||||
fi
|
||||
AC_SUBST(MOZ_NUWA_PROCESS)
|
||||
if test "$MOZ_WIDGET_TOOLKIT" = gonk -a -n "$MOZ_B2G_LOADER"; then
|
||||
if test -z "$MOZ_NUWA_PROCESS"; then
|
||||
AC_MSG_ERROR([B2G loader works with Nuwa]);
|
||||
fi
|
||||
export MOZ_B2G_LOADER
|
||||
AC_DEFINE(MOZ_B2G_LOADER)
|
||||
fi
|
||||
AC_SUBST(MOZ_B2G_LOADER)
|
||||
|
||||
AC_SUBST(NSPR_CFLAGS)
|
||||
AC_SUBST(NSPR_LIBS)
|
||||
|
|
|
@ -37,10 +37,6 @@ include $(topsrcdir)/config/config.mk
|
|||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifneq ($(MOZ_WIDGET_TOOLKIT),android)
|
||||
#LIBS += ../contentproc/$(LIB_PREFIX)plugin-container.$(LIB_SUFFIX)
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT) #{
|
||||
# Note the manifest file exists in the tree, so we use the explicit filename
|
||||
# here.
|
||||
|
|
|
@ -4,9 +4,148 @@
|
|||
* 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 "../contentproc/plugin-container.cpp"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
return content_process_main(argc, argv);
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
// FIXME/cjones testing
|
||||
#if !defined(OS_WIN)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include <windows.h>
|
||||
// we want a wmain entry point
|
||||
// but we don't want its DLL load protection, because we'll handle it here
|
||||
#define XRE_DONT_PROTECT_DLL_LOAD
|
||||
#include "nsWindowsWMain.cpp"
|
||||
#include "nsSetDllDirectory.h"
|
||||
#endif
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include "sandbox/chromium/base/basictypes.h"
|
||||
#include "sandbox/win/src/sandbox.h"
|
||||
#include "sandbox/win/src/sandbox_factory.h"
|
||||
#include "mozilla/sandboxTarget.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
# include <sys/time.h>
|
||||
# include <sys/resource.h>
|
||||
|
||||
# include <binder/ProcessState.h>
|
||||
|
||||
# ifdef LOGE_IF
|
||||
# undef LOGE_IF
|
||||
# endif
|
||||
|
||||
# include <android/log.h>
|
||||
# define LOGE_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_print(ANDROID_LOG_ERROR, \
|
||||
"Gecko:MozillaRntimeMain", __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_NUWA_PROCESS
|
||||
#include <binder/ProcessState.h>
|
||||
#include "ipc/Nuwa.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
static void
|
||||
InitializeBinder(void *aDummy) {
|
||||
// Change thread priority to 0 only during calling ProcessState::self().
|
||||
// The priority is registered to binder driver and used for default Binder
|
||||
// Thread's priority.
|
||||
// To change the process's priority to small value need's root permission.
|
||||
int curPrio = getpriority(PRIO_PROCESS, 0);
|
||||
int err = setpriority(PRIO_PROCESS, 0, 0);
|
||||
MOZ_ASSERT(!err);
|
||||
LOGE_IF(err, "setpriority failed. Current process needs root permission.");
|
||||
android::ProcessState::self()->startThreadPool();
|
||||
setpriority(PRIO_PROCESS, 0, curPrio);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(XP_WIN)
|
||||
static bool gIsSandboxEnabled = false;
|
||||
void StartSandboxCallback()
|
||||
{
|
||||
if (gIsSandboxEnabled) {
|
||||
sandbox::TargetServices* target_service =
|
||||
sandbox::SandboxFactory::GetTargetServices();
|
||||
target_service->LowerToken();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
bool isNuwa = false;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
isNuwa |= strcmp(argv[i], "-nuwa") == 0;
|
||||
#if defined(XP_WIN)
|
||||
gIsSandboxEnabled |= strcmp(argv[i], "-sandbox") == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MOZ_NUWA_PROCESS
|
||||
if (isNuwa) {
|
||||
PrepareNuwaProcess();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
// This creates a ThreadPool for binder ipc. A ThreadPool is necessary to
|
||||
// receive binder calls, though not necessary to send binder calls.
|
||||
// ProcessState::Self() also needs to be called once on the main thread to
|
||||
// register the main thread with the binder driver.
|
||||
|
||||
#ifdef MOZ_NUWA_PROCESS
|
||||
if (!isNuwa) {
|
||||
InitializeBinder(nullptr);
|
||||
} else {
|
||||
NuwaAddFinalConstructor(&InitializeBinder, nullptr);
|
||||
}
|
||||
#else
|
||||
InitializeBinder(nullptr);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Check for the absolute minimum number of args we need to move
|
||||
// forward here. We expect the last arg to be the child process type.
|
||||
if (argc < 1)
|
||||
return 3;
|
||||
GeckoProcessType proctype = XRE_StringToChildProcessType(argv[--argc]);
|
||||
|
||||
#ifdef XP_WIN
|
||||
// For plugins, this is done in PluginProcessChild::Init, as we need to
|
||||
// avoid it for unsupported plugins. See PluginProcessChild::Init for
|
||||
// the details.
|
||||
if (proctype != GeckoProcessType_Plugin) {
|
||||
mozilla::SanitizeEnvironmentVariables();
|
||||
SetDllDirectory(L"");
|
||||
}
|
||||
|
||||
if (gIsSandboxEnabled) {
|
||||
sandbox::TargetServices* target_service =
|
||||
sandbox::SandboxFactory::GetTargetServices();
|
||||
if (!target_service) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
sandbox::ResultCode result = target_service->Init();
|
||||
if (result != sandbox::SBOX_ALL_OK) {
|
||||
return 2;
|
||||
}
|
||||
mozilla::SandboxTarget::Instance()->SetStartSandboxCallback(StartSandboxCallback);
|
||||
}
|
||||
#endif
|
||||
|
||||
nsresult rv = XRE_InitChildProcess(argc, argv, proctype);
|
||||
NS_ENSURE_SUCCESS(rv, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=2 autoindent cindent expandtab: */
|
||||
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
@ -20,13 +18,6 @@
|
|||
#include "base/logging.h"
|
||||
#include "base/string_tokenizer.h"
|
||||
#include "base/string_util.h"
|
||||
#include "nsLiteralString.h"
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
#include "ProcessUtils.h"
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
#endif // MOZ_B2G_LOADER
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
/*
|
||||
|
@ -197,71 +188,12 @@ bool LaunchApp(const std::vector<std::string>& argv,
|
|||
wait, process_handle);
|
||||
}
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
/**
|
||||
* Launch an app using B2g Loader.
|
||||
*/
|
||||
static bool
|
||||
LaunchAppProcLoader(const std::vector<std::string>& argv,
|
||||
const file_handle_mapping_vector& fds_to_remap,
|
||||
const environment_map& env_vars_to_set,
|
||||
ChildPrivileges privs,
|
||||
ProcessHandle* process_handle) {
|
||||
size_t i;
|
||||
scoped_array<char*> argv_cstr(new char*[argv.size() + 1]);
|
||||
for (i = 0; i < argv.size(); i++) {
|
||||
argv_cstr[i] = const_cast<char*>(argv[i].c_str());
|
||||
}
|
||||
argv_cstr[argv.size()] = nullptr;
|
||||
|
||||
scoped_array<char*> env_cstr(new char*[env_vars_to_set.size() + 1]);
|
||||
i = 0;
|
||||
for (environment_map::const_iterator it = env_vars_to_set.begin();
|
||||
it != env_vars_to_set.end(); ++it) {
|
||||
env_cstr[i++] = strdup((it->first + "=" + it->second).c_str());
|
||||
}
|
||||
env_cstr[env_vars_to_set.size()] = nullptr;
|
||||
|
||||
bool ok = ProcLoaderLoad((const char **)argv_cstr.get(),
|
||||
(const char **)env_cstr.get(),
|
||||
fds_to_remap, privs,
|
||||
process_handle);
|
||||
MOZ_ASSERT(ok, "ProcLoaderLoad() failed");
|
||||
|
||||
for (size_t i = 0; i < env_vars_to_set.size(); i++) {
|
||||
free(env_cstr[i]);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
static bool
|
||||
IsLaunchingNuwa(const std::vector<std::string>& argv) {
|
||||
std::vector<std::string>::const_iterator it;
|
||||
for (it = argv.begin(); it != argv.end(); ++it) {
|
||||
if (*it == std::string("-nuwa")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif // MOZ_B2G_LOADER
|
||||
|
||||
bool LaunchApp(const std::vector<std::string>& argv,
|
||||
const file_handle_mapping_vector& fds_to_remap,
|
||||
const environment_map& env_vars_to_set,
|
||||
ChildPrivileges privs,
|
||||
bool wait, ProcessHandle* process_handle,
|
||||
ProcessArchitecture arch) {
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
static bool beforeFirstNuwaLaunch = true;
|
||||
if (!wait && beforeFirstNuwaLaunch && IsLaunchingNuwa(argv)) {
|
||||
beforeFirstNuwaLaunch = false;
|
||||
return LaunchAppProcLoader(argv, fds_to_remap, env_vars_to_set,
|
||||
privs, process_handle);
|
||||
}
|
||||
#endif // MOZ_B2G_LOADER
|
||||
|
||||
scoped_array<char*> argv_cstr(new char*[argv.size() + 1]);
|
||||
// Illegal to allocate memory after fork and before execvp
|
||||
InjectiveMultimap fd_shuffle1, fd_shuffle2;
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
LIBRARY_NAME = 'plugin-container'
|
||||
if CONFIG['MOZ_B2G_LOADER']:
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
SOURCES += [
|
||||
'plugin-container.cpp',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
if CONFIG['OS_ARCH'] == 'WINNT':
|
||||
LOCAL_INCLUDES += [
|
||||
'/toolkit/xre',
|
||||
'/xpcom/base',
|
||||
]
|
||||
|
||||
if CONFIG['OS_ARCH'] == 'WINNT':
|
||||
# For sandbox includes and the include dependencies those have
|
||||
LOCAL_INCLUDES += [
|
||||
'/security',
|
||||
'/security/sandbox',
|
||||
'/security/sandbox/chromium',
|
||||
]
|
|
@ -1,151 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: sw=4 ts=4 et :
|
||||
* 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 "nsXPCOM.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
// FIXME/cjones testing
|
||||
#if !defined(OS_WIN)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include <windows.h>
|
||||
// we want a wmain entry point
|
||||
// but we don't want its DLL load protection, because we'll handle it here
|
||||
#define XRE_DONT_PROTECT_DLL_LOAD
|
||||
#include "nsWindowsWMain.cpp"
|
||||
#include "nsSetDllDirectory.h"
|
||||
#endif
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include "sandbox/chromium/base/basictypes.h"
|
||||
#include "sandbox/win/src/sandbox.h"
|
||||
#include "sandbox/win/src/sandbox_factory.h"
|
||||
#include "mozilla/sandboxTarget.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
# include <sys/time.h>
|
||||
# include <sys/resource.h>
|
||||
|
||||
# include <binder/ProcessState.h>
|
||||
|
||||
# ifdef LOGE_IF
|
||||
# undef LOGE_IF
|
||||
# endif
|
||||
|
||||
# include <android/log.h>
|
||||
# define LOGE_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_print(ANDROID_LOG_ERROR, \
|
||||
"Gecko:MozillaRntimeMain", __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_NUWA_PROCESS
|
||||
#include <binder/ProcessState.h>
|
||||
#include "ipc/Nuwa.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
static void
|
||||
InitializeBinder(void *aDummy) {
|
||||
// Change thread priority to 0 only during calling ProcessState::self().
|
||||
// The priority is registered to binder driver and used for default Binder
|
||||
// Thread's priority.
|
||||
// To change the process's priority to small value need's root permission.
|
||||
int curPrio = getpriority(PRIO_PROCESS, 0);
|
||||
int err = setpriority(PRIO_PROCESS, 0, 0);
|
||||
MOZ_ASSERT(!err);
|
||||
LOGE_IF(err, "setpriority failed. Current process needs root permission.");
|
||||
android::ProcessState::self()->startThreadPool();
|
||||
setpriority(PRIO_PROCESS, 0, curPrio);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(XP_WIN)
|
||||
static bool gIsSandboxEnabled = false;
|
||||
void StartSandboxCallback()
|
||||
{
|
||||
if (gIsSandboxEnabled) {
|
||||
sandbox::TargetServices* target_service =
|
||||
sandbox::SandboxFactory::GetTargetServices();
|
||||
target_service->LowerToken();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
content_process_main(int argc, char* argv[])
|
||||
{
|
||||
bool isNuwa = false;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
isNuwa |= strcmp(argv[i], "-nuwa") == 0;
|
||||
#if defined(XP_WIN)
|
||||
gIsSandboxEnabled |= strcmp(argv[i], "-sandbox") == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MOZ_NUWA_PROCESS
|
||||
if (isNuwa) {
|
||||
PrepareNuwaProcess();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
// This creates a ThreadPool for binder ipc. A ThreadPool is necessary to
|
||||
// receive binder calls, though not necessary to send binder calls.
|
||||
// ProcessState::Self() also needs to be called once on the main thread to
|
||||
// register the main thread with the binder driver.
|
||||
|
||||
#ifdef MOZ_NUWA_PROCESS
|
||||
if (!isNuwa) {
|
||||
InitializeBinder(nullptr);
|
||||
} else {
|
||||
NuwaAddFinalConstructor(&InitializeBinder, nullptr);
|
||||
}
|
||||
#else
|
||||
InitializeBinder(nullptr);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Check for the absolute minimum number of args we need to move
|
||||
// forward here. We expect the last arg to be the child process type.
|
||||
if (argc < 1)
|
||||
return 3;
|
||||
GeckoProcessType proctype = XRE_StringToChildProcessType(argv[--argc]);
|
||||
|
||||
#ifdef XP_WIN
|
||||
// For plugins, this is done in PluginProcessChild::Init, as we need to
|
||||
// avoid it for unsupported plugins. See PluginProcessChild::Init for
|
||||
// the details.
|
||||
if (proctype != GeckoProcessType_Plugin) {
|
||||
mozilla::SanitizeEnvironmentVariables();
|
||||
SetDllDirectory(L"");
|
||||
}
|
||||
|
||||
if (gIsSandboxEnabled) {
|
||||
sandbox::TargetServices* target_service =
|
||||
sandbox::SandboxFactory::GetTargetServices();
|
||||
if (!target_service) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
sandbox::ResultCode result = target_service->Init();
|
||||
if (result != sandbox::SBOX_ALL_OK) {
|
||||
return 2;
|
||||
}
|
||||
mozilla::SandboxTarget::Instance()->SetStartSandboxCallback(StartSandboxCallback);
|
||||
}
|
||||
#endif
|
||||
|
||||
nsresult rv = XRE_InitChildProcess(argc, argv, proctype);
|
||||
NS_ENSURE_SUCCESS(rv, 1);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=2 autoindent cindent expandtab: */
|
||||
/* 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/. */
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
struct FDRemap {
|
||||
FileDescriptor fd;
|
||||
int mapto;
|
||||
};
|
||||
|
||||
protocol PProcLoader
|
||||
{
|
||||
child:
|
||||
/**
|
||||
* Request B2G loader service to load content process.
|
||||
*
|
||||
* It actually calls the main() function of plugin-container.
|
||||
*/
|
||||
async Load(nsCString[] argv, nsCString[] env,
|
||||
FDRemap[] fdsRemap, uint32_t privs,
|
||||
int32_t cookie);
|
||||
|
||||
parent:
|
||||
/**
|
||||
* The acknowledgement of Load().
|
||||
*/
|
||||
async LoadComplete(int32_t pid, int32_t cookie);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=2 autoindent cindent expandtab: */
|
||||
/* 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/. */
|
||||
|
@ -7,10 +5,6 @@
|
|||
#ifndef mozilla_ipc_ProcessUtils_h
|
||||
#define mozilla_ipc_ProcessUtils_h
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
#include "base/process_util.h"
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
|
@ -18,17 +12,6 @@ namespace ipc {
|
|||
// this directly.
|
||||
void SetThisProcessName(const char *aName);
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
// see ProcessUtils_linux.cpp for explaination.
|
||||
void ProcLoaderClientGeckoInit();
|
||||
|
||||
bool ProcLoaderLoad(const char *aArgv[],
|
||||
const char *aEnvp[],
|
||||
const base::file_handle_mapping_vector &aFdsRemap,
|
||||
const base::ChildPrivileges aPrivs,
|
||||
base::ProcessHandle *aProcessHandle);
|
||||
#endif /* MOZ_B2G_LOADER */
|
||||
|
||||
} // namespace ipc
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=2 autoindent cindent expandtab: */
|
||||
/* 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/. */
|
||||
|
@ -10,37 +8,6 @@
|
|||
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/ipc/PProcLoaderParent.h"
|
||||
#include "mozilla/ipc/PProcLoaderChild.h"
|
||||
#include "mozilla/ipc/Transport.h"
|
||||
#include "mozilla/ipc/FileDescriptorUtils.h"
|
||||
#include "mozilla/ipc/IOThreadChild.h"
|
||||
#include "mozilla/dom/ContentProcess.h"
|
||||
#include "base/file_descriptor_shuffle.h"
|
||||
#include "mozilla/BackgroundHangMonitor.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "base/process_util.h"
|
||||
|
||||
#include "prenv.h"
|
||||
|
||||
#include "nsXULAppAPI.h" // export XRE_* functions
|
||||
|
||||
#include "nsAppRunner.h"
|
||||
|
||||
int content_process_main(int argc, char *argv[]);
|
||||
|
||||
extern bool gDisableAndroidLog;
|
||||
|
||||
#endif /* MOZ_B2G_LOADER */
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
|
@ -49,522 +16,5 @@ void SetThisProcessName(const char *aName)
|
|||
prctl(PR_SET_NAME, (unsigned long)aName, 0uL, 0uL, 0uL);
|
||||
}
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
/**
|
||||
* How does B2G Loader Work?
|
||||
*
|
||||
* <<parent process>> <<child process>>
|
||||
* ProcLoaderParent -----> ProcLoaderChild
|
||||
* ^ |
|
||||
* | load() | content_process_main()
|
||||
* | V
|
||||
* ProcLoaderClient Nuwa/plugin-container
|
||||
* ^
|
||||
* | ProcLoaderLoad()
|
||||
* ...
|
||||
* ContentParent
|
||||
*
|
||||
*
|
||||
* B2G loader includes an IPC protocol PProcLoader for communication
|
||||
* between client (parent) and server (child). The b2g process is the
|
||||
* client. It requests the server to load/start the Nuwa process with
|
||||
* the given arguments, env variables, and file descriptors.
|
||||
*
|
||||
* ProcLoaderClientInit() is called by B2G loader to initialize the
|
||||
* client side, the b2g process. Then the b2g_main() is called to
|
||||
* start b2g process.
|
||||
*
|
||||
* ProcLoaderClientGeckoInit() is called by XRE_main() to create the
|
||||
* parent actor, |ProcLoaderParent|, of PProcLoader for servicing the
|
||||
* request to run Nuwa process later once Gecko has been initialized.
|
||||
*
|
||||
* ProcLoaderServiceRun() is called by the server process. It starts
|
||||
* an IOThread and event loop to serve the |ProcLoaderChild|
|
||||
* implmentation of PProcLoader protocol as the child actor. Once it
|
||||
* recieves a load() request, it stops the IOThread and event loop,
|
||||
* then starts running the main function of the content process with
|
||||
* the given arguments.
|
||||
*
|
||||
* NOTE: The server process serves at most one load() request.
|
||||
*/
|
||||
|
||||
using namespace base;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
static bool sProcLoaderClientOnDeinit = false;
|
||||
static DebugOnly<bool> sProcLoaderClientInitialized = false;
|
||||
static DebugOnly<bool> sProcLoaderClientGeckoInitialized = false;
|
||||
static pid_t sProcLoaderPid = 0;
|
||||
static int sProcLoaderChannelFd = -1;
|
||||
static PProcLoaderParent *sProcLoaderParent = nullptr;
|
||||
static MessageLoop *sProcLoaderLoop = nullptr;
|
||||
|
||||
static void ProcLoaderClientDeinit();
|
||||
|
||||
|
||||
class ProcLoaderParent : public PProcLoaderParent
|
||||
{
|
||||
private:
|
||||
nsAutoPtr<FileDescriptor> mChannelFd; // To keep a reference.
|
||||
|
||||
public:
|
||||
ProcLoaderParent(FileDescriptor *aFd) : mChannelFd(aFd) {}
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool RecvLoadComplete(const int32_t &aPid,
|
||||
const int32_t &aCookie) MOZ_OVERRIDE;
|
||||
|
||||
virtual void OnChannelError() MOZ_OVERRIDE;
|
||||
};
|
||||
|
||||
void
|
||||
ProcLoaderParent::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
_ProcLoaderParentDestroy(PProcLoaderParent *aLoader)
|
||||
{
|
||||
aLoader->Close();
|
||||
delete aLoader;
|
||||
sProcLoaderClientOnDeinit = false;
|
||||
}
|
||||
|
||||
bool
|
||||
ProcLoaderParent::RecvLoadComplete(const int32_t &aPid,
|
||||
const int32_t &aCookie)
|
||||
{
|
||||
ProcLoaderClientDeinit();
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ProcLoaderParent::OnChannelError()
|
||||
{
|
||||
if (sProcLoaderClientOnDeinit) {
|
||||
// Get error for closing while the channel is already error.
|
||||
return;
|
||||
}
|
||||
NS_WARNING("ProcLoaderParent is in channel error");
|
||||
ProcLoaderClientDeinit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the client of B2G loader for loader itself.
|
||||
*
|
||||
* The initialization of B2G loader are divided into two stages. First
|
||||
* stage is to collect child info passed from the main program of the
|
||||
* loader. Second stage is to initialize Gecko according to info from the
|
||||
* first stage and make the client of loader service ready.
|
||||
*
|
||||
* \param aPeerPid is the pid of the child.
|
||||
* \param aChannelFd is the file descriptor of the socket used for IPC.
|
||||
*/
|
||||
static void
|
||||
ProcLoaderClientInit(pid_t aPeerPid, int aChannelFd)
|
||||
{
|
||||
MOZ_ASSERT(!sProcLoaderClientInitialized, "call ProcLoaderClientInit() more than once");
|
||||
MOZ_ASSERT(aPeerPid != 0 && aChannelFd != -1, "invalid argument");
|
||||
sProcLoaderPid = aPeerPid;
|
||||
sProcLoaderChannelFd = aChannelFd;
|
||||
sProcLoaderClientInitialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the client of B2G loader for Gecko.
|
||||
*/
|
||||
void
|
||||
ProcLoaderClientGeckoInit()
|
||||
{
|
||||
MOZ_ASSERT(sProcLoaderClientInitialized, "call ProcLoaderClientInit() at first");
|
||||
MOZ_ASSERT(!sProcLoaderClientGeckoInitialized,
|
||||
"call ProcLoaderClientGeckoInit() more than once");
|
||||
|
||||
sProcLoaderClientGeckoInitialized = true;
|
||||
|
||||
FileDescriptor *fd = new FileDescriptor(sProcLoaderChannelFd);
|
||||
close(sProcLoaderChannelFd);
|
||||
sProcLoaderChannelFd = -1;
|
||||
Transport *transport = OpenDescriptor(*fd, Transport::MODE_CLIENT);
|
||||
sProcLoaderParent = new ProcLoaderParent(fd);
|
||||
sProcLoaderParent->Open(transport,
|
||||
sProcLoaderPid,
|
||||
XRE_GetIOMessageLoop(),
|
||||
ParentSide);
|
||||
sProcLoaderLoop = MessageLoop::current();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown and destroy the client of B2G loader service.
|
||||
*/
|
||||
static void
|
||||
ProcLoaderClientDeinit()
|
||||
{
|
||||
MOZ_ASSERT(sProcLoaderClientGeckoInitialized && sProcLoaderClientInitialized);
|
||||
sProcLoaderClientGeckoInitialized = false;
|
||||
sProcLoaderClientInitialized = false;
|
||||
|
||||
sProcLoaderClientOnDeinit = true;
|
||||
|
||||
MOZ_ASSERT(sProcLoaderParent != nullptr);
|
||||
PProcLoaderParent *procLoaderParent = sProcLoaderParent;
|
||||
sProcLoaderParent = nullptr;
|
||||
sProcLoaderLoop = nullptr;
|
||||
|
||||
MessageLoop::current()->
|
||||
PostTask(FROM_HERE,
|
||||
NewRunnableFunction(&_ProcLoaderParentDestroy,
|
||||
procLoaderParent));
|
||||
}
|
||||
|
||||
struct AsyncSendLoadData
|
||||
{
|
||||
nsTArray<nsCString> mArgv;
|
||||
nsTArray<nsCString> mEnv;
|
||||
nsTArray<FDRemap> mFdsremap;
|
||||
ChildPrivileges mPrivs;
|
||||
int mCookie;
|
||||
};
|
||||
|
||||
static void
|
||||
AsyncSendLoad(AsyncSendLoadData *aLoad)
|
||||
{
|
||||
PProcLoaderParent *loader = sProcLoaderParent;
|
||||
DebugOnly<bool> ok =
|
||||
loader->SendLoad(aLoad->mArgv, aLoad->mEnv, aLoad->mFdsremap,
|
||||
aLoad->mPrivs, aLoad->mCookie);
|
||||
MOZ_ASSERT(ok);
|
||||
delete aLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request the loader service, the server, to load Nuwa.
|
||||
*/
|
||||
bool
|
||||
ProcLoaderLoad(const char *aArgv[],
|
||||
const char *aEnvp[],
|
||||
const file_handle_mapping_vector &aFdsRemap,
|
||||
const ChildPrivileges aPrivs,
|
||||
ProcessHandle *aProcessHandle)
|
||||
{
|
||||
static int cookie=0;
|
||||
int i;
|
||||
|
||||
if (sProcLoaderParent == nullptr || sProcLoaderPid == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AsyncSendLoadData *load = new AsyncSendLoadData();
|
||||
nsTArray<nsCString> &argv = load->mArgv;
|
||||
for (i = 0; aArgv[i] != nullptr; i++) {
|
||||
argv.AppendElement(nsCString(aArgv[i]));
|
||||
}
|
||||
nsTArray<nsCString> &env = load->mEnv;
|
||||
for (i = 0; aEnvp[i] != nullptr; i++) {
|
||||
env.AppendElement(nsCString(aEnvp[i]));
|
||||
}
|
||||
nsTArray<FDRemap> &fdsremap = load->mFdsremap;
|
||||
for (file_handle_mapping_vector::const_iterator fdmap =
|
||||
aFdsRemap.begin();
|
||||
fdmap != aFdsRemap.end();
|
||||
fdmap++) {
|
||||
fdsremap.AppendElement(FDRemap(fdmap->first, fdmap->second));
|
||||
}
|
||||
load->mPrivs = aPrivs;
|
||||
load->mCookie = cookie++;
|
||||
|
||||
*aProcessHandle = sProcLoaderPid;
|
||||
sProcLoaderPid = 0;
|
||||
|
||||
sProcLoaderLoop->PostTask(FROM_HERE,
|
||||
NewRunnableFunction(AsyncSendLoad, load));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
class ProcLoaderRunnerBase;
|
||||
|
||||
static bool sProcLoaderServing = false;
|
||||
static ProcLoaderRunnerBase *sProcLoaderDispatchedTask = nullptr;
|
||||
|
||||
class ProcLoaderRunnerBase
|
||||
{
|
||||
public:
|
||||
virtual int DoWork() = 0;
|
||||
};
|
||||
|
||||
|
||||
class ProcLoaderNoopRunner : public ProcLoaderRunnerBase {
|
||||
public:
|
||||
virtual int DoWork();
|
||||
};
|
||||
|
||||
int
|
||||
ProcLoaderNoopRunner::DoWork() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The runner to load Nuwa at the current process.
|
||||
*/
|
||||
class ProcLoaderLoadRunner : public ProcLoaderRunnerBase {
|
||||
private:
|
||||
const nsTArray<nsCString> mArgv;
|
||||
const nsTArray<nsCString> mEnv;
|
||||
const nsTArray<FDRemap> mFdsRemap;
|
||||
const ChildPrivileges mPrivs;
|
||||
|
||||
void ShuffleFds();
|
||||
|
||||
public:
|
||||
ProcLoaderLoadRunner(const InfallibleTArray<nsCString>& aArgv,
|
||||
const InfallibleTArray<nsCString>& aEnv,
|
||||
const InfallibleTArray<FDRemap>& aFdsRemap,
|
||||
const ChildPrivileges aPrivs)
|
||||
: mArgv(aArgv)
|
||||
, mEnv(aEnv)
|
||||
, mFdsRemap(aFdsRemap)
|
||||
, mPrivs(aPrivs) {}
|
||||
|
||||
int DoWork();
|
||||
};
|
||||
|
||||
void
|
||||
ProcLoaderLoadRunner::ShuffleFds()
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
InjectiveMultimap fd_shuffle1, fd_shuffle2;
|
||||
fd_shuffle1.reserve(mFdsRemap.Length());
|
||||
fd_shuffle2.reserve(mFdsRemap.Length());
|
||||
for (i = 0; i < mFdsRemap.Length(); i++) {
|
||||
const FDRemap *map = &mFdsRemap[i];
|
||||
int fd = map->fd().PlatformHandle();
|
||||
int tofd = map->mapto();
|
||||
|
||||
fd_shuffle1.push_back(InjectionArc(fd, tofd, false));
|
||||
fd_shuffle2.push_back(InjectionArc(fd, tofd, false));
|
||||
}
|
||||
|
||||
DebugOnly<bool> ok = ShuffleFileDescriptors(&fd_shuffle1);
|
||||
MOZ_ASSERT(ok, "ShuffleFileDescriptors failed");
|
||||
|
||||
CloseSuperfluousFds(fd_shuffle2);
|
||||
}
|
||||
|
||||
int
|
||||
ProcLoaderLoadRunner::DoWork()
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
ShuffleFds();
|
||||
|
||||
unsigned int argc = mArgv.Length();
|
||||
char **argv = new char *[argc + 1];
|
||||
for (i = 0; i < argc; i++) {
|
||||
argv[i] = ::strdup(mArgv[i].get());
|
||||
}
|
||||
argv[argc] = nullptr;
|
||||
|
||||
unsigned int envc = mEnv.Length();
|
||||
for (i = 0; i < envc; i++) {
|
||||
PR_SetEnv(mEnv[i].get());
|
||||
}
|
||||
|
||||
SetCurrentProcessPrivileges(mPrivs);
|
||||
|
||||
MOZ_ASSERT(content_process_main != nullptr,
|
||||
"content_process_main not found");
|
||||
// Start Nuwa (main function)
|
||||
int ret = content_process_main(argc, argv);
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
free(argv[i]);
|
||||
}
|
||||
delete[] argv;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
class ProcLoaderChild : public PProcLoaderChild
|
||||
{
|
||||
pid_t mPeerPid;
|
||||
|
||||
public:
|
||||
ProcLoaderChild(pid_t aPeerPid) : mPeerPid(aPeerPid) {}
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool RecvLoad(const InfallibleTArray<nsCString>& aArgv,
|
||||
const InfallibleTArray<nsCString>& aEnv,
|
||||
const InfallibleTArray<FDRemap>& aFdsremap,
|
||||
const uint32_t& aPrivs,
|
||||
const int32_t& aCookie);
|
||||
|
||||
virtual void OnChannelError();
|
||||
};
|
||||
|
||||
void
|
||||
ProcLoaderChild::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
_ProcLoaderChildDestroy(ProcLoaderChild *aChild)
|
||||
{
|
||||
aChild->Close();
|
||||
delete aChild;
|
||||
MessageLoop::current()->Quit();
|
||||
}
|
||||
|
||||
bool
|
||||
ProcLoaderChild::RecvLoad(const InfallibleTArray<nsCString>& aArgv,
|
||||
const InfallibleTArray<nsCString>& aEnv,
|
||||
const InfallibleTArray<FDRemap>& aFdsRemap,
|
||||
const uint32_t& aPrivs,
|
||||
const int32_t& aCookie) {
|
||||
if (!sProcLoaderServing) {
|
||||
return true;
|
||||
}
|
||||
sProcLoaderServing = false;
|
||||
|
||||
MOZ_ASSERT(sProcLoaderDispatchedTask == nullptr);
|
||||
ChildPrivileges privs = static_cast<ChildPrivileges>(aPrivs);
|
||||
sProcLoaderDispatchedTask =
|
||||
new ProcLoaderLoadRunner(aArgv, aEnv, aFdsRemap, privs);
|
||||
|
||||
SendLoadComplete(mPeerPid, aCookie);
|
||||
|
||||
MessageLoop::current()->PostTask(FROM_HERE,
|
||||
NewRunnableFunction(_ProcLoaderChildDestroy,
|
||||
this));
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ProcLoaderChild::OnChannelError()
|
||||
{
|
||||
if (!sProcLoaderServing) {
|
||||
return;
|
||||
}
|
||||
sProcLoaderServing = false;
|
||||
|
||||
PProcLoaderChild::OnChannelError();
|
||||
|
||||
MOZ_ASSERT(sProcLoaderDispatchedTask == nullptr);
|
||||
sProcLoaderDispatchedTask = new ProcLoaderNoopRunner();
|
||||
|
||||
MessageLoop::current()->PostTask(FROM_HERE,
|
||||
NewRunnableFunction(_ProcLoaderChildDestroy,
|
||||
this));
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper class which calls NS_LogInit/NS_LogTerm in its scope.
|
||||
*/
|
||||
class ScopedLogging
|
||||
{
|
||||
public:
|
||||
ScopedLogging() { NS_LogInit(); }
|
||||
~ScopedLogging() { NS_LogTerm(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* Run service of ProcLoader.
|
||||
*
|
||||
* \param aPeerPid is the pid of the parent.
|
||||
* \param aFd is the file descriptor of the socket for IPC.
|
||||
*
|
||||
* See the comment near the head of this file.
|
||||
*/
|
||||
static int
|
||||
ProcLoaderServiceRun(pid_t aPeerPid, int aFd,
|
||||
int aArgc, const char *aArgv[])
|
||||
{
|
||||
ScopedLogging logging;
|
||||
|
||||
char **_argv;
|
||||
_argv = new char *[aArgc + 1];
|
||||
for (int i = 0; i < aArgc; i++) {
|
||||
_argv[i] = ::strdup(aArgv[i]);
|
||||
MOZ_ASSERT(_argv[i] != nullptr);
|
||||
}
|
||||
_argv[aArgc] = nullptr;
|
||||
|
||||
gArgv = _argv;
|
||||
gArgc = aArgc;
|
||||
|
||||
{
|
||||
gDisableAndroidLog = true;
|
||||
|
||||
nsresult rv = XRE_InitCommandLine(aArgc, _argv);
|
||||
if (NS_FAILED(rv)) {
|
||||
gDisableAndroidLog = false;
|
||||
MOZ_CRASH();
|
||||
}
|
||||
|
||||
FileDescriptor fd(aFd);
|
||||
close(aFd);
|
||||
|
||||
MOZ_ASSERT(!sProcLoaderServing);
|
||||
MessageLoop loop;
|
||||
|
||||
nsAutoPtr<ContentProcess> process;
|
||||
process = new ContentProcess(aPeerPid);
|
||||
ChildThread *iothread = process->child_thread();
|
||||
|
||||
Transport *transport = OpenDescriptor(fd, Transport::MODE_CLIENT);
|
||||
ProcLoaderChild *loaderChild = new ProcLoaderChild(aPeerPid);
|
||||
// Pass a message loop to initialize (connect) the channel
|
||||
// (connection).
|
||||
loaderChild->Open(transport, aPeerPid, iothread->message_loop());
|
||||
|
||||
BackgroundHangMonitor::Prohibit();
|
||||
|
||||
sProcLoaderServing = true;
|
||||
loop.Run();
|
||||
|
||||
BackgroundHangMonitor::Allow();
|
||||
|
||||
XRE_DeinitCommandLine();
|
||||
|
||||
gDisableAndroidLog = false;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(sProcLoaderDispatchedTask != nullptr);
|
||||
ProcLoaderRunnerBase *task = sProcLoaderDispatchedTask;
|
||||
sProcLoaderDispatchedTask = nullptr;
|
||||
int ret = task->DoWork();
|
||||
delete task;
|
||||
|
||||
for (int i = 0; i < aArgc; i++) {
|
||||
free(_argv[i]);
|
||||
}
|
||||
delete[] _argv;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* MOZ_B2G_LOADER */
|
||||
|
||||
} // namespace ipc
|
||||
} // namespace mozilla
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
void
|
||||
XRE_ProcLoaderClientInit(pid_t aPeerPid, int aChannelFd)
|
||||
{
|
||||
mozilla::ipc::ProcLoaderClientInit(aPeerPid, aChannelFd);
|
||||
}
|
||||
|
||||
int
|
||||
XRE_ProcLoaderServiceRun(pid_t aPeerPid, int aFd,
|
||||
int aArgc, const char *aArgv[])
|
||||
{
|
||||
return mozilla::ipc::ProcLoaderServiceRun(aPeerPid, aFd,
|
||||
aArgc, aArgv);
|
||||
}
|
||||
#endif /* MOZ_B2G_LOADER */
|
||||
|
|
|
@ -130,14 +130,12 @@ IPDL_SOURCES = [
|
|||
'PBackground.ipdl',
|
||||
'PBackgroundSharedTypes.ipdlh',
|
||||
'PBackgroundTest.ipdl',
|
||||
'PProcLoader.ipdl',
|
||||
'ProtocolTypes.ipdlh',
|
||||
'URIParams.ipdlh',
|
||||
]
|
||||
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/toolkit/xre',
|
||||
'/xpcom/threads',
|
||||
]
|
||||
|
||||
|
|
|
@ -26,7 +26,4 @@ if CONFIG['MOZ_B2G_RIL'] or CONFIG['MOZ_B2G_BT'] or CONFIG['MOZ_NFC'] or CONFIG[
|
|||
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
|
||||
DIRS += ['keystore', 'netd']
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android':
|
||||
DIRS += ['contentproc']
|
||||
|
||||
DIRS += ['app']
|
||||
|
|
|
@ -160,5 +160,3 @@ if CONFIG['MOZ_ENABLE_XREMOTE']:
|
|||
'/widget/xremoteclient',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_B2G_LOADER']:
|
||||
DEFINES['OMNIJAR_NAME'] = CONFIG['OMNIJAR_NAME']
|
||||
|
|
|
@ -185,10 +185,6 @@
|
|||
#include "GTestRunner.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
#include "ProcessUtils.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
#include "AndroidBridge.h"
|
||||
#endif
|
||||
|
@ -3776,10 +3772,6 @@ XREMain::XRE_mainRun()
|
|||
nsresult rv = NS_OK;
|
||||
NS_ASSERTION(mScopedXPCom, "Scoped xpcom not initialized.");
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
mozilla::ipc::ProcLoaderClientGeckoInit();
|
||||
#endif
|
||||
|
||||
#ifdef NS_FUNCTION_TIMER
|
||||
// initialize some common services, so we don't pay the cost for these at odd times later on;
|
||||
// SetWindowCreator -> ChromeRegistry -> IOService -> SocketTransportService -> (nspr wspm init), Prefs
|
||||
|
|
|
@ -81,11 +81,6 @@
|
|||
using mozilla::_ipdltest::IPDLUnitTestProcessChild;
|
||||
#endif // ifdef MOZ_IPDL_TESTS
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
#include "nsLocalFile.h"
|
||||
#include "nsXREAppData.h"
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
using mozilla::ipc::BrowserProcessSubThread;
|
||||
|
@ -820,38 +815,3 @@ XRE_GetWindowsEnvironment()
|
|||
}
|
||||
#endif // XP_WIN
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
extern const nsXREAppData* gAppData;
|
||||
|
||||
/**
|
||||
* Preload static data of Gecko for B2G loader.
|
||||
*
|
||||
* This function is supposed to be called before XPCOM is initialized.
|
||||
* For now, this function preloads
|
||||
* - XPT interface Information
|
||||
*/
|
||||
void
|
||||
XRE_ProcLoaderPreload(const char* aProgramDir, const nsXREAppData* aAppData)
|
||||
{
|
||||
void PreloadXPT(nsIFile *);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> omnijarFile;
|
||||
rv = NS_NewNativeLocalFile(nsCString(aProgramDir),
|
||||
true,
|
||||
getter_AddRefs(omnijarFile));
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
rv = omnijarFile->AppendNative(NS_LITERAL_CSTRING(NS_STRINGIFY(OMNIJAR_NAME)));
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
/*
|
||||
* gAppData is required by nsXULAppInfo. The manifest parser
|
||||
* evaluate flags with the information from nsXULAppInfo.
|
||||
*/
|
||||
gAppData = aAppData;
|
||||
|
||||
PreloadXPT(omnijarFile);
|
||||
|
||||
gAppData = nullptr;
|
||||
}
|
||||
#endif /* MOZ_B2G_LOADER */
|
||||
|
|
|
@ -878,10 +878,6 @@ void mozilla_sampler_unlock()
|
|||
|
||||
bool mozilla_sampler_register_thread(const char* aName, void* stackTop)
|
||||
{
|
||||
if (sInitCount == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(MOZ_WIDGET_GONK) && !defined(MOZ_PROFILING)
|
||||
// The only way to profile secondary threads on b2g
|
||||
// is to build with profiling OR have the profiler
|
||||
|
@ -899,10 +895,6 @@ bool mozilla_sampler_register_thread(const char* aName, void* stackTop)
|
|||
|
||||
void mozilla_sampler_unregister_thread()
|
||||
{
|
||||
if (sInitCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Sampler::UnregisterCurrentThread();
|
||||
|
||||
PseudoStack *stack = tlsPseudoStack.get();
|
||||
|
@ -914,10 +906,6 @@ void mozilla_sampler_unregister_thread()
|
|||
}
|
||||
|
||||
void mozilla_sampler_sleep_start() {
|
||||
if (sInitCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
PseudoStack *stack = tlsPseudoStack.get();
|
||||
if (stack == nullptr) {
|
||||
return;
|
||||
|
@ -926,10 +914,6 @@ void mozilla_sampler_sleep_start() {
|
|||
}
|
||||
|
||||
void mozilla_sampler_sleep_end() {
|
||||
if (sInitCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
PseudoStack *stack = tlsPseudoStack.get();
|
||||
if (stack == nullptr) {
|
||||
return;
|
||||
|
|
|
@ -101,13 +101,6 @@ Break(const char* aMsg);
|
|||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
/* Avoid calling Android logger/logd temporarily while running
|
||||
* B2GLoader to start the child process.
|
||||
*/
|
||||
bool gDisableAndroidLog = false;
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
static const char* sMultiprocessDescription = nullptr;
|
||||
|
@ -399,9 +392,6 @@ NS_DebugBreak(uint32_t aSeverity, const char* aStr, const char* aExpr,
|
|||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
if (!gDisableAndroidLog)
|
||||
#endif
|
||||
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", buf.buffer);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -467,16 +467,6 @@ XRE_API(WindowsEnvironmentType,
|
|||
XRE_GetWindowsEnvironment, ())
|
||||
#endif // XP_WIN
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
XRE_API(int,
|
||||
XRE_ProcLoaderServiceRun, (pid_t, int, int argc, const char *argv[]));
|
||||
XRE_API(void,
|
||||
XRE_ProcLoaderClientInit, (pid_t, int));
|
||||
XRE_API(void,
|
||||
XRE_ProcLoaderPreload, (const char* aProgramDir,
|
||||
const nsXREAppData* aAppData));
|
||||
#endif // MOZ_B2G_LOADER
|
||||
|
||||
XRE_API(int,
|
||||
XRE_XPCShellMain, (int argc, char** argv, char** envp))
|
||||
|
||||
|
|
|
@ -36,18 +36,6 @@
|
|||
#include "nsIScriptError.h"
|
||||
#include "nsIXULAppInfo.h"
|
||||
#include "nsIXULRuntime.h"
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
#include "mozilla/XPTInterfaceInfoManager.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
#define XPTONLY_MANIFEST &nsComponentManagerImpl::XPTOnlyManifestManifest
|
||||
#define XPTONLY_XPT &nsComponentManagerImpl::XPTOnlyManifestXPT
|
||||
#else
|
||||
#define XPTONLY_MANIFEST nullptr
|
||||
#define XPTONLY_XPT nullptr
|
||||
#endif
|
||||
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -76,43 +64,36 @@ struct ManifestDirective
|
|||
(nsChromeRegistry::ManifestProcessingContext& cx,
|
||||
int lineno, char *const *argv,
|
||||
bool platform, bool contentaccessible);
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
// The function to handle the directive for XPT Only parsing.
|
||||
void (*xptonlyfunc)(nsComponentManagerImpl::XPTOnlyManifestProcessingContext& cx,
|
||||
int lineno, char *const * argv);
|
||||
#else
|
||||
void *xptonlyfunc;
|
||||
#endif
|
||||
|
||||
bool isContract;
|
||||
};
|
||||
static const ManifestDirective kParsingTable[] = {
|
||||
{ "manifest", 1, false, true, true, false,
|
||||
&nsComponentManagerImpl::ManifestManifest, nullptr, XPTONLY_MANIFEST },
|
||||
&nsComponentManagerImpl::ManifestManifest, nullptr },
|
||||
{ "binary-component", 1, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestBinaryComponent, nullptr, nullptr },
|
||||
&nsComponentManagerImpl::ManifestBinaryComponent, nullptr },
|
||||
{ "interfaces", 1, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestXPT, nullptr, XPTONLY_XPT },
|
||||
&nsComponentManagerImpl::ManifestXPT, nullptr },
|
||||
{ "component", 2, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestComponent, nullptr, nullptr },
|
||||
&nsComponentManagerImpl::ManifestComponent, nullptr },
|
||||
{ "contract", 2, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestContract, nullptr, nullptr, true},
|
||||
&nsComponentManagerImpl::ManifestContract, nullptr, true},
|
||||
{ "category", 3, true, false, false, false,
|
||||
&nsComponentManagerImpl::ManifestCategory, nullptr, nullptr },
|
||||
&nsComponentManagerImpl::ManifestCategory, nullptr },
|
||||
{ "content", 2, true, true, true, true,
|
||||
nullptr, &nsChromeRegistry::ManifestContent, nullptr },
|
||||
nullptr, &nsChromeRegistry::ManifestContent },
|
||||
{ "locale", 3, true, true, true, false,
|
||||
nullptr, &nsChromeRegistry::ManifestLocale, nullptr },
|
||||
nullptr, &nsChromeRegistry::ManifestLocale },
|
||||
{ "skin", 3, false, true, true, false,
|
||||
nullptr, &nsChromeRegistry::ManifestSkin, nullptr },
|
||||
nullptr, &nsChromeRegistry::ManifestSkin },
|
||||
{ "overlay", 2, true, true, false, false,
|
||||
nullptr, &nsChromeRegistry::ManifestOverlay, nullptr },
|
||||
nullptr, &nsChromeRegistry::ManifestOverlay },
|
||||
{ "style", 2, false, true, false, false,
|
||||
nullptr, &nsChromeRegistry::ManifestStyle, nullptr },
|
||||
nullptr, &nsChromeRegistry::ManifestStyle },
|
||||
{ "override", 2, true, true, true, false,
|
||||
nullptr, &nsChromeRegistry::ManifestOverride, nullptr },
|
||||
nullptr, &nsChromeRegistry::ManifestOverride },
|
||||
{ "resource", 2, true, true, false, false,
|
||||
nullptr, &nsChromeRegistry::ManifestResource, nullptr }
|
||||
nullptr, &nsChromeRegistry::ManifestResource }
|
||||
};
|
||||
|
||||
static const char kWhitespace[] = "\t ";
|
||||
|
@ -145,16 +126,8 @@ struct AutoPR_smprintf_free
|
|||
|
||||
} // anonymous namespace
|
||||
|
||||
/**
|
||||
* If we are pre-loading XPTs, this method may do nothing because the
|
||||
* console service is not initialized.
|
||||
*/
|
||||
void LogMessage(const char* aMsg, ...)
|
||||
{
|
||||
if (!nsComponentManagerImpl::gComponentManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIConsoleService> console =
|
||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||
if (!console)
|
||||
|
@ -170,10 +143,6 @@ void LogMessage(const char* aMsg, ...)
|
|||
console->LogMessage(error);
|
||||
}
|
||||
|
||||
/**
|
||||
* If we are pre-loading XPTs, this method may do nothing because the
|
||||
* console service is not initialized.
|
||||
*/
|
||||
void LogMessageWithContext(FileLocation &aFile,
|
||||
uint32_t aLineNumber, const char* aMsg, ...)
|
||||
{
|
||||
|
@ -184,10 +153,6 @@ void LogMessageWithContext(FileLocation &aFile,
|
|||
if (!formatted)
|
||||
return;
|
||||
|
||||
if (!nsComponentManagerImpl::gComponentManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCString file;
|
||||
aFile.GetURIString(file);
|
||||
|
||||
|
@ -423,23 +388,11 @@ struct CachedDirective
|
|||
} // anonymous namespace
|
||||
|
||||
|
||||
/**
|
||||
* For XPT-Only mode, the parser handles only directives of "manifest"
|
||||
* and "interfaces", and always call the function given by |xptonlyfunc|
|
||||
* variable of struct |ManifestDirective|.
|
||||
*
|
||||
* This function is safe to be called before the component manager is
|
||||
* ready if aXPTOnly is true for it don't invoke any component during
|
||||
* parsing.
|
||||
*/
|
||||
void
|
||||
ParseManifest(NSLocationType type, FileLocation &file, char* buf, bool aChromeOnly, bool aXPTOnly)
|
||||
ParseManifest(NSLocationType type, FileLocation &file, char* buf, bool aChromeOnly)
|
||||
{
|
||||
nsComponentManagerImpl::ManifestProcessingContext mgrcx(type, file, aChromeOnly);
|
||||
nsChromeRegistry::ManifestProcessingContext chromecx(type, file);
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
nsComponentManagerImpl::XPTOnlyManifestProcessingContext xptonlycx(file);
|
||||
#endif
|
||||
nsresult rv;
|
||||
|
||||
NS_NAMED_LITERAL_STRING(kPlatform, "platform");
|
||||
|
@ -463,12 +416,7 @@ ParseManifest(NSLocationType type, FileLocation &file, char* buf, bool aChromeOn
|
|||
nsAutoString osTarget;
|
||||
nsAutoString abi;
|
||||
|
||||
nsCOMPtr<nsIXULAppInfo> xapp;
|
||||
if (!aXPTOnly) {
|
||||
// Avoid to create any component for XPT only mode.
|
||||
// No xapp means no ID, version, ..., modifiers checking.
|
||||
xapp = do_GetService(XULAPPINFO_SERVICE_CONTRACTID);
|
||||
}
|
||||
nsCOMPtr<nsIXULAppInfo> xapp (do_GetService(XULAPPINFO_SERVICE_CONTRACTID));
|
||||
if (xapp) {
|
||||
nsAutoCString s;
|
||||
rv = xapp->GetID(s);
|
||||
|
@ -568,10 +516,9 @@ ParseManifest(NSLocationType type, FileLocation &file, char* buf, bool aChromeOn
|
|||
for (const ManifestDirective* d = kParsingTable;
|
||||
d < ArrayEnd(kParsingTable);
|
||||
++d) {
|
||||
if (!strcmp(d->directive, token) &&
|
||||
(!aXPTOnly || d->xptonlyfunc)) {
|
||||
directive = d;
|
||||
break;
|
||||
if (!strcmp(d->directive, token)) {
|
||||
directive = d;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -630,9 +577,8 @@ ParseManifest(NSLocationType type, FileLocation &file, char* buf, bool aChromeOn
|
|||
CheckStringFlag(kABI, wtoken, abi, stABI) ||
|
||||
CheckVersionFlag(kOsVersion, wtoken, osVersion, stOsVersion) ||
|
||||
CheckVersionFlag(kAppVersion, wtoken, appVersion, stAppVersion) ||
|
||||
CheckVersionFlag(kGeckoVersion, wtoken, geckoVersion, stGeckoVersion)) {
|
||||
CheckVersionFlag(kGeckoVersion, wtoken, geckoVersion, stGeckoVersion))
|
||||
continue;
|
||||
}
|
||||
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
bool tablet = false;
|
||||
|
@ -673,11 +619,6 @@ ParseManifest(NSLocationType type, FileLocation &file, char* buf, bool aChromeOn
|
|||
stABI == eBad)
|
||||
continue;
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
if (aXPTOnly) {
|
||||
directive->xptonlyfunc(xptonlycx, line, argv);
|
||||
} else
|
||||
#endif /* MOZ_B2G_LOADER */
|
||||
if (directive->regfunc) {
|
||||
if (GeckoProcessType_Default != XRE_GetProcessType())
|
||||
continue;
|
||||
|
@ -695,7 +636,7 @@ ParseManifest(NSLocationType type, FileLocation &file, char* buf, bool aChromeOn
|
|||
(nsChromeRegistry::gChromeRegistry->*(directive->regfunc))
|
||||
(chromecx, line, argv, platform, contentAccessible);
|
||||
}
|
||||
else if (directive->mgrfunc && (directive->ischrome || !aChromeOnly)) {
|
||||
else if (directive->ischrome || !aChromeOnly) {
|
||||
if (directive->isContract) {
|
||||
CachedDirective* cd = contracts.AppendElement();
|
||||
cd->lineno = line;
|
||||
|
@ -705,9 +646,6 @@ ParseManifest(NSLocationType type, FileLocation &file, char* buf, bool aChromeOn
|
|||
else
|
||||
(nsComponentManagerImpl::gComponentManager->*(directive->mgrfunc))
|
||||
(mgrcx, line, argv);
|
||||
} else {
|
||||
LogMessageWithContext(file, line,
|
||||
"No valid manifest directive.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
class nsIFile;
|
||||
|
||||
void ParseManifest(NSLocationType type, mozilla::FileLocation &file,
|
||||
char* buf, bool aChromeOnly, bool aXPTOnly=false);
|
||||
char* buf, bool aChromeOnly);
|
||||
|
||||
void LogMessage(const char* aMsg, ...);
|
||||
|
||||
|
|
|
@ -69,7 +69,6 @@
|
|||
#include "nsStringEnumerator.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsDataHashtable.h"
|
||||
|
||||
#include <new> // for placement new
|
||||
|
||||
|
@ -105,36 +104,6 @@ NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
|
|||
|
||||
#define UID_STRING_LENGTH 39
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
typedef nsDataHashtable<nsCStringHashKey, bool> XPTIInfosBookType;
|
||||
static XPTIInfosBookType *sXPTIInfosBook = nullptr;
|
||||
|
||||
static XPTIInfosBookType *
|
||||
GetXPTIInfosBook()
|
||||
{
|
||||
if (sXPTIInfosBook == nullptr) {
|
||||
sXPTIInfosBook = new XPTIInfosBookType;
|
||||
}
|
||||
return sXPTIInfosBook;
|
||||
}
|
||||
|
||||
static bool
|
||||
IsRegisteredXPTIInfo(FileLocation &aFile)
|
||||
{
|
||||
nsAutoCString uri;
|
||||
aFile.GetURIString(uri);
|
||||
return GetXPTIInfosBook()->Get(uri);
|
||||
}
|
||||
|
||||
static void
|
||||
MarkRegisteredXPTIInfo(FileLocation &aFile)
|
||||
{
|
||||
nsAutoCString uri;
|
||||
aFile.GetURIString(uri);
|
||||
GetXPTIInfosBook()->Put(uri, true);
|
||||
}
|
||||
#endif /* MOZ_B2G_LOADER */
|
||||
|
||||
nsresult
|
||||
nsGetServiceFromCategory::operator()(const nsIID& aIID, void** aInstancePtr) const
|
||||
{
|
||||
|
@ -555,14 +524,11 @@ CutExtension(nsCString& path)
|
|||
path.Cut(0, dotPos + 1);
|
||||
}
|
||||
|
||||
static void
|
||||
DoRegisterManifest(NSLocationType aType,
|
||||
FileLocation &aFile,
|
||||
bool aChromeOnly,
|
||||
bool aXPTOnly)
|
||||
void
|
||||
nsComponentManagerImpl::RegisterManifest(NSLocationType aType,
|
||||
FileLocation &aFile,
|
||||
bool aChromeOnly)
|
||||
{
|
||||
MOZ_ASSERT(!aXPTOnly ||
|
||||
nsComponentManagerImpl::gComponentManager == nullptr);
|
||||
uint32_t len;
|
||||
FileLocation::Data data;
|
||||
nsAutoArrayPtr<char> buf;
|
||||
|
@ -576,7 +542,7 @@ DoRegisterManifest(NSLocationType aType,
|
|||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
buf[len] = '\0';
|
||||
ParseManifest(aType, aFile, buf, aChromeOnly, aXPTOnly);
|
||||
ParseManifest(aType, aFile, buf, aChromeOnly);
|
||||
} else if (NS_BOOTSTRAPPED_LOCATION != aType) {
|
||||
nsCString uri;
|
||||
aFile.GetURIString(uri);
|
||||
|
@ -584,14 +550,6 @@ DoRegisterManifest(NSLocationType aType,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsComponentManagerImpl::RegisterManifest(NSLocationType aType,
|
||||
FileLocation &aFile,
|
||||
bool aChromeOnly)
|
||||
{
|
||||
DoRegisterManifest(aType, aFile, aChromeOnly, false);
|
||||
}
|
||||
|
||||
void
|
||||
nsComponentManagerImpl::ManifestManifest(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
||||
{
|
||||
|
@ -629,19 +587,14 @@ nsComponentManagerImpl::ManifestBinaryComponent(ManifestProcessingContext& cx, i
|
|||
RegisterModule(m, &f);
|
||||
}
|
||||
|
||||
static void
|
||||
DoRegisterXPT(FileLocation &aFile)
|
||||
void
|
||||
nsComponentManagerImpl::ManifestXPT(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
||||
{
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
if (IsRegisteredXPTIInfo(aFile)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
FileLocation f(cx.mFile, argv[0]);
|
||||
uint32_t len;
|
||||
FileLocation::Data data;
|
||||
nsAutoArrayPtr<char> buf;
|
||||
nsresult rv = aFile.GetData(data);
|
||||
nsresult rv = f.GetData(data);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = data.GetSize(&len);
|
||||
}
|
||||
|
@ -651,23 +604,13 @@ DoRegisterXPT(FileLocation &aFile)
|
|||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
XPTInterfaceInfoManager::GetSingleton()->RegisterBuffer(buf, len);
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
MarkRegisteredXPTIInfo(aFile);
|
||||
#endif
|
||||
} else {
|
||||
nsCString uri;
|
||||
aFile.GetURIString(uri);
|
||||
f.GetURIString(uri);
|
||||
LogMessage("Could not read '%s'.", uri.get());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsComponentManagerImpl::ManifestXPT(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
||||
{
|
||||
FileLocation f(cx.mFile, argv[0]);
|
||||
DoRegisterXPT(f);
|
||||
}
|
||||
|
||||
void
|
||||
nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
||||
{
|
||||
|
@ -851,10 +794,6 @@ nsresult nsComponentManagerImpl::Shutdown(void)
|
|||
|
||||
delete sStaticModules;
|
||||
delete sModuleLocations;
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
delete sXPTIInfosBook;
|
||||
sXPTIInfosBook = nullptr;
|
||||
#endif
|
||||
|
||||
// Unload libraries
|
||||
mNativeModuleLoader.UnloadLibraries();
|
||||
|
@ -2003,54 +1942,6 @@ nsComponentManagerImpl::GetManifestLocations(nsIArray **aLocations)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsComponentManagerImpl::XPTOnlyManifestManifest(XPTOnlyManifestProcessingContext &aCx,
|
||||
int aLineno,
|
||||
char * const * aArgv)
|
||||
{
|
||||
char* file = aArgv[0];
|
||||
FileLocation f(aCx.mFile, file);
|
||||
|
||||
DoRegisterManifest(NS_COMPONENT_LOCATION, f, false, true);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsComponentManagerImpl::XPTOnlyManifestXPT(XPTOnlyManifestProcessingContext &aCx,
|
||||
int aLineno,
|
||||
char * const * aArgv)
|
||||
{
|
||||
FileLocation f(aCx.mFile, aArgv[0]);
|
||||
DoRegisterXPT(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* To load XPT Interface Information before the component manager is ready.
|
||||
*
|
||||
* With this function, B2G loader could XPT interface info. as earier
|
||||
* as possible to gain benefit of shared memory model of the kernel.
|
||||
*/
|
||||
/* static */ void
|
||||
nsComponentManagerImpl::PreloadXPT(nsIFile *aFile)
|
||||
{
|
||||
MOZ_ASSERT(nsComponentManagerImpl::gComponentManager == nullptr);
|
||||
FileLocation location(aFile, "chrome.manifest");
|
||||
|
||||
DoRegisterManifest(NS_COMPONENT_LOCATION, location,
|
||||
false, true /* aXPTOnly */);
|
||||
}
|
||||
|
||||
void
|
||||
PreloadXPT(nsIFile *aOmnijarFile)
|
||||
{
|
||||
nsComponentManagerImpl::PreloadXPT(aOmnijarFile);
|
||||
}
|
||||
|
||||
#endif /* MOZ_B2G_LOADER */
|
||||
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
XRE_AddManifestLocation(NSLocationType aType, nsIFile* aLocation)
|
||||
{
|
||||
|
|
|
@ -38,10 +38,6 @@
|
|||
#include "mozilla/Omnijar.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
#include "mozilla/FileLocation.h"
|
||||
#endif
|
||||
|
||||
struct nsFactoryEntry;
|
||||
class nsIServiceManager;
|
||||
struct PRThread;
|
||||
|
@ -320,30 +316,6 @@ public:
|
|||
|
||||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
// Preload XPT interface info for B2G loader.
|
||||
// This function is called before XPCOM has been initialized.
|
||||
static void PreloadXPT(nsIFile *aFile);
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
// Parsing functions of directives of manifest for XPT only parsing.
|
||||
struct XPTOnlyManifestProcessingContext
|
||||
{
|
||||
XPTOnlyManifestProcessingContext(mozilla::FileLocation &aFile)
|
||||
: mFile(aFile)
|
||||
{ }
|
||||
|
||||
~XPTOnlyManifestProcessingContext() { }
|
||||
|
||||
mozilla::FileLocation mFile;
|
||||
};
|
||||
static void XPTOnlyManifestManifest(XPTOnlyManifestProcessingContext& aCx,
|
||||
int aLineno, char * const *aArgv);
|
||||
static void XPTOnlyManifestXPT(XPTOnlyManifestProcessingContext& aCx,
|
||||
int aLineno, char * const *aArgv);
|
||||
#endif
|
||||
|
||||
private:
|
||||
~nsComponentManagerImpl();
|
||||
};
|
||||
|
|
|
@ -65,7 +65,6 @@ private:
|
|||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BackgroundHangManager)
|
||||
static StaticRefPtr<BackgroundHangManager> sInstance;
|
||||
static bool sProhibited;
|
||||
|
||||
// Lock for access to members of this class
|
||||
Monitor mLock;
|
||||
|
@ -163,7 +162,6 @@ public:
|
|||
|
||||
|
||||
StaticRefPtr<BackgroundHangManager> BackgroundHangManager::sInstance;
|
||||
bool BackgroundHangManager::sProhibited = false;
|
||||
|
||||
ThreadLocal<BackgroundHangThread*> BackgroundHangThread::sTlsKey;
|
||||
|
||||
|
@ -411,16 +409,8 @@ BackgroundHangThread*
|
|||
BackgroundHangThread::FindThread()
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
if (BackgroundHangManager::sInstance == nullptr) {
|
||||
MOZ_ASSERT(BackgroundHangManager::sProhibited,
|
||||
"BackgroundHandleManager is not initialized");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (sTlsKey.initialized()) {
|
||||
// Use TLS if available
|
||||
MOZ_ASSERT(!BackgroundHangManager::sProhibited,
|
||||
"BackgroundHandleManager is not initialized");
|
||||
return sTlsKey.get();
|
||||
}
|
||||
// If TLS is unavailable, we can search through the thread list
|
||||
|
@ -446,7 +436,6 @@ void
|
|||
BackgroundHangMonitor::Startup()
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
MOZ_ASSERT(!BackgroundHangManager::sProhibited, "Prohibited");
|
||||
MOZ_ASSERT(!BackgroundHangManager::sInstance, "Already initialized");
|
||||
ThreadStackHelper::Startup();
|
||||
BackgroundHangThread::Startup();
|
||||
|
@ -458,7 +447,6 @@ void
|
|||
BackgroundHangMonitor::Shutdown()
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
MOZ_ASSERT(!BackgroundHangManager::sProhibited, "Prohibited");
|
||||
MOZ_ASSERT(BackgroundHangManager::sInstance, "Not initialized");
|
||||
/* Scope our lock inside Shutdown() because the sInstance object can
|
||||
be destroyed as soon as we set sInstance to nullptr below, and
|
||||
|
@ -475,8 +463,7 @@ BackgroundHangMonitor::BackgroundHangMonitor(const char* aName,
|
|||
: mThread(BackgroundHangThread::FindThread())
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
if (!BackgroundHangManager::sProhibited && !mThread) {
|
||||
// If sProhibit is true, mThread would be null, and no monitoring.
|
||||
if (!mThread) {
|
||||
mThread = new BackgroundHangThread(aName, aTimeoutMs, aMaxTimeoutMs);
|
||||
}
|
||||
#endif
|
||||
|
@ -486,8 +473,7 @@ BackgroundHangMonitor::BackgroundHangMonitor()
|
|||
: mThread(BackgroundHangThread::FindThread())
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
MOZ_ASSERT(!BackgroundHangManager::sProhibited || mThread,
|
||||
"This thread is not initialized for hang monitoring");
|
||||
MOZ_ASSERT(mThread, "Thread not initialized for hang monitoring");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -499,11 +485,6 @@ void
|
|||
BackgroundHangMonitor::NotifyActivity()
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
if (mThread == nullptr) {
|
||||
MOZ_ASSERT(BackgroundHangManager::sProhibited,
|
||||
"This thread is not initialized for hang monitoring");
|
||||
return;
|
||||
}
|
||||
mThread->NotifyActivity();
|
||||
#endif
|
||||
}
|
||||
|
@ -512,49 +493,18 @@ void
|
|||
BackgroundHangMonitor::NotifyWait()
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
if (mThread == nullptr) {
|
||||
MOZ_ASSERT(BackgroundHangManager::sProhibited,
|
||||
"This thread is not initialized for hang monitoring");
|
||||
return;
|
||||
}
|
||||
mThread->NotifyWait();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
BackgroundHangMonitor::Prohibit()
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
MOZ_ASSERT(BackgroundHangManager::sInstance == nullptr,
|
||||
"The background hang monitor is already initialized");
|
||||
BackgroundHangManager::sProhibited = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
BackgroundHangMonitor::Allow()
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
MOZ_ASSERT(BackgroundHangManager::sInstance == nullptr,
|
||||
"The background hang monitor is already initialized");
|
||||
BackgroundHangManager::sProhibited = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Because we are iterating through the BackgroundHangThread linked list,
|
||||
we need to take a lock. Using MonitorAutoLock as a base class makes
|
||||
sure all of that is taken care of for us. */
|
||||
BackgroundHangMonitor::ThreadHangStatsIterator::ThreadHangStatsIterator()
|
||||
: MonitorAutoLock(BackgroundHangManager::sInstance->mLock)
|
||||
, mThread(BackgroundHangManager::sInstance ?
|
||||
BackgroundHangManager::sInstance->mHangThreads.getFirst() :
|
||||
nullptr)
|
||||
, mThread(BackgroundHangManager::sInstance->mHangThreads.getFirst())
|
||||
{
|
||||
#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
|
||||
MOZ_ASSERT(BackgroundHangManager::sInstance || BackgroundHangManager::sProhibited,
|
||||
"Inconsistent state");
|
||||
#endif
|
||||
}
|
||||
|
||||
Telemetry::ThreadHangStats*
|
||||
|
|
|
@ -107,8 +107,6 @@ class BackgroundHangThread;
|
|||
* }
|
||||
* }
|
||||
*
|
||||
* Prohibit() and Allow() make the background hang monitor work safely
|
||||
* before Startup().
|
||||
*/
|
||||
class BackgroundHangMonitor
|
||||
{
|
||||
|
@ -206,27 +204,6 @@ public:
|
|||
* NotifyActivity when subsequently exiting the wait state.
|
||||
*/
|
||||
void NotifyWait();
|
||||
|
||||
/**
|
||||
* Prohibit the hang monitor from activating.
|
||||
*
|
||||
* Startup() should not be called between Prohibit() and Allow().
|
||||
* This function makes the background hang monitor stop monitoring
|
||||
* threads.
|
||||
*
|
||||
* Prohibit() and Allow() can be called before XPCOM is ready. If
|
||||
* we don't stop monitoring threads it could case errors.
|
||||
*/
|
||||
static void Prohibit();
|
||||
|
||||
/**
|
||||
* Allow the hang monitor to run.
|
||||
*
|
||||
* Allow() and Prohibit() should be called in pair.
|
||||
*
|
||||
* \see Prohibit()
|
||||
*/
|
||||
static void Allow();
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
Загрузка…
Ссылка в новой задаче