Home | History | Annotate | Download | only in app
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/app/chrome_main_delegate.h"
      6 
      7 #include "content/public/app/content_main.h"
      8 
      9 #if defined(OS_WIN)
     10 #include "base/debug/dump_without_crashing.h"
     11 #include "base/win/win_util.h"
     12 #include "chrome/common/chrome_constants.h"
     13 
     14 #define DLLEXPORT __declspec(dllexport)
     15 
     16 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
     17 extern "C" {
     18 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
     19                                  sandbox::SandboxInterfaceInfo* sandbox_info);
     20 }
     21 #elif defined(OS_POSIX)
     22 extern "C" {
     23 __attribute__((visibility("default")))
     24 int ChromeMain(int argc, const char** argv);
     25 }
     26 #endif
     27 
     28 #if defined(OS_WIN)
     29 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
     30                                  sandbox::SandboxInterfaceInfo* sandbox_info) {
     31 #elif defined(OS_POSIX)
     32 int ChromeMain(int argc, const char** argv) {
     33 #endif
     34   ChromeMainDelegate chrome_main_delegate;
     35   content::ContentMainParams params(&chrome_main_delegate);
     36 
     37 #if defined(OS_WIN)
     38   // The process should crash when going through abnormal termination.
     39   base::win::SetShouldCrashOnProcessDetach(true);
     40   base::win::SetAbortBehaviorForCrashReporting();
     41   params.instance = instance;
     42   params.sandbox_info = sandbox_info;
     43 
     44   // SetDumpWithoutCrashingFunction must be passed the DumpProcess function
     45   // from the EXE and not from the DLL in order for DumpWithoutCrashing to
     46   // function correctly.
     47   typedef void (__cdecl *DumpProcessFunction)();
     48   DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>(
     49       ::GetProcAddress(::GetModuleHandle(chrome::kBrowserProcessExecutableName),
     50           "DumpProcessWithoutCrash"));
     51   base::debug::SetDumpWithoutCrashingFunction(DumpProcess);
     52 #else
     53   params.argc = argc;
     54   params.argv = argv;
     55 #endif
     56 
     57   int rv = content::ContentMain(params);
     58 
     59 #if defined(OS_WIN)
     60   base::win::SetShouldCrashOnProcessDetach(false);
     61 #endif
     62 
     63   return rv;
     64 }
     65