Bug 1843831 [wpt PR 41060] - LoAF: Expose script start position instead of column...
[gecko.git] / ipc / app / MozillaRuntimeMain.cpp
blob6741617b607f0cf65018abce0114c71b5daf21e2
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "../contentproc/plugin-container.cpp"
9 #include "mozilla/Bootstrap.h"
10 #include "mozilla/RuntimeExceptionModule.h"
11 #include "mozilla/ScopeExit.h"
12 #if defined(XP_WIN)
13 # include "mozilla/WindowsDllBlocklist.h"
14 # include "mozilla/GeckoArgs.h"
15 #endif // defined(XP_WIN)
17 using namespace mozilla;
19 static bool UseForkServer(int argc, char* argv[]) {
20 #if defined(MOZ_ENABLE_FORKSERVER)
21 return strcmp(argv[argc - 1], "forkserver") == 0;
22 #else
23 return false;
24 #endif
27 static int RunForkServer(Bootstrap::UniquePtr&& bootstrap, int argc,
28 char* argv[]) {
29 #if defined(MOZ_ENABLE_FORKSERVER)
30 int ret = 0;
32 bootstrap->NS_LogInit();
34 // Run a fork server in this process, single thread. When it
35 // returns, it means the fork server have been stopped or a new
36 // content process is created.
38 // For the later case, XRE_ForkServer() will return false, running
39 // in a content process just forked from the fork server process.
40 // argc & argv will be updated with the values passing from the
41 // chrome process. With the new values, this function
42 // continues the reset of the code acting as a content process.
43 if (bootstrap->XRE_ForkServer(&argc, &argv)) {
44 // Return from the fork server in the fork server process.
45 // Stop the fork server.
46 } else {
47 // In a content process forked from the fork server.
48 // Start acting as a content process.
49 ret = content_process_main(bootstrap.get(), argc, argv);
52 bootstrap->NS_LogTerm();
53 return ret;
54 #else
55 return 0;
56 #endif
59 int main(int argc, char* argv[]) {
60 auto bootstrapResult = GetBootstrap();
61 if (bootstrapResult.isErr()) {
62 return 2;
65 Bootstrap::UniquePtr bootstrap = bootstrapResult.unwrap();
67 int ret;
68 if (UseForkServer(argc, argv)) {
69 ret = RunForkServer(std::move(bootstrap), argc, argv);
70 } else {
71 // Set the process type. We don't remove the arg here as that will be done
72 // later in common code.
73 SetGeckoProcessType(argv[argc - 1]);
75 // Register an external module to report on otherwise uncatchable
76 // exceptions. Note that in child processes this must be called after Gecko
77 // process type has been set.
78 CrashReporter::RegisterRuntimeExceptionModule();
80 // Make sure we unregister the runtime exception module before returning.
81 auto unregisterRuntimeExceptionModule = MakeScopeExit(
82 [] { CrashReporter::UnregisterRuntimeExceptionModule(); });
84 #ifdef HAS_DLL_BLOCKLIST
85 uint32_t initFlags = eDllBlocklistInitFlagIsChildProcess;
86 SetDllBlocklistProcessTypeFlags(initFlags, GetGeckoProcessType());
87 DllBlocklist_Initialize(initFlags);
88 #endif
90 ret = content_process_main(bootstrap.get(), argc, argv);
92 #if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST)
93 DllBlocklist_Shutdown();
94 #endif
97 return ret;