| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <windows.h> | 5 #include <windows.h> |
| 6 #include <tchar.h> | 6 #include <tchar.h> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "chrome/app/breakpad_win.h" | 10 #include "chrome/app/breakpad_win.h" |
| 11 #include "chrome/app/client_util.h" | 11 #include "chrome/app/client_util.h" |
| 12 #include "chrome/app/metro_driver_win.h" | 12 #include "chrome/app/metro_driver_win.h" |
| 13 #include "content/public/app/startup_helper_win.h" | 13 #include "content/public/app/startup_helper_win.h" |
| 14 #include "content/public/common/result_codes.h" | 14 #include "content/public/common/result_codes.h" |
| 15 #include "sandbox/win/src/sandbox_factory.h" | 15 #include "sandbox/win/src/sandbox_factory.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // TODO(jschuh): Remove this after we narrow down the cause of the crashes. | 19 // TODO(jschuh): Remove this after we narrow down the cause of the crashes. |
| 20 class ThreadTracker { | 20 class ThreadTracker { |
| 21 public: | 21 public: |
| 22 static void NTAPI UpdateCount(PVOID module, DWORD reason, PVOID reserved) { | 22 static void NTAPI UpdateCount(PVOID module, DWORD reason, PVOID reserved) { |
| 23 if (reason == DLL_THREAD_ATTACH) { | 23 if (reason == DLL_THREAD_ATTACH) { |
| 24 // We hit the threshold, but the loader would eat an exception fired now. |
| 25 // So schedule an APC to fire the exception once loading is done. |
| 24 if (::InterlockedIncrement(&count_) > cap_) | 26 if (::InterlockedIncrement(&count_) > cap_) |
| 25 __debugbreak(); | 27 ::QueueUserAPC(CrashProcessCallback, ::GetCurrentThread(), NULL); |
| 26 } else if (reason == DLL_THREAD_DETACH) { | 28 } else if (reason == DLL_THREAD_DETACH) { |
| 27 ::InterlockedDecrement(&count_); | 29 ::InterlockedDecrement(&count_); |
| 28 } | 30 } |
| 29 } | 31 } |
| 30 | 32 |
| 31 static void SetCap(LONG cap) { cap_ = cap; } | 33 static void SetCap(LONG cap) { cap_ = cap; } |
| 32 | 34 |
| 33 private: | 35 private: |
| 34 static LONG volatile count_; | 36 static void CALLBACK CrashProcessCallback(ULONG_PTR) { __debugbreak(); } |
| 35 static LONG volatile cap_; | 37 |
| 38 static volatile LONG count_; |
| 39 static volatile LONG cap_; |
| 36 }; | 40 }; |
| 37 | 41 |
| 38 LONG volatile ThreadTracker::count_ = 1; | 42 LONG volatile ThreadTracker::count_ = 1; |
| 39 LONG volatile ThreadTracker::cap_ = LONG_MAX; | 43 LONG volatile ThreadTracker::cap_ = LONG_MAX; |
| 40 | 44 |
| 41 } // namespace | 45 } // namespace |
| 42 | 46 |
| 43 // Magic required to get our function called on thread attach and detach. | 47 // Magic required to get our function called on thread attach and detach. |
| 44 extern "C" { | 48 extern "C" { |
| 45 #pragma data_seg(push, old_seg) | 49 #pragma data_seg(push, old_seg) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 CommandLine::Init(0, NULL); | 84 CommandLine::Init(0, NULL); |
| 81 // The exit manager is in charge of calling the dtors of singletons. | 85 // The exit manager is in charge of calling the dtors of singletons. |
| 82 base::AtExitManager exit_manager; | 86 base::AtExitManager exit_manager; |
| 83 | 87 |
| 84 MetroDriver metro_driver; | 88 MetroDriver metro_driver; |
| 85 if (metro_driver.in_metro_mode()) | 89 if (metro_driver.in_metro_mode()) |
| 86 return metro_driver.RunInMetro(instance, &RunChrome); | 90 return metro_driver.RunInMetro(instance, &RunChrome); |
| 87 // Not in metro mode, proceed as normal. | 91 // Not in metro mode, proceed as normal. |
| 88 return RunChrome(instance); | 92 return RunChrome(instance); |
| 89 } | 93 } |
| OLD | NEW |