diff options
author | jschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-14 23:27:55 +0000 |
---|---|---|
committer | jschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-14 23:27:55 +0000 |
commit | 5d0343d5e8235f056596a077bf3cc1ef2b4fa286 (patch) | |
tree | be21fa29c93d1a133a7a6ef5fb0a41595a4b16c4 /chrome/app/chrome_exe_main_win.cc | |
parent | 6b0a5d7161ba4266defe00506a9ef2187873c2e1 (diff) | |
download | chromium_src-5d0343d5e8235f056596a077bf3cc1ef2b4fa286.zip chromium_src-5d0343d5e8235f056596a077bf3cc1ef2b4fa286.tar.gz chromium_src-5d0343d5e8235f056596a077bf3cc1ef2b4fa286.tar.bz2 |
Track and cap thread creation
This is to help track down some crashes we're seeing with massive numbers of threads.
Review URL: https://chromiumcodereview.appspot.com/10928207
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/app/chrome_exe_main_win.cc')
-rw-r--r-- | chrome/app/chrome_exe_main_win.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/chrome/app/chrome_exe_main_win.cc b/chrome/app/chrome_exe_main_win.cc index 237784d..f82f361 100644 --- a/chrome/app/chrome_exe_main_win.cc +++ b/chrome/app/chrome_exe_main_win.cc @@ -14,6 +14,43 @@ #include "content/public/common/result_codes.h" #include "sandbox/win/src/sandbox_factory.h" +namespace { + +// TODO(jschuh): Remove this after we narrow down the cause of the crashes. +class ThreadTracker { + public: + static void NTAPI UpdateCount(PVOID module, DWORD reason, PVOID reserved) { + if (reason == DLL_THREAD_ATTACH) { + if (::InterlockedIncrement(&count_) > cap_) + __debugbreak(); + } else if (reason == DLL_THREAD_DETACH) { + ::InterlockedDecrement(&count_); + } + } + + static void SetCap(LONG cap) { cap_ = cap; } + + private: + static LONG volatile count_; + static LONG volatile cap_; +}; + +LONG volatile ThreadTracker::count_ = 1; +LONG volatile ThreadTracker::cap_ = LONG_MAX; + +} // namespace + +// Magic required to get our function called on thread attach and detach. +extern "C" { +#pragma data_seg(push, old_seg) +#pragma data_seg(".CRT$XLB") +PIMAGE_TLS_CALLBACK p_thread_callback = ThreadTracker::UpdateCount; +#pragma data_seg(pop, old_seg) + +#pragma comment(linker, "/INCLUDE:__tls_used") +#pragma comment(linker, "/INCLUDE:_p_thread_callback") +} + int RunChrome(HINSTANCE instance) { bool exit_now = true; // We restarted because of a previous crash. Ask user if we should relaunch. @@ -26,6 +63,10 @@ int RunChrome(HINSTANCE instance) { sandbox::SandboxInterfaceInfo sandbox_info = {0}; content::InitializeSandboxInfo(&sandbox_info); + // Cap the threads for any sandboxed process. + if (sandbox_info.target_services) + ThreadTracker::SetCap(200); + // Load and launch the chrome dll. *Everything* happens inside. MainDllLoader* loader = MakeMainDllLoader(); int rc = loader->Launch(instance, &sandbox_info); |