Chromium Code Reviews| Index: base/win/dllmain.cc |
| diff --git a/base/win/dllmain.cc b/base/win/dllmain.cc |
| index fad951905ddb3b01301ee6ba9eec12becf8da13d..f18cf711c6635fe2a169833861394f306a683d73 100644 |
| --- a/base/win/dllmain.cc |
| +++ b/base/win/dllmain.cc |
| @@ -26,7 +26,7 @@ |
| #include <windows.h> |
| -#include "base/logging.h" |
| +#include "base/compiler_specific.h" |
| // Indicate if another service is scanning the callbacks. When this becomes |
| // set to true, then DllMain() will stop supporting the callback service. This |
| @@ -34,6 +34,9 @@ |
| // shows that some other service is handling callbacks. |
| static bool linker_notifications_are_active = false; |
| +// Indicates if we should crash in response to DLL_PROCESS_DETACH. |
| +static bool crash_on_process_detach = false; |
| + |
| // This will be our mostly no-op callback that we'll list. We won't |
| // deliberately call it, and if it is called, that means we don't need to do any |
| // of the callbacks anymore. We expect such a call to arrive via a |
| @@ -83,10 +86,16 @@ PIMAGE_TLS_CALLBACK p_thread_callback_dllmain_typical_entry = on_callback; |
| #endif // _WIN64 |
| } // extern "C" |
| +NOINLINE static void CrashOnProcessDetach() { |
| + *((int*)0) = 0x356; |
| +} |
| // Make DllMain call the listed callbacks. This way any third parties that are |
| // linked in will also be called. |
| BOOL WINAPI DllMain(PVOID h, DWORD reason, PVOID reserved) { |
| + if (DLL_PROCESS_DETACH == reason && crash_on_process_detach) |
| + CrashOnProcessDetach(); |
| + |
| if (DLL_THREAD_DETACH != reason && DLL_PROCESS_DETACH != reason) |
| return true; // We won't service THREAD_ATTACH calls. |
| @@ -113,3 +122,13 @@ static void NTAPI on_callback(PVOID h, DWORD reason, PVOID reserved) { |
| // and allow us to do the callbacks on XP, where we are currently devoid of |
| // callbacks (due to an explicit LoadLibrary call). |
| } |
| + |
| +namespace base { |
| +namespace win { |
| + |
| +void DLLMain_SetCrashOnProcessDetach(bool crash) { |
|
rvargas (doing something else)
2012/03/21 03:13:45
This is problematic because this file is not part
eroman
2012/03/21 04:14:31
Good point.
How about if I add exported methods t
rvargas (doing something else)
2012/03/21 17:46:12
Sounds good.
|
| + crash_on_process_detach = crash; |
| +} |
| + |
| +} // namespace win |
| +} // namespace base |