xpcshell.cpp (2305B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* XPConnect JavaScript interactive shell. */ 8 9 #include <stdio.h> 10 11 #include "mozilla/Bootstrap.h" 12 #include "XREShellData.h" 13 14 #ifdef XP_MACOSX 15 # include "xpcshellMacUtils.h" 16 #endif 17 #ifdef XP_WIN 18 # include "mozilla/WindowsDllBlocklist.h" 19 20 # include <windows.h> 21 # include <shlobj.h> 22 23 // we want a wmain entry point 24 # define XRE_WANT_ENVIRON 25 # include "nsWindowsWMain.cpp" 26 # ifdef MOZ_SANDBOX 27 # include "mozilla/sandboxing/SandboxInitialization.h" 28 # endif 29 #endif 30 31 #ifdef MOZ_WIDGET_GTK 32 # include <gtk/gtk.h> 33 #endif 34 35 #include "mozilla/BaseProfiler.h" 36 37 #ifdef LIBFUZZER 38 # include "FuzzerDefs.h" 39 #endif 40 41 int main(int argc, char** argv, char** envp) { 42 #ifdef MOZ_WIDGET_GTK 43 // A default display may or may not be required for xpcshell tests, and so 44 // is not created here. Instead we set the command line args, which is a 45 // fairly cheap operation. 46 gtk_parse_args(&argc, &argv); 47 #endif 48 49 #ifdef XP_MACOSX 50 InitAutoreleasePool(); 51 #endif 52 53 // unbuffer stdout so that output is in the correct order; note that stderr 54 // is unbuffered by default 55 setbuf(stdout, nullptr); 56 57 #ifdef HAS_DLL_BLOCKLIST 58 DllBlocklist_Initialize(); 59 #endif 60 61 char aLocal; 62 mozilla::baseprofiler::profiler_init(&aLocal); 63 64 XREShellData shellData; 65 #if defined(XP_WIN) && defined(MOZ_SANDBOX) 66 shellData.sandboxBrokerServices = 67 mozilla::sandboxing::GetInitializedBrokerServices(); 68 #endif 69 70 auto bootstrapResult = mozilla::GetBootstrap(); 71 if (bootstrapResult.isErr()) { 72 return 2; 73 } 74 75 mozilla::Bootstrap::UniquePtr bootstrap = bootstrapResult.unwrap(); 76 77 #ifdef LIBFUZZER 78 shellData.fuzzerDriver = fuzzer::FuzzerDriver; 79 #endif 80 #ifdef AFLFUZZ 81 shellData.fuzzerDriver = afl_interface_raw; 82 #endif 83 84 int result = bootstrap->XRE_XPCShellMain(argc, argv, envp, &shellData); 85 86 mozilla::baseprofiler::profiler_shutdown(); 87 88 #if defined(DEBUG) && defined(HAS_DLL_BLOCKLIST) 89 DllBlocklist_Shutdown(); 90 #endif 91 92 #ifdef XP_MACOSX 93 FinishAutoreleasePool(); 94 #endif 95 96 return result; 97 }