mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-27 19:07:31 +09:00
[PALEMOON] Steal Basilisk's nsBrowserApp
This commit is contained in:
parent
8ba0d446a1
commit
32277773cb
2 changed files with 162 additions and 206 deletions
|
|
@ -7,10 +7,7 @@
|
||||||
DIRS += ['profile/extensions']
|
DIRS += ['profile/extensions']
|
||||||
|
|
||||||
|
|
||||||
if CONFIG['OS_ARCH'] == 'WINNT' and CONFIG['MOZ_ASAN']:
|
|
||||||
GeckoProgram(CONFIG['MOZ_APP_NAME'])
|
GeckoProgram(CONFIG['MOZ_APP_NAME'])
|
||||||
else:
|
|
||||||
GeckoProgram(CONFIG['MOZ_APP_NAME'], msvcrt='static')
|
|
||||||
|
|
||||||
JS_PREFERENCE_FILES += [
|
JS_PREFERENCE_FILES += [
|
||||||
'profile/palemoon.js',
|
'profile/palemoon.js',
|
||||||
|
|
@ -30,12 +27,6 @@ FINAL_TARGET_FILES.defaults.profile += ['profile/prefs.js']
|
||||||
|
|
||||||
DEFINES['APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
|
DEFINES['APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
|
||||||
|
|
||||||
for var in ('MOZILLA_OFFICIAL', 'LIBXUL_SDK'):
|
|
||||||
if CONFIG[var]:
|
|
||||||
DEFINES[var] = True
|
|
||||||
|
|
||||||
DEFINES['XPCOM_GLUE'] = True
|
|
||||||
|
|
||||||
LOCAL_INCLUDES += [
|
LOCAL_INCLUDES += [
|
||||||
'!/build',
|
'!/build',
|
||||||
]
|
]
|
||||||
|
|
@ -46,11 +37,9 @@ LOCAL_INCLUDES += [
|
||||||
'/xpcom/build',
|
'/xpcom/build',
|
||||||
]
|
]
|
||||||
|
|
||||||
DELAYLOAD_DLLS += [
|
USE_LIBS += [
|
||||||
'mozglue.dll',
|
'mozglue',
|
||||||
]
|
]
|
||||||
USE_STATIC_LIBS = True
|
|
||||||
|
|
||||||
|
|
||||||
if CONFIG['_MSC_VER']:
|
if CONFIG['_MSC_VER']:
|
||||||
# Always enter a Windows program through wmain, whether or not we're
|
# Always enter a Windows program through wmain, whether or not we're
|
||||||
|
|
@ -72,16 +61,6 @@ if CONFIG['OS_ARCH'] == 'WINNT':
|
||||||
if CONFIG['OS_ARCH'] == 'WINNT' and not CONFIG['GNU_CC']:
|
if CONFIG['OS_ARCH'] == 'WINNT' and not CONFIG['GNU_CC']:
|
||||||
LDFLAGS += ['/HEAP:0x40000']
|
LDFLAGS += ['/HEAP:0x40000']
|
||||||
|
|
||||||
if CONFIG['OS_ARCH'] == 'WINNT':
|
|
||||||
USE_LIBS += [
|
|
||||||
'mozglue',
|
|
||||||
'xpcomglue_staticruntime',
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
USE_LIBS += [
|
|
||||||
'xpcomglue',
|
|
||||||
]
|
|
||||||
|
|
||||||
DISABLE_STL_WRAPPING = True
|
DISABLE_STL_WRAPPING = True
|
||||||
|
|
||||||
if CONFIG['MOZ_LINKER']:
|
if CONFIG['MOZ_LINKER']:
|
||||||
|
|
|
||||||
|
|
@ -8,25 +8,13 @@
|
||||||
#include "application.ini.h"
|
#include "application.ini.h"
|
||||||
#include "nsXPCOMGlue.h"
|
#include "nsXPCOMGlue.h"
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
#undef _WIN32_WINNT
|
|
||||||
#define _WIN32_WINNT 0x0600
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winbase.h>
|
|
||||||
#include <VersionHelpers.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <io.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#elif defined(XP_UNIX)
|
#elif defined(XP_UNIX)
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XP_MACOSX
|
|
||||||
#include <mach/mach_time.h>
|
|
||||||
#include "MacQuirks.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
@ -35,20 +23,31 @@
|
||||||
#include "nsIFile.h"
|
#include "nsIFile.h"
|
||||||
#include "nsStringGlue.h"
|
#include "nsStringGlue.h"
|
||||||
|
|
||||||
// Easy access to a five second startup delay used to get
|
|
||||||
// a debugger attached in the metro environment.
|
|
||||||
// #define DEBUG_delay_start_metro
|
|
||||||
|
|
||||||
#ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
// we want a wmain entry point
|
#ifdef MOZ_ASAN
|
||||||
#include "nsWindowsWMain.cpp"
|
// ASAN requires palemoon.exe to be built with -MD, and it's OK if we don't
|
||||||
#define snprintf _snprintf
|
// support Windows XP SP2 in ASAN builds.
|
||||||
|
#define XRE_DONT_SUPPORT_XPSP2
|
||||||
|
#endif
|
||||||
|
#define XRE_WANT_ENVIRON
|
||||||
#define strcasecmp _stricmp
|
#define strcasecmp _stricmp
|
||||||
|
#ifdef MOZ_SANDBOX
|
||||||
|
#include "mozilla/sandboxing/SandboxInitialization.h"
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include "BinaryPath.h"
|
#include "BinaryPath.h"
|
||||||
|
|
||||||
#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
|
#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
|
||||||
#include "mozilla/StartupTimeline.h"
|
|
||||||
|
#include "mozilla/Sprintf.h"
|
||||||
|
#include "mozilla/Telemetry.h"
|
||||||
|
#include "mozilla/WindowsDllBlocklist.h"
|
||||||
|
|
||||||
|
#if !defined(MOZ_WIDGET_COCOA) && !defined(MOZ_WIDGET_ANDROID) \
|
||||||
|
&& !(defined(XP_LINUX) && defined(MOZ_SANDBOX))
|
||||||
|
#define MOZ_BROWSER_CAN_BE_CONTENTPROC
|
||||||
|
#include "../../ipc/contentproc/plugin-container.cpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
|
|
@ -56,12 +55,6 @@ using namespace mozilla;
|
||||||
#define kOSXResourcesFolder "Resources"
|
#define kOSXResourcesFolder "Resources"
|
||||||
#endif
|
#endif
|
||||||
#define kDesktopFolder "browser"
|
#define kDesktopFolder "browser"
|
||||||
#define kMetroFolder "metro"
|
|
||||||
#define kMetroAppIniFilename "metroapp.ini"
|
|
||||||
#ifdef XP_WIN
|
|
||||||
#define kMetroTestFile "tests.ini"
|
|
||||||
const char* kMetroConsoleIdParam = "testconsoleid=";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void Output(const char *fmt, ... )
|
static void Output(const char *fmt, ... )
|
||||||
{
|
{
|
||||||
|
|
@ -84,10 +77,19 @@ static void Output(const char *fmt, ... )
|
||||||
#if MOZ_WINCONSOLE
|
#if MOZ_WINCONSOLE
|
||||||
fwprintf_s(stderr, wide_msg);
|
fwprintf_s(stderr, wide_msg);
|
||||||
#else
|
#else
|
||||||
MessageBoxW(nullptr,
|
// Linking user32 at load-time interferes with the DLL blocklist (bug 932100).
|
||||||
wide_msg,
|
// This is a rare codepath, so we can load user32 at run-time instead.
|
||||||
L"Pale Moon",
|
HMODULE user32 = LoadLibraryW(L"user32.dll");
|
||||||
MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
|
if (user32) {
|
||||||
|
decltype(MessageBoxW)* messageBoxW =
|
||||||
|
(decltype(MessageBoxW)*) GetProcAddress(user32, "MessageBoxW");
|
||||||
|
if (messageBoxW) {
|
||||||
|
messageBoxW(nullptr, wide_msg, L"Pale Moon", MB_OK
|
||||||
|
| MB_ICONERROR
|
||||||
|
| MB_SETFOREGROUND);
|
||||||
|
}
|
||||||
|
FreeLibrary(user32);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -114,76 +116,60 @@ static bool IsArg(const char* arg, const char* s)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef XP_WIN
|
|
||||||
/*
|
|
||||||
* AttachToTestHarness - Windows helper for when we are running
|
|
||||||
* in the immersive environment. Firefox is launched by Windows in
|
|
||||||
* response to a request by metrotestharness, which is launched by
|
|
||||||
* runtests.py. As such stdout in fx doesn't point to the right
|
|
||||||
* stream. This helper touches up stdout such that test output gets
|
|
||||||
* routed to a named pipe metrotestharness creates and dumps to its
|
|
||||||
* stdout.
|
|
||||||
*/
|
|
||||||
static void AttachToTestHarness()
|
|
||||||
{
|
|
||||||
// attach to the metrotestharness named logging pipe
|
|
||||||
HANDLE winOut = CreateFileA("\\\\.\\pipe\\metrotestharness",
|
|
||||||
GENERIC_WRITE,
|
|
||||||
FILE_SHARE_WRITE, 0,
|
|
||||||
OPEN_EXISTING, 0, 0);
|
|
||||||
|
|
||||||
if (winOut == INVALID_HANDLE_VALUE) {
|
|
||||||
OutputDebugStringW(L"Could not create named logging pipe.\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the c runtime handle
|
|
||||||
int stdOut = _open_osfhandle((intptr_t)winOut, _O_APPEND);
|
|
||||||
if (stdOut == -1) {
|
|
||||||
OutputDebugStringW(L"Could not open c-runtime handle.\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FILE *fp = _fdopen(stdOut, "a");
|
|
||||||
*stdout = *fp;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
XRE_GetFileFromPathType XRE_GetFileFromPath;
|
XRE_GetFileFromPathType XRE_GetFileFromPath;
|
||||||
XRE_CreateAppDataType XRE_CreateAppData;
|
XRE_CreateAppDataType XRE_CreateAppData;
|
||||||
XRE_FreeAppDataType XRE_FreeAppData;
|
XRE_FreeAppDataType XRE_FreeAppData;
|
||||||
#ifdef XRE_HAS_DLL_BLOCKLIST
|
XRE_TelemetryAccumulateType XRE_TelemetryAccumulate;
|
||||||
XRE_SetupDllBlocklistType XRE_SetupDllBlocklist;
|
|
||||||
#endif
|
|
||||||
XRE_StartupTimelineRecordType XRE_StartupTimelineRecord;
|
XRE_StartupTimelineRecordType XRE_StartupTimelineRecord;
|
||||||
XRE_mainType XRE_main;
|
XRE_mainType XRE_main;
|
||||||
XRE_StopLateWriteChecksType XRE_StopLateWriteChecks;
|
XRE_StopLateWriteChecksType XRE_StopLateWriteChecks;
|
||||||
|
XRE_XPCShellMainType XRE_XPCShellMain;
|
||||||
|
XRE_GetProcessTypeType XRE_GetProcessType;
|
||||||
|
XRE_SetProcessTypeType XRE_SetProcessType;
|
||||||
|
XRE_InitChildProcessType XRE_InitChildProcess;
|
||||||
|
XRE_EnableSameExecutableForContentProcType XRE_EnableSameExecutableForContentProc;
|
||||||
|
#ifdef LIBFUZZER
|
||||||
|
XRE_LibFuzzerSetMainType XRE_LibFuzzerSetMain;
|
||||||
|
XRE_LibFuzzerGetFuncsType XRE_LibFuzzerGetFuncs;
|
||||||
|
#endif
|
||||||
|
|
||||||
static const nsDynamicFunctionLoad kXULFuncs[] = {
|
static const nsDynamicFunctionLoad kXULFuncs[] = {
|
||||||
{ "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
|
{ "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
|
||||||
{ "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
|
{ "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
|
||||||
{ "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData },
|
{ "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData },
|
||||||
#ifdef XRE_HAS_DLL_BLOCKLIST
|
{ "XRE_TelemetryAccumulate", (NSFuncPtr*) &XRE_TelemetryAccumulate },
|
||||||
{ "XRE_SetupDllBlocklist", (NSFuncPtr*) &XRE_SetupDllBlocklist },
|
|
||||||
#endif
|
|
||||||
{ "XRE_StartupTimelineRecord", (NSFuncPtr*) &XRE_StartupTimelineRecord },
|
{ "XRE_StartupTimelineRecord", (NSFuncPtr*) &XRE_StartupTimelineRecord },
|
||||||
{ "XRE_main", (NSFuncPtr*) &XRE_main },
|
{ "XRE_main", (NSFuncPtr*) &XRE_main },
|
||||||
{ "XRE_StopLateWriteChecks", (NSFuncPtr*) &XRE_StopLateWriteChecks },
|
{ "XRE_StopLateWriteChecks", (NSFuncPtr*) &XRE_StopLateWriteChecks },
|
||||||
|
{ "XRE_XPCShellMain", (NSFuncPtr*) &XRE_XPCShellMain },
|
||||||
|
{ "XRE_GetProcessType", (NSFuncPtr*) &XRE_GetProcessType },
|
||||||
|
{ "XRE_SetProcessType", (NSFuncPtr*) &XRE_SetProcessType },
|
||||||
|
{ "XRE_InitChildProcess", (NSFuncPtr*) &XRE_InitChildProcess },
|
||||||
|
{ "XRE_EnableSameExecutableForContentProc", (NSFuncPtr*) &XRE_EnableSameExecutableForContentProc },
|
||||||
|
#ifdef LIBFUZZER
|
||||||
|
{ "XRE_LibFuzzerSetMain", (NSFuncPtr*) &XRE_LibFuzzerSetMain },
|
||||||
|
{ "XRE_LibFuzzerGetFuncs", (NSFuncPtr*) &XRE_LibFuzzerGetFuncs },
|
||||||
|
#endif
|
||||||
{ nullptr, nullptr }
|
{ nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int do_main(int argc, char* argv[], nsIFile *xreDirectory)
|
#ifdef LIBFUZZER
|
||||||
|
int libfuzzer_main(int argc, char **argv);
|
||||||
|
|
||||||
|
/* This wrapper is used by the libFuzzer main to call into libxul */
|
||||||
|
|
||||||
|
void libFuzzerGetFuncs(const char* moduleName, LibFuzzerInitFunc* initFunc,
|
||||||
|
LibFuzzerTestingFunc* testingFunc) {
|
||||||
|
return XRE_LibFuzzerGetFuncs(moduleName, initFunc, testingFunc);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int do_main(int argc, char* argv[], char* envp[], nsIFile *xreDirectory)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIFile> appini;
|
nsCOMPtr<nsIFile> appini;
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
uint32_t mainFlags = 0;
|
uint32_t mainFlags = 0;
|
||||||
|
|
||||||
#ifdef XP_WIN
|
|
||||||
if (!IsWindowsVistaOrGreater()) {
|
|
||||||
Output("Couldn't load valid PE image.\n");
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
// Allow palemoon.exe to launch XULRunner apps via -app <application.ini>
|
// Allow palemoon.exe to launch XULRunner apps via -app <application.ini>
|
||||||
// Note that -app must be the *first* argument.
|
// Note that -app must be the *first* argument.
|
||||||
const char *appDataFile = getenv("XUL_APP_FILE");
|
const char *appDataFile = getenv("XUL_APP_FILE");
|
||||||
|
|
@ -207,14 +193,26 @@ static int do_main(int argc, char* argv[], nsIFile *xreDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
char appEnv[MAXPATHLEN];
|
char appEnv[MAXPATHLEN];
|
||||||
snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
|
SprintfLiteral(appEnv, "XUL_APP_FILE=%s", argv[2]);
|
||||||
if (putenv(appEnv)) {
|
if (putenv(strdup(appEnv))) {
|
||||||
Output("Couldn't set %s.\n", appEnv);
|
Output("Couldn't set %s.\n", appEnv);
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
argv[2] = argv[0];
|
argv[2] = argv[0];
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -= 2;
|
argc -= 2;
|
||||||
|
} else if (argc > 1 && IsArg(argv[1], "xpcshell")) {
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
argv[i] = argv[i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
XREShellData shellData;
|
||||||
|
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
|
||||||
|
shellData.sandboxBrokerServices =
|
||||||
|
sandboxing::GetInitializedBrokerServices();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return XRE_XPCShellMain(--argc, argv, envp, &shellData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appini) {
|
if (appini) {
|
||||||
|
|
@ -224,6 +222,13 @@ static int do_main(int argc, char* argv[], nsIFile *xreDirectory)
|
||||||
Output("Couldn't read application.ini");
|
Output("Couldn't read application.ini");
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
#if defined(HAS_DLL_BLOCKLIST)
|
||||||
|
// The dll blocklist operates in the exe vs. xullib. Pass a flag to
|
||||||
|
// xullib so automated tests can check the result once the browser
|
||||||
|
// is up and running.
|
||||||
|
appData->flags |=
|
||||||
|
DllBlocklist_CheckStatus() ? NS_XRE_DLL_BLOCKLIST_ENABLED : 0;
|
||||||
|
#endif
|
||||||
// xreDirectory already has a refcount from NS_NewLocalFile
|
// xreDirectory already has a refcount from NS_NewLocalFile
|
||||||
appData->xreDirectory = xreDirectory;
|
appData->xreDirectory = xreDirectory;
|
||||||
int result = XRE_main(argc, argv, appData, mainFlags);
|
int result = XRE_main(argc, argv, appData, mainFlags);
|
||||||
|
|
@ -231,7 +236,6 @@ static int do_main(int argc, char* argv[], nsIFile *xreDirectory)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Desktop browser launch
|
|
||||||
ScopedAppData appData(&sAppData);
|
ScopedAppData appData(&sAppData);
|
||||||
nsCOMPtr<nsIFile> exeFile;
|
nsCOMPtr<nsIFile> exeFile;
|
||||||
rv = mozilla::BinaryPath::GetFile(argv[0], getter_AddRefs(exeFile));
|
rv = mozilla::BinaryPath::GetFile(argv[0], getter_AddRefs(exeFile));
|
||||||
|
|
@ -243,10 +247,7 @@ static int do_main(int argc, char* argv[], nsIFile *xreDirectory)
|
||||||
nsCOMPtr<nsIFile> greDir;
|
nsCOMPtr<nsIFile> greDir;
|
||||||
exeFile->GetParent(getter_AddRefs(greDir));
|
exeFile->GetParent(getter_AddRefs(greDir));
|
||||||
#ifdef XP_MACOSX
|
#ifdef XP_MACOSX
|
||||||
nsCOMPtr<nsIFile> parent;
|
greDir->SetNativeLeafName(NS_LITERAL_CSTRING(kOSXResourcesFolder));
|
||||||
greDir->GetParent(getter_AddRefs(parent));
|
|
||||||
greDir = parent.forget();
|
|
||||||
greDir->AppendNative(NS_LITERAL_CSTRING(kOSXResourcesFolder));
|
|
||||||
#endif
|
#endif
|
||||||
nsCOMPtr<nsIFile> appSubdir;
|
nsCOMPtr<nsIFile> appSubdir;
|
||||||
greDir->Clone(getter_AddRefs(appSubdir));
|
greDir->Clone(getter_AddRefs(appSubdir));
|
||||||
|
|
@ -256,33 +257,29 @@ static int do_main(int argc, char* argv[], nsIFile *xreDirectory)
|
||||||
// xreDirectory already has a refcount from NS_NewLocalFile
|
// xreDirectory already has a refcount from NS_NewLocalFile
|
||||||
appData.xreDirectory = xreDirectory;
|
appData.xreDirectory = xreDirectory;
|
||||||
|
|
||||||
return XRE_main(argc, argv, &appData, mainFlags);
|
#if defined(HAS_DLL_BLOCKLIST)
|
||||||
}
|
appData.flags |=
|
||||||
|
DllBlocklist_CheckStatus() ? NS_XRE_DLL_BLOCKLIST_ENABLED : 0;
|
||||||
/**
|
|
||||||
* Local TimeStamp::Now()-compatible implementation used to record timestamps
|
|
||||||
* which will be passed to XRE_StartupTimelineRecord().
|
|
||||||
*/
|
|
||||||
static uint64_t
|
|
||||||
TimeStamp_Now()
|
|
||||||
{
|
|
||||||
#ifdef XP_WIN
|
|
||||||
LARGE_INTEGER freq;
|
|
||||||
::QueryPerformanceFrequency(&freq);
|
|
||||||
return GetTickCount64() * freq.QuadPart;
|
|
||||||
#elif defined(XP_MACOSX)
|
|
||||||
return mach_absolute_time();
|
|
||||||
#elif defined(HAVE_CLOCK_MONOTONIC)
|
|
||||||
struct timespec ts;
|
|
||||||
int rv = clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
|
|
||||||
if (rv != 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t baseNs = (uint64_t)ts.tv_sec * 1000000000;
|
|
||||||
return baseNs + (uint64_t)ts.tv_nsec;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
|
||||||
|
sandbox::BrokerServices* brokerServices =
|
||||||
|
sandboxing::GetInitializedBrokerServices();
|
||||||
|
#if defined(MOZ_CONTENT_SANDBOX)
|
||||||
|
if (!brokerServices) {
|
||||||
|
Output("Couldn't initialize the broker services.\n");
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
appData.sandboxBrokerServices = brokerServices;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LIBFUZZER
|
||||||
|
if (getenv("LIBFUZZER"))
|
||||||
|
XRE_LibFuzzerSetMain(argc, argv, libfuzzer_main);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return XRE_main(argc, argv, &appData, mainFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
@ -298,11 +295,6 @@ FileExists(const char *path)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LIBXUL_SDK
|
|
||||||
# define XPCOM_PATH "xulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL
|
|
||||||
#else
|
|
||||||
# define XPCOM_PATH XPCOM_DLL
|
|
||||||
#endif
|
|
||||||
static nsresult
|
static nsresult
|
||||||
InitXPCOMGlue(const char *argv0, nsIFile **xreDirectory)
|
InitXPCOMGlue(const char *argv0, nsIFile **xreDirectory)
|
||||||
{
|
{
|
||||||
|
|
@ -315,55 +307,13 @@ InitXPCOMGlue(const char *argv0, nsIFile **xreDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
|
char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
|
||||||
if (!lastSlash || (size_t(lastSlash - exePath) > MAXPATHLEN - sizeof(XPCOM_PATH) - 1))
|
if (!lastSlash ||
|
||||||
|
(size_t(lastSlash - exePath) > MAXPATHLEN - sizeof(XPCOM_DLL) - 1))
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
strcpy(lastSlash + 1, XPCOM_PATH);
|
strcpy(lastSlash + 1, XPCOM_DLL);
|
||||||
lastSlash += sizeof(XPCOM_PATH) - sizeof(XPCOM_DLL);
|
|
||||||
|
|
||||||
if (!FileExists(exePath)) {
|
if (!FileExists(exePath)) {
|
||||||
#if defined(LIBXUL_SDK) && defined(XP_MACOSX)
|
|
||||||
// Check for <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib
|
|
||||||
bool greFound = false;
|
|
||||||
CFBundleRef appBundle = CFBundleGetMainBundle();
|
|
||||||
if (!appBundle)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
CFURLRef fwurl = CFBundleCopyPrivateFrameworksURL(appBundle);
|
|
||||||
CFURLRef absfwurl = nullptr;
|
|
||||||
if (fwurl) {
|
|
||||||
absfwurl = CFURLCopyAbsoluteURL(fwurl);
|
|
||||||
CFRelease(fwurl);
|
|
||||||
}
|
|
||||||
if (absfwurl) {
|
|
||||||
CFURLRef xulurl =
|
|
||||||
CFURLCreateCopyAppendingPathComponent(nullptr, absfwurl,
|
|
||||||
CFSTR("XUL.framework"),
|
|
||||||
true);
|
|
||||||
|
|
||||||
if (xulurl) {
|
|
||||||
CFURLRef xpcomurl =
|
|
||||||
CFURLCreateCopyAppendingPathComponent(nullptr, xulurl,
|
|
||||||
CFSTR("libxpcom.dylib"),
|
|
||||||
false);
|
|
||||||
|
|
||||||
if (xpcomurl) {
|
|
||||||
if (CFURLGetFileSystemRepresentation(xpcomurl, true,
|
|
||||||
(UInt8*) exePath,
|
|
||||||
sizeof(exePath)) &&
|
|
||||||
access(tbuffer, R_OK | X_OK) == 0) {
|
|
||||||
if (realpath(tbuffer, exePath)) {
|
|
||||||
greFound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CFRelease(xpcomurl);
|
|
||||||
}
|
|
||||||
CFRelease(xulurl);
|
|
||||||
}
|
|
||||||
CFRelease(absfwurl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!greFound) {
|
|
||||||
#endif
|
|
||||||
Output("Could not find the Mozilla runtime.\n");
|
Output("Could not find the Mozilla runtime.\n");
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
@ -383,8 +333,10 @@ InitXPCOMGlue(const char *argv0, nsIFile **xreDirectory)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This will set this thread as the main thread.
|
||||||
NS_LogInit();
|
NS_LogInit();
|
||||||
|
|
||||||
|
if (xreDirectory) {
|
||||||
// chop XPCOM_DLL off exePath
|
// chop XPCOM_DLL off exePath
|
||||||
*lastSlash = '\0';
|
*lastSlash = '\0';
|
||||||
#ifdef XP_MACOSX
|
#ifdef XP_MACOSX
|
||||||
|
|
@ -398,30 +350,55 @@ InitXPCOMGlue(const char *argv0, nsIFile **xreDirectory)
|
||||||
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), false,
|
rv = NS_NewNativeLocalFile(nsDependentCString(exePath), false,
|
||||||
xreDirectory);
|
xreDirectory);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[], char* envp[])
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_delay_start_metro
|
mozilla::TimeStamp start = mozilla::TimeStamp::Now();
|
||||||
Sleep(5000);
|
|
||||||
#endif
|
|
||||||
uint64_t start = TimeStamp_Now();
|
|
||||||
|
|
||||||
#ifdef XP_MACOSX
|
#ifdef HAS_DLL_BLOCKLIST
|
||||||
TriggerQuirks();
|
DllBlocklist_Initialize();
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
// In order to be effective against AppInit DLLs, the blocklist must be
|
||||||
|
// initialized before user32.dll is loaded into the process (bug 932100).
|
||||||
|
if (GetModuleHandleA("user32.dll")) {
|
||||||
|
fprintf(stderr, "DLL blocklist was unable to intercept AppInit DLLs.\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int gotCounters;
|
#ifdef MOZ_BROWSER_CAN_BE_CONTENTPROC
|
||||||
#if defined(XP_UNIX)
|
// We are launching as a content process, delegate to the appropriate
|
||||||
struct rusage initialRUsage;
|
// main
|
||||||
gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage);
|
if (argc > 1 && IsArg(argv[1], "contentproc")) {
|
||||||
#elif defined(XP_WIN)
|
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
|
||||||
IO_COUNTERS ioCounters;
|
// We need to initialize the sandbox TargetServices before InitXPCOMGlue
|
||||||
gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters);
|
// because we might need the sandbox broker to give access to some files.
|
||||||
|
if (IsSandboxedProcess() && !sandboxing::GetInitializedTargetServices()) {
|
||||||
|
Output("Failed to initialize the sandbox target services.");
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
nsresult rv = InitXPCOMGlue(argv[0], nullptr);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = content_process_main(argc, argv);
|
||||||
|
|
||||||
|
// InitXPCOMGlue calls NS_LogInit, so we need to balance it here.
|
||||||
|
NS_LogTerm();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
nsIFile *xreDirectory;
|
nsIFile *xreDirectory;
|
||||||
|
|
||||||
nsresult rv = InitXPCOMGlue(argv[0], &xreDirectory);
|
nsresult rv = InitXPCOMGlue(argv[0], &xreDirectory);
|
||||||
|
|
@ -431,11 +408,11 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
XRE_StartupTimelineRecord(mozilla::StartupTimeline::START, start);
|
XRE_StartupTimelineRecord(mozilla::StartupTimeline::START, start);
|
||||||
|
|
||||||
#ifdef XRE_HAS_DLL_BLOCKLIST
|
#ifdef MOZ_BROWSER_CAN_BE_CONTENTPROC
|
||||||
XRE_SetupDllBlocklist();
|
XRE_EnableSameExecutableForContentProc();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int result = do_main(argc, argv, xreDirectory);
|
int result = do_main(argc, argv, envp, xreDirectory);
|
||||||
|
|
||||||
NS_LogTerm();
|
NS_LogTerm();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue