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/. */
7 * This file represents the only external interface exposed from libxul. It
8 * is used by the various stub binaries (nsBrowserApp, xpcshell,
9 * plugin-container) to initialize XPCOM and start their main loop.
12 #ifndef mozilla_Bootstrap_h
13 #define mozilla_Bootstrap_h
15 #include "mozilla/Maybe.h"
16 #include "mozilla/ResultVariant.h"
17 #include "mozilla/UniquePtr.h"
18 #include "mozilla/UniquePtrExtensions.h"
19 #include "mozilla/Variant.h"
21 #include "nsXULAppAPI.h"
23 #ifdef MOZ_WIDGET_ANDROID
27 struct StaticXREAppData
;
30 extern "C" NS_EXPORT
void GeckoStart(JNIEnv
* aEnv
, char** argv
, int argc
,
31 const mozilla::StaticXREAppData
& aAppData
,
32 bool xpcshell
, const char* outFilePath
);
35 #if defined(XP_WIN) && defined(MOZ_SANDBOX)
43 struct StaticXREAppData
;
45 struct BootstrapConfig
{
46 #if defined(XP_WIN) && defined(MOZ_SANDBOX)
47 /* Chromium sandbox BrokerServices. */
48 sandbox::BrokerServices
* sandboxBrokerServices
;
50 /* Pointer to static XRE AppData from application.ini.h */
51 const StaticXREAppData
* appData
;
52 /* When the pointer above is null, points to the (string) path of an
53 * application.ini file to open and parse.
54 * When the pointer above is non-null, may indicate the directory where
55 * application files are, relative to the XRE. */
56 const char* appDataPath
;
60 * This class is virtual abstract so that using it does not require linking
61 * any symbols. The singleton instance of this class is obtained from the
62 * exported method XRE_GetBootstrap.
68 // Because of allocator mismatches, code outside libxul shouldn't delete a
69 // Bootstrap instance. Use Dispose().
70 virtual ~Bootstrap() {}
73 * Destroy and deallocate this Bootstrap instance.
75 virtual void Dispose() = 0;
78 * Helper class to use with UniquePtr.
80 class BootstrapDelete
{
82 constexpr BootstrapDelete() {}
83 void operator()(Bootstrap
* aPtr
) const { aPtr
->Dispose(); }
87 typedef mozilla::UniquePtr
<Bootstrap
, BootstrapDelete
> UniquePtr
;
89 virtual void NS_LogInit() = 0;
91 virtual void NS_LogTerm() = 0;
93 virtual void XRE_TelemetryAccumulate(int aID
, uint32_t aSample
) = 0;
95 virtual void XRE_StartupTimelineRecord(int aEvent
,
96 mozilla::TimeStamp aWhen
) = 0;
98 virtual int XRE_main(int argc
, char* argv
[],
99 const BootstrapConfig
& aConfig
) = 0;
101 virtual void XRE_StopLateWriteChecks() = 0;
103 virtual int XRE_XPCShellMain(int argc
, char** argv
, char** envp
,
104 const XREShellData
* aShellData
) = 0;
106 virtual GeckoProcessType
XRE_GetProcessType() = 0;
108 virtual void XRE_SetProcessType(const char* aProcessTypeString
) = 0;
110 virtual nsresult
XRE_InitChildProcess(int argc
, char* argv
[],
111 const XREChildData
* aChildData
) = 0;
113 virtual void XRE_EnableSameExecutableForContentProc() = 0;
115 #ifdef MOZ_WIDGET_ANDROID
116 virtual void GeckoStart(JNIEnv
* aEnv
, char** argv
, int argc
,
117 const StaticXREAppData
& aAppData
, bool xpcshell
,
118 const char* outFilePath
) = 0;
120 virtual void XRE_SetAndroidChildFds(JNIEnv
* aEnv
,
121 const XRE_AndroidChildFds
& fds
) = 0;
122 # ifdef MOZ_PROFILE_GENERATE
123 virtual void XRE_WriteLLVMProfData() = 0;
128 virtual void XRE_LibFuzzerSetDriver(LibFuzzerDriver aDriver
) = 0;
131 #ifdef MOZ_ENABLE_FORKSERVER
132 virtual int XRE_ForkServer(int* argc
, char*** argv
) = 0;
136 enum class LibLoadingStrategy
{
142 using DLErrorType
= unsigned long; // (DWORD)
144 using DLErrorType
= UniqueFreePtr
<char>;
147 using BootstrapError
= Variant
<nsresult
, DLErrorType
>;
149 using BootstrapResult
= ::mozilla::Result
<Bootstrap::UniquePtr
, BootstrapError
>;
152 * Creates and returns the singleton instance of the bootstrap object.
153 * @param `b` is an outparam. We use a parameter and not a return value
154 * because MSVC doesn't let us return a c++ class from a function with
155 * "C" linkage. On failure this will be null.
156 * @note This function may only be called once and will crash if called again.
159 typedef void (*GetBootstrapType
)(Bootstrap::UniquePtr
&);
160 BootstrapResult
GetBootstrap(
161 const char* aXPCOMFile
= nullptr,
162 LibLoadingStrategy aLibLoadingStrategy
= LibLoadingStrategy::NoReadAhead
);
164 extern "C" NS_EXPORT
void NS_FROZENCALL
165 XRE_GetBootstrap(Bootstrap::UniquePtr
& b
);
167 inline BootstrapResult
GetBootstrap(const char* aXPCOMFile
= nullptr) {
168 Bootstrap::UniquePtr bootstrap
;
169 XRE_GetBootstrap(bootstrap
);
174 } // namespace mozilla
176 #endif // mozilla_Bootstrap_h