Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/Bootstrap.h
Line
Count
Source (jump to first uncovered line)
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/. */
5
6
/**
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.
10
 */
11
12
#ifndef mozilla_Bootstrap_h
13
#define mozilla_Bootstrap_h
14
15
#include "mozilla/UniquePtr.h"
16
#include "nscore.h"
17
#include "nsXULAppAPI.h"
18
19
#ifdef MOZ_WIDGET_ANDROID
20
#include "jni.h"
21
22
extern "C" NS_EXPORT
23
void GeckoStart(JNIEnv* aEnv, char** argv, int argc, const mozilla::StaticXREAppData& aAppData);
24
#endif
25
26
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
27
namespace sandbox {
28
class BrokerServices;
29
}
30
#endif
31
32
namespace mozilla {
33
34
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
35
namespace sandboxing {
36
class PermissionsService;
37
}
38
#endif
39
40
struct BootstrapConfig
41
{
42
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
43
  /* Chromium sandbox BrokerServices. */
44
  sandbox::BrokerServices* sandboxBrokerServices;
45
  sandboxing::PermissionsService* sandboxPermissionsService;
46
#endif
47
  /* Pointer to static XRE AppData from application.ini.h */
48
  const StaticXREAppData* appData;
49
  /* When the pointer above is null, points to the (string) path of an
50
   * application.ini file to open and parse.
51
   * When the pointer above is non-null, may indicate the directory where
52
   * application files are, relative to the XRE. */
53
  const char* appDataPath;
54
};
55
56
/**
57
 * This class is virtual abstract so that using it does not require linking
58
 * any symbols. The singleton instance of this class is obtained from the
59
 * exported method XRE_GetBootstrap.
60
 */
61
class Bootstrap
62
{
63
protected:
64
0
  Bootstrap() { }
65
66
  // Because of allocator mismatches, code outside libxul shouldn't delete a
67
  // Bootstrap instance. Use Dispose().
68
0
  virtual ~Bootstrap() { }
69
70
  /**
71
   * Destroy and deallocate this Bootstrap instance.
72
   */
73
  virtual void Dispose() = 0;
74
75
  /**
76
   * Helper class to use with UniquePtr.
77
   */
78
  class BootstrapDelete
79
  {
80
  public:
81
6
    constexpr BootstrapDelete() { }
82
    void operator()(Bootstrap* aPtr) const
83
0
    {
84
0
      aPtr->Dispose();
85
0
    }
86
  };
87
88
public:
89
  typedef mozilla::UniquePtr<Bootstrap, BootstrapDelete> UniquePtr;
90
91
  virtual void NS_LogInit() = 0;
92
93
  virtual void NS_LogTerm() = 0;
94
95
  virtual void XRE_TelemetryAccumulate(int aID, uint32_t aSample) = 0;
96
97
  virtual void XRE_StartupTimelineRecord(int aEvent, mozilla::TimeStamp aWhen) = 0;
98
99
  virtual int XRE_main(int argc, char* argv[], const BootstrapConfig& aConfig) = 0;
100
101
  virtual void XRE_StopLateWriteChecks() = 0;
102
103
  virtual int XRE_XPCShellMain(int argc, char** argv, char** envp, const XREShellData* aShellData) = 0;
104
105
  virtual GeckoProcessType XRE_GetProcessType() = 0;
106
107
  virtual void XRE_SetProcessType(const char* aProcessTypeString) = 0;
108
109
  virtual nsresult XRE_InitChildProcess(int argc, char* argv[], const XREChildData* aChildData) = 0;
110
111
  virtual void XRE_EnableSameExecutableForContentProc() = 0;
112
113
#ifdef MOZ_WIDGET_ANDROID
114
  virtual void GeckoStart(JNIEnv* aEnv, char** argv, int argc, const StaticXREAppData& aAppData) = 0;
115
116
  virtual void XRE_SetAndroidChildFds(JNIEnv* aEnv, const XRE_AndroidChildFds& fds) = 0;
117
#endif
118
119
#ifdef LIBFUZZER
120
  virtual void XRE_LibFuzzerSetDriver(LibFuzzerDriver aDriver) = 0;
121
#endif
122
123
#ifdef MOZ_IPDL_TESTS
124
  virtual int XRE_RunIPDLTest(int argc, char **argv) = 0;
125
#endif
126
};
127
128
/**
129
 * Creates and returns the singleton instnace of the bootstrap object.
130
 * @param `b` is an outparam. We use a parameter and not a return value
131
 *        because MSVC doesn't let us return a c++ class from a function with
132
 *        "C" linkage. On failure this will be null.
133
 * @note This function may only be called once and will crash if called again.
134
 */
135
#ifdef XPCOM_GLUE
136
typedef void (*GetBootstrapType)(Bootstrap::UniquePtr&);
137
Bootstrap::UniquePtr GetBootstrap(const char* aXPCOMFile=nullptr);
138
#else
139
extern "C" NS_EXPORT void NS_FROZENCALL
140
XRE_GetBootstrap(Bootstrap::UniquePtr& b);
141
142
inline Bootstrap::UniquePtr
143
GetBootstrap(const char* aXPCOMFile=nullptr) {
144
  Bootstrap::UniquePtr bootstrap;
145
  XRE_GetBootstrap(bootstrap);
146
  return bootstrap;
147
}
148
#endif
149
150
} // namespace mozilla
151
152
#endif // mozilla_Bootstrap_h