chromium WinMain

入口函数

这里研究和分析一下chromium启动的初步,浅析一下。
我们先从整体看一下,普通情况下,chromium的主进程主线程的运行情况,看一下栈路径

0:000> kL
 # Child-SP          RetAddr           Call Site
00 00000000`002ef1c8 000007fe`fd8c1420 ntdll!NtWaitForMultipleObjects+0xa
01 00000000`002ef1d0 00000000`76c12cf3 KERNELBASE!WaitForMultipleObjectsEx+0xe8
02 00000000`002ef2d0 00000000`77098f7d kernel32!WaitForMultipleObjectsExImplementation+0xb3
03 00000000`002ef360 00000000`770962b2 USER32!RealMsgWaitForMultipleObjectsEx+0x12a
04 00000000`002ef400 000007fe`ec2b1c9c USER32!MsgWaitForMultipleObjectsEx+0x46
05 00000000`002ef440 000007fe`ec2b1b11 chrome_7feec210000!base::MessagePumpForUI::WaitForWork+0x2c
06 00000000`002ef4b0 000007fe`ec2b1732 chrome_7feec210000!base::MessagePumpForUI::DoRunLoop+0xe1
07 00000000`002ef520 000007fe`ec29dd83 chrome_7feec210000!base::MessagePumpWin::Run+0x42
08 (Inline Function) --------`-------- chrome_7feec210000!base::MessageLoop::RunHandler+0x15
09 00000000`002ef560 000007fe`ecb5b8a8 chrome_7feec210000!base::RunLoop::Run+0x83
0a 00000000`002ef5b0 000007fe`ed33f870 chrome_7feec210000!ChromeBrowserMainParts::MainMessageLoopRun+0xbc
0b 00000000`002ef630 000007fe`ed33b993 chrome_7feec210000!content::BrowserMainLoop::RunMainMessageLoopParts+0x74
0c 00000000`002ef680 000007fe`ed2e3c15 chrome_7feec210000!content::BrowserMainRunnerImpl::Run+0x17
0d 00000000`002ef6b0 000007fe`ecbf17d6 chrome_7feec210000!content::BrowserMain+0x101
0e 00000000`002ef730 000007fe`ecbf1613 chrome_7feec210000!content::RunNamedProcessTypeMain+0x18e
0f 00000000`002ef8a0 000007fe`ecbeeae1 chrome_7feec210000!content::ContentMainRunnerImpl::Run+0x93
10 00000000`002ef930 000007fe`ecae1c7e chrome_7feec210000!content::ContentMain+0x35
11 00000000`002ef960 00000001`3ffa0f6f chrome_7feec210000!ChromeMain+0x82
12 00000000`002ef9f0 00000001`3ffa01b0 chrome!MainDllLoader::Launch+0x317
13 00000000`002efb10 00000001`3ffde018 chrome!wWinMain+0x234
14 00000000`002efd30 00000000`76c0652d chrome!__tmainCRTStartup+0x148
15 00000000`002efd70 00000000`772fc521 kernel32!BaseThreadInitThunk+0xd
16 00000000`002efda0 00000000`00000000 ntdll!RtlUserThreadStart+0x1d

wWinMain

一般情况下,在chromium的目录结构中,位于*\app文件夹中的文件基本上都是模块的启动代码文件。我们从进程启动处看。其位于chrome_exe_main_win.cc文件中,位于chrome\app的文件夹根目录里。


#if !defined(WIN_CONSOLE_APP)
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) {
#else
int main() {
  HINSTANCE instance = GetModuleHandle(nullptr);
#endif
  // Initialize the CommandLine singleton from the environment.
  base::CommandLine::Init(0, nullptr);
  const base::CommandLine* command_line =
      base::CommandLine::ForCurrentProcess();

  const std::string process_type =
      command_line->GetSwitchValueASCII(switches::kProcessType);

  startup_metric_utils::InitializePreReadOptions(
      BrowserDistribution::GetDistribution()->GetRegistryPath());

  // Confirm that an explicit prefetch profile is used for all process types
  // except for the browser process. Any new process type will have to assign
  // itself a prefetch id. See kPrefetchArgument* constants in
  // content_switches.cc for details.
  DCHECK(!startup_metric_utils::GetPreReadOptions().use_prefetch_argument ||
         process_type.empty() ||
         HasValidWindowsPrefetchArgument(*command_line));

  if (process_type == crash_reporter::switches::kCrashpadHandler) {
    return crash_reporter::RunAsCrashpadHandler(
        *base::CommandLine::ForCurrentProcess());
  }

  crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer());
  crash_reporter::InitializeCrashpadWithEmbeddedHandler(process_type.empty(),
                                                        process_type);

  SwitchToLFHeap();

  startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now());

  // Signal Chrome Elf that Chrome has begun to start.
  SignalChromeElf();

  // The exit manager is in charge of calling the dtors of singletons.
  base::AtExitManager exit_manager;

  // We don't want to set DPI awareness on pre-Win7 because we don't support
  // DirectWrite there. GDI fonts are kerned very badly, so better to leave
  // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite().
  if (base::win::GetVersion() >= base::win::VERSION_WIN7)
    EnableHighDPISupport();

  if (AttemptFastNotify(*command_line))
    return 0;

  // Load and launch the chrome dll. *Everything* happens inside.
  VLOG(1) << "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值