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"
9 #include "AutoSQLiteLifetime.h"
11 #if defined(XP_WIN) && defined(_M_X64) && defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
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);
24 class BootstrapImpl final
: public Bootstrap
{
26 AutoSQLiteLifetime mSQLLT
;
28 virtual void Dispose() override
{ delete this; }
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();
90 virtual void XRE_LibFuzzerSetDriver(LibFuzzerDriver aDriver
) override
{
91 ::XRE_LibFuzzerSetDriver(aDriver
);
95 #ifdef MOZ_ENABLE_FORKSERVER
96 virtual int XRE_ForkServer(int* argc
, char*** argv
) override
{
97 return ::XRE_ForkServer(argc
, argv
);
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.
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;
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