Bug 1942239 - Add option to explicitly enable incremental origin initialization in...
[gecko.git] / toolkit / xre / Bootstrap.cpp
blob3c8b68fa3aef9681fb13670118dc7dd28408420f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "mozilla/Bootstrap.h"
7 #include "nsXPCOM.h"
9 #include "AutoSQLiteLifetime.h"
11 #if defined(XP_WIN) && defined(_M_X64) && defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
12 # include <windows.h>
13 #endif // XP_WIN && _M_X64 && MOZ_DIAGNOSTIC_ASSERT_ENABLED
15 #ifdef MOZ_WIDGET_ANDROID
16 # include "mozilla/jni/Utils.h"
17 # ifdef MOZ_PROFILE_GENERATE
18 extern "C" int __llvm_profile_dump(void);
19 # endif
20 #endif
22 namespace mozilla {
24 class BootstrapImpl final : public Bootstrap {
25 protected:
26 AutoSQLiteLifetime mSQLLT;
28 virtual void Dispose() override { delete this; }
30 public:
31 BootstrapImpl() = default;
33 ~BootstrapImpl() = default;
35 virtual void NS_LogInit() override { ::NS_LogInit(); }
37 virtual void NS_LogTerm() override { ::NS_LogTerm(); }
39 virtual void XRE_TelemetryAccumulate(int aID, uint32_t aSample) override {
40 ::XRE_TelemetryAccumulate(aID, aSample);
43 virtual void XRE_StartupTimelineRecord(int aEvent,
44 mozilla::TimeStamp aWhen) override {
45 ::XRE_StartupTimelineRecord(aEvent, aWhen);
48 virtual int XRE_main(int argc, char* argv[],
49 const BootstrapConfig& aConfig) override {
50 return ::XRE_main(argc, argv, aConfig);
53 virtual void XRE_StopLateWriteChecks() override {
54 ::XRE_StopLateWriteChecks();
57 virtual int XRE_XPCShellMain(int argc, char** argv, char** envp,
58 const XREShellData* aShellData) override {
59 return ::XRE_XPCShellMain(argc, argv, envp, aShellData);
62 virtual nsresult XRE_InitChildProcess(
63 int argc, char* argv[], const XREChildData* aChildData) override {
64 return ::XRE_InitChildProcess(argc, argv, aChildData);
67 virtual void XRE_EnableSameExecutableForContentProc() override {
68 ::XRE_EnableSameExecutableForContentProc();
71 #ifdef MOZ_WIDGET_ANDROID
72 virtual void XRE_SetGeckoThreadEnv(JNIEnv* aEnv) override {
73 mozilla::jni::SetGeckoThreadEnv(aEnv);
76 virtual void XRE_SetAndroidChildFds(JNIEnv* aEnv, jintArray aFds) override {
77 ::XRE_SetAndroidChildFds(aEnv, aFds);
80 # ifdef MOZ_PROFILE_GENERATE
81 virtual void XRE_WriteLLVMProfData() override {
82 __android_log_print(ANDROID_LOG_INFO, "GeckoLibLoad",
83 "Calling __llvm_profile_dump()");
84 __llvm_profile_dump();
86 # endif
87 #endif
89 #ifdef LIBFUZZER
90 virtual void XRE_LibFuzzerSetDriver(LibFuzzerDriver aDriver) override {
91 ::XRE_LibFuzzerSetDriver(aDriver);
93 #endif
95 #ifdef MOZ_ENABLE_FORKSERVER
96 virtual int XRE_ForkServer(int* argc, char*** argv) override {
97 return ::XRE_ForkServer(argc, argv);
99 #endif
102 #if defined(XP_WIN) && defined(_M_X64) && defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
103 extern "C" uint32_t _tls_index;
105 extern "C" NS_EXPORT bool XRE_CheckBlockScopeStaticVarInit(
106 uint32_t* aTlsIndex) {
107 // Copy the value of xul's _tls_index for diagnostics.
108 if (aTlsIndex) {
109 *aTlsIndex = _tls_index;
112 // Check that block-scope static variable initialization works. We use
113 // volatile here to keep the compiler honest - we want it to generate the code
114 // that will ensure that only a single thread goes through the lambda.
115 static bool sItWorks = []() -> bool {
116 bool const volatile value = true;
117 return value;
118 }();
119 return sItWorks;
121 #endif // XP_WIN && _M_X64 && MOZ_DIAGNOSTIC_ASSERT_ENABLED
123 extern "C" NS_EXPORT void NS_FROZENCALL
124 XRE_GetBootstrap(Bootstrap::UniquePtr& b) {
125 static bool sBootstrapInitialized = false;
126 MOZ_RELEASE_ASSERT(!sBootstrapInitialized);
128 sBootstrapInitialized = true;
129 b.reset(new BootstrapImpl());
132 } // namespace mozilla