[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
grt | a237cc4 | 2016-09-20 22:56:19 | [diff] [blame] | 5 | #include <stdint.h> |
[email protected] | 86671a3 | 2011-10-06 21:15:20 | [diff] [blame] | 6 | |
Sebastien Marchand | f1349f5 | 2019-01-25 03:16:41 | [diff] [blame] | 7 | #include "base/bind.h" |
brucedawson | 695bdb6e | 2017-06-27 22:45:59 | [diff] [blame] | 8 | #include "base/callback_helpers.h" |
skyostil | b354f88 | 2016-12-13 18:42:45 | [diff] [blame] | 9 | #include "base/command_line.h" |
grt | a237cc4 | 2016-09-20 22:56:19 | [diff] [blame] | 10 | #include "base/time/time.h" |
mfomitchev | ca35d83 | 2017-02-09 22:41:29 | [diff] [blame] | 11 | #include "build/build_config.h" |
grt | a237cc4 | 2016-09-20 22:56:19 | [diff] [blame] | 12 | #include "chrome/app/chrome_main_delegate.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 13 | #include "chrome/common/buildflags.h" |
mfomitchev | ca35d83 | 2017-02-09 22:41:29 | [diff] [blame] | 14 | #include "chrome/common/chrome_switches.h" |
Alexei Svitkine | a40cefb | 2019-06-05 05:14:22 | [diff] [blame] | 15 | #include "chrome/common/profiler/main_thread_stack_sampling_profiler.h" |
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 16 | #include "content/public/app/content_main.h" |
skyostil | b354f88 | 2016-12-13 18:42:45 | [diff] [blame] | 17 | #include "content/public/common/content_switches.h" |
| 18 | #include "headless/public/headless_shell.h" |
| 19 | #include "ui/gfx/switches.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | |
dvallet | 42a29e0 | 2017-03-01 22:34:50 | [diff] [blame] | 21 | #if defined(OS_MACOSX) |
| 22 | #include "chrome/app/chrome_main_mac.h" |
| 23 | #endif |
| 24 | |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 25 | #if defined(OS_WIN) |
[email protected] | f0e90cf9 | 2014-07-21 17:13:58 | [diff] [blame] | 26 | #include "base/debug/dump_without_crashing.h" |
[email protected] | 36a2f08 | 2013-08-27 05:33:57 | [diff] [blame] | 27 | #include "base/win/win_util.h" |
Patrick Monette | 0196be2 | 2019-05-10 03:33:15 | [diff] [blame] | 28 | #include "chrome/chrome_elf/chrome_elf_main.h" |
[email protected] | f0e90cf9 | 2014-07-21 17:13:58 | [diff] [blame] | 29 | #include "chrome/common/chrome_constants.h" |
grt | a47e865 | 2017-01-18 23:45:06 | [diff] [blame] | 30 | #include "chrome/install_static/initialize_from_primary_module.h" |
grt | e29f8ab | 2016-11-15 22:26:30 | [diff] [blame] | 31 | #include "chrome/install_static/install_details.h" |
[email protected] | 36a2f08 | 2013-08-27 05:33:57 | [diff] [blame] | 32 | |
[email protected] | 9c50aa4 | 2008-08-01 15:54:35 | [diff] [blame] | 33 | #define DLLEXPORT __declspec(dllexport) |
| 34 | |
| 35 | // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. |
| 36 | extern "C" { |
| 37 | DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, |
grt | a237cc4 | 2016-09-20 22:56:19 | [diff] [blame] | 38 | sandbox::SandboxInterfaceInfo* sandbox_info, |
| 39 | int64_t exe_entry_point_ticks); |
[email protected] | 9c50aa4 | 2008-08-01 15:54:35 | [diff] [blame] | 40 | } |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 41 | #elif defined(OS_POSIX) |
| 42 | extern "C" { |
[email protected] | e14a9f9 | 2009-08-05 19:26:07 | [diff] [blame] | 43 | __attribute__((visibility("default"))) |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 44 | int ChromeMain(int argc, const char** argv); |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 45 | } |
| 46 | #endif |
[email protected] | 9c50aa4 | 2008-08-01 15:54:35 | [diff] [blame] | 47 | |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 48 | #if defined(OS_WIN) |
| 49 | DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, |
grt | a237cc4 | 2016-09-20 22:56:19 | [diff] [blame] | 50 | sandbox::SandboxInterfaceInfo* sandbox_info, |
| 51 | int64_t exe_entry_point_ticks) { |
[email protected] | 8a820c8 | 2014-03-09 18:06:58 | [diff] [blame] | 52 | #elif defined(OS_POSIX) |
| 53 | int ChromeMain(int argc, const char** argv) { |
grt | a237cc4 | 2016-09-20 22:56:19 | [diff] [blame] | 54 | int64_t exe_entry_point_ticks = 0; |
[email protected] | 8a820c8 | 2014-03-09 18:06:58 | [diff] [blame] | 55 | #endif |
scottmg | 255cf55 | 2014-12-04 00:25:20 | [diff] [blame] | 56 | |
grt | e29f8ab | 2016-11-15 22:26:30 | [diff] [blame] | 57 | #if defined(OS_WIN) |
grt | a47e865 | 2017-01-18 23:45:06 | [diff] [blame] | 58 | install_static::InitializeFromPrimaryModule(); |
grt | e29f8ab | 2016-11-15 22:26:30 | [diff] [blame] | 59 | #endif |
| 60 | |
grt | a237cc4 | 2016-09-20 22:56:19 | [diff] [blame] | 61 | ChromeMainDelegate chrome_main_delegate( |
| 62 | base::TimeTicks::FromInternalValue(exe_entry_point_ticks)); |
[email protected] | 8a820c8 | 2014-03-09 18:06:58 | [diff] [blame] | 63 | content::ContentMainParams params(&chrome_main_delegate); |
| 64 | |
| 65 | #if defined(OS_WIN) |
brucedawson | 695bdb6e | 2017-06-27 22:45:59 | [diff] [blame] | 66 | // The process should crash when going through abnormal termination, but we |
| 67 | // must be sure to reset this setting when ChromeMain returns normally. |
| 68 | auto crash_on_detach_resetter = base::ScopedClosureRunner( |
| 69 | base::Bind(&base::win::SetShouldCrashOnProcessDetach, |
| 70 | base::win::ShouldCrashOnProcessDetach())); |
[email protected] | 36a2f08 | 2013-08-27 05:33:57 | [diff] [blame] | 71 | base::win::SetShouldCrashOnProcessDetach(true); |
| 72 | base::win::SetAbortBehaviorForCrashReporting(); |
[email protected] | 8a820c8 | 2014-03-09 18:06:58 | [diff] [blame] | 73 | params.instance = instance; |
| 74 | params.sandbox_info = sandbox_info; |
[email protected] | f0e90cf9 | 2014-07-21 17:13:58 | [diff] [blame] | 75 | |
wfh | 9384627 | 2017-06-28 11:50:47 | [diff] [blame] | 76 | // Pass chrome_elf's copy of DumpProcessWithoutCrash resolved via load-time |
| 77 | // dynamic linking. |
| 78 | base::debug::SetDumpWithoutCrashingFunction(&DumpProcessWithoutCrash); |
grt | e29f8ab | 2016-11-15 22:26:30 | [diff] [blame] | 79 | |
| 80 | // Verify that chrome_elf and this module (chrome.dll and chrome_child.dll) |
| 81 | // have the same version. |
| 82 | if (install_static::InstallDetails::Get().VersionMismatch()) |
| 83 | base::debug::DumpWithoutCrashing(); |
[email protected] | 8a820c8 | 2014-03-09 18:06:58 | [diff] [blame] | 84 | #else |
| 85 | params.argc = argc; |
| 86 | params.argv = argv; |
sky | d6439ec | 2016-02-23 23:18:24 | [diff] [blame] | 87 | base::CommandLine::Init(params.argc, params.argv); |
dvallet | 8303a91 | 2017-05-13 01:18:11 | [diff] [blame] | 88 | #endif // defined(OS_WIN) |
| 89 | base::CommandLine::Init(0, nullptr); |
skyostil | b354f88 | 2016-12-13 18:42:45 | [diff] [blame] | 90 | const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess()); |
| 91 | ALLOW_UNUSED_LOCAL(command_line); |
sadrul | 59e835de | 2016-09-22 00:59:15 | [diff] [blame] | 92 | |
Robert Sesek | 81ea450 | 2018-09-04 15:12:18 | [diff] [blame] | 93 | #if defined(OS_MACOSX) |
| 94 | SetUpBundleOverrides(); |
| 95 | #endif |
| 96 | |
Alexei Svitkine | a40cefb | 2019-06-05 05:14:22 | [diff] [blame] | 97 | // Start the sampling profiler as early as possible - namely, once the command |
| 98 | // line data is available. Allocated as an object on the stack to ensure that |
| 99 | // the destructor runs on shutdown, which is important to avoid the profiler |
| 100 | // thread's destruction racing with main thread destruction. |
| 101 | MainThreadStackSamplingProfiler scoped_sampling_profiler; |
| 102 | |
Kunihiko Sakamoto | 7a07960 | 2018-08-03 05:19:12 | [diff] [blame] | 103 | // Chrome-specific process modes. |
Peter Collingbourne | 381beab3 | 2018-08-02 19:42:51 | [diff] [blame] | 104 | #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) |
Kunihiko Sakamoto | 7a07960 | 2018-08-03 05:19:12 | [diff] [blame] | 105 | if (command_line->HasSwitch(switches::kHeadless)) { |
dvallet | 8303a91 | 2017-05-13 01:18:11 | [diff] [blame] | 106 | return headless::HeadlessShellMain(params); |
Kunihiko Sakamoto | 7a07960 | 2018-08-03 05:19:12 | [diff] [blame] | 107 | } |
dvallet | 8303a91 | 2017-05-13 01:18:11 | [diff] [blame] | 108 | #endif // defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) |
skyostil | b354f88 | 2016-12-13 18:42:45 | [diff] [blame] | 109 | |
[email protected] | 8a820c8 | 2014-03-09 18:06:58 | [diff] [blame] | 110 | int rv = content::ContentMain(params); |
| 111 | |
[email protected] | 8a820c8 | 2014-03-09 18:06:58 | [diff] [blame] | 112 | return rv; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 113 | } |