1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_GeckoArgs_h
6 #define mozilla_GeckoArgs_h
8 #include "mozilla/CmdLineAndEnvUtils.h"
9 #include "mozilla/Maybe.h"
10 #include "mozilla/UniquePtrExtensions.h"
11 #include "mozilla/ipc/SharedMemory.h"
23 // Type used for passing arguments to a content process, including OS files.
24 struct ChildProcessArgs
{
25 std::vector
<std::string
> mArgs
;
26 std::vector
<UniqueFileHandle
> mFiles
;
28 std::vector
<UniqueMachSendRight
> mSendRights
;
33 // On some unix platforms, file handles are passed down without using a fixed
34 // file descriptor. This method can be used to override the default mapping.
35 void SetPassedFileHandles(Span
<int> aFiles
);
36 void SetPassedFileHandles(std::vector
<UniqueFileHandle
>&& aFiles
);
38 // Add the file handles from a ChildProcessArgs to a fdsToRemap table.
39 void AddToFdsToRemap(const ChildProcessArgs
& aArgs
,
40 std::vector
<std::pair
<int, int>>& aFdsToRemap
);
44 // Size of the internal static array of mach send rights. This acts as a limit
45 // to the number of mach send rights which can be passed on the command line.
46 constexpr size_t kMaxPassedMachSendRights
= 10;
48 // Fill the internal static array with the mach send rights which were passed
49 // from the parent process.
50 void SetPassedMachSendRights(std::vector
<UniqueMachSendRight
>&& aSendRights
);
54 struct CommandLineArg
{
55 Maybe
<T
> Get(int& aArgc
, char** aArgv
,
56 const CheckArgFlag aFlags
= CheckArgFlag::RemoveArg
) {
57 return GetCommon(sMatch
, aArgc
, aArgv
, aFlags
);
59 static Maybe
<T
> GetCommon(const char* aMatch
, int& aArgc
, char** aArgv
,
60 const CheckArgFlag aFlags
);
62 const char* Name() { return sName
; };
64 void Put(T aValue
, ChildProcessArgs
& aArgs
) {
65 return PutCommon(sName
, std::move(aValue
), aArgs
);
67 static void PutCommon(const char* aName
, T aValue
, ChildProcessArgs
& aArgs
);
76 inline Maybe
<const char*> CommandLineArg
<const char*>::GetCommon(
77 const char* aMatch
, int& aArgc
, char** aArgv
, const CheckArgFlag aFlags
) {
78 MOZ_ASSERT(aArgv
, "aArgv must be initialized before CheckArg()");
79 const char* rv
= nullptr;
80 if (ARG_FOUND
== CheckArg(aArgc
, aArgv
, aMatch
, &rv
, aFlags
)) {
87 inline Maybe
<bool> CommandLineArg
<bool>::GetCommon(const char* aMatch
,
88 int& aArgc
, char** aArgv
,
89 const CheckArgFlag aFlags
) {
90 MOZ_ASSERT(aArgv
, "aArgv must be initialized before CheckArg()");
92 CheckArg(aArgc
, aArgv
, aMatch
, (const char**)nullptr, aFlags
)) {
99 inline Maybe
<uint64_t> CommandLineArg
<uint64_t>::GetCommon(
100 const char* aMatch
, int& aArgc
, char** aArgv
, const CheckArgFlag aFlags
) {
101 if (Maybe
<const char*> arg
= CommandLineArg
<const char*>::GetCommon(
102 aMatch
, aArgc
, aArgv
, aFlags
)) {
104 char* endptr
= nullptr;
105 uint64_t conv
= std::strtoull(*arg
, &endptr
, 10);
106 if (errno
== 0 && endptr
&& *endptr
== '\0') {
114 inline Maybe
<uint32_t> CommandLineArg
<uint32_t>::GetCommon(
115 const char* aMatch
, int& aArgc
, char** aArgv
, const CheckArgFlag aFlags
) {
116 return CommandLineArg
<uint64_t>::GetCommon(aMatch
, aArgc
, aArgv
, aFlags
);
120 Maybe
<UniqueFileHandle
> CommandLineArg
<UniqueFileHandle
>::GetCommon(
121 const char* aMatch
, int& aArgc
, char** aArgv
, const CheckArgFlag aFlags
);
125 Maybe
<UniqueMachSendRight
> CommandLineArg
<UniqueMachSendRight
>::GetCommon(
126 const char* aMatch
, int& aArgc
, char** aArgv
, const CheckArgFlag aFlags
);
132 inline void CommandLineArg
<const char*>::PutCommon(const char* aName
,
134 ChildProcessArgs
& aArgs
) {
135 aArgs
.mArgs
.push_back(aName
);
136 aArgs
.mArgs
.push_back(aValue
);
140 inline void CommandLineArg
<bool>::PutCommon(const char* aName
, bool aValue
,
141 ChildProcessArgs
& aArgs
) {
143 aArgs
.mArgs
.push_back(aName
);
148 inline void CommandLineArg
<uint64_t>::PutCommon(const char* aName
,
150 ChildProcessArgs
& aArgs
) {
151 aArgs
.mArgs
.push_back(aName
);
152 aArgs
.mArgs
.push_back(std::to_string(aValue
));
156 inline void CommandLineArg
<uint32_t>::PutCommon(const char* aName
,
158 ChildProcessArgs
& aArgs
) {
159 CommandLineArg
<uint64_t>::PutCommon(aName
, aValue
, aArgs
);
163 void CommandLineArg
<UniqueFileHandle
>::PutCommon(const char* aName
,
164 UniqueFileHandle aValue
,
165 ChildProcessArgs
& aArgs
);
169 void CommandLineArg
<UniqueMachSendRight
>::PutCommon(const char* aName
,
170 UniqueMachSendRight aValue
,
171 ChildProcessArgs
& aArgs
);
174 #if defined(__GNUC__)
175 # pragma GCC diagnostic push
176 # pragma GCC diagnostic ignored "-Wunused-variable"
179 static CommandLineArg
<uint64_t> sParentPid
{"-parentPid", "parentpid"};
180 static CommandLineArg
<const char*> sInitialChannelID
{"-initialChannelId",
182 static CommandLineArg
<const char*> sParentBuildID
{"-parentBuildID",
184 static CommandLineArg
<const char*> sAppDir
{"-appDir", "appdir"};
185 static CommandLineArg
<const char*> sGREOmni
{"-greomni", "greomni"};
186 static CommandLineArg
<const char*> sAppOmni
{"-appomni", "appomni"};
187 static CommandLineArg
<const char*> sProfile
{"-profile", "profile"};
189 static CommandLineArg
<UniqueFileHandle
> sIPCHandle
{"-ipcHandle", "ipchandle"};
191 static CommandLineArg
<mozilla::ipc::SharedMemoryHandle
> sJsInitHandle
{
192 "-jsInitHandle", "jsinithandle"};
193 static CommandLineArg
<uint64_t> sJsInitLen
{"-jsInitLen", "jsinitlen"};
194 static CommandLineArg
<mozilla::ipc::SharedMemoryHandle
> sPrefsHandle
{
195 "-prefsHandle", "prefshandle"};
196 static CommandLineArg
<uint64_t> sPrefsLen
{"-prefsLen", "prefslen"};
197 static CommandLineArg
<mozilla::ipc::SharedMemoryHandle
> sPrefMapHandle
{
198 "-prefMapHandle", "prefmaphandle"};
199 static CommandLineArg
<uint64_t> sPrefMapSize
{"-prefMapSize", "prefmapsize"};
201 static CommandLineArg
<uint64_t> sSandboxingKind
{"-sandboxingKind",
204 static CommandLineArg
<bool> sSafeMode
{"-safeMode", "safemode"};
206 static CommandLineArg
<bool> sIsForBrowser
{"-isForBrowser", "isforbrowser"};
207 static CommandLineArg
<bool> sNotForBrowser
{"-notForBrowser", "notforbrowser"};
209 static CommandLineArg
<const char*> sPluginPath
{"-pluginPath", "pluginpath"};
210 static CommandLineArg
<bool> sPluginNativeEvent
{"-pluginNativeEvent",
211 "pluginnativeevent"};
213 #if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
214 static CommandLineArg
<const char*> sCrashReporter
{"-crashReporter",
216 #elif defined(XP_UNIX)
217 static CommandLineArg
<UniqueFileHandle
> sCrashReporter
{"-crashReporter",
222 # if defined(MOZ_SANDBOX)
223 static CommandLineArg
<bool> sWin32kLockedDown
{"-win32kLockedDown",
225 # endif // defined(MOZ_SANDBOX)
226 static CommandLineArg
<bool> sDisableDynamicDllBlocklist
{
227 "-disableDynamicBlocklist", "disabledynamicblocklist"};
228 #endif // defined(XP_WIN)
230 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
231 static CommandLineArg
<UniqueFileHandle
> sSandboxReporter
{"-sandboxReporter",
233 static CommandLineArg
<UniqueFileHandle
> sChrootClient
{"-chrootClient",
237 #if defined(__GNUC__)
238 # pragma GCC diagnostic pop
241 } // namespace geckoargs
243 } // namespace mozilla
245 #endif // mozilla_GeckoArgs_h