Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: base/win/dllmain.cc

Issue 9803002: [windows] Make calls to exit(), _exit(), abort(), and ExitProcess() from the renderer process resul… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address brettw comments Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/win/win_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Windows doesn't support pthread_key_create's destr_function, and in fact 5 // Windows doesn't support pthread_key_create's destr_function, and in fact
6 // it's a bit tricky to get code to run when a thread exits. This is 6 // it's a bit tricky to get code to run when a thread exits. This is
7 // cargo-cult magic from http://www.codeproject.com/threads/tls.asp. 7 // cargo-cult magic from http://www.codeproject.com/threads/tls.asp.
8 // We are trying to be compatible with both a LoadLibrary style invocation, as 8 // We are trying to be compatible with both a LoadLibrary style invocation, as
9 // well as static linking. This code only needs to be included if we use 9 // well as static linking. This code only needs to be included if we use
10 // LoadLibrary, but it hooks into the "standard" set of TLS callbacks that are 10 // LoadLibrary, but it hooks into the "standard" set of TLS callbacks that are
11 // provided for static linking. 11 // provided for static linking.
12 12
13 // This code is deliberately written to match the style of calls seen in 13 // This code is deliberately written to match the style of calls seen in
14 // base/threading/thread_local_storage_win.cc. Please keep the two in sync if 14 // base/threading/thread_local_storage_win.cc. Please keep the two in sync if
15 // coding conventions are changed. 15 // coding conventions are changed.
16 16
17 // WARNING: Do *NOT* try to include this in the construction of the base 17 // WARNING: Do *NOT* try to include this in the construction of the base
18 // library, even though it potentially drives code in 18 // library, even though it potentially drives code in
19 // base/threading/thread_local_storage_win.cc. If you do, some users will end 19 // base/threading/thread_local_storage_win.cc. If you do, some users will end
20 // up getting duplicate definition of DllMain() in some of their later links. 20 // up getting duplicate definition of DllMain() in some of their later links.
21 21
22 // Force a reference to _tls_used to make the linker create the TLS directory 22 // Force a reference to _tls_used to make the linker create the TLS directory
23 // if it's not already there (that is, even if __declspec(thread) is not used). 23 // if it's not already there (that is, even if __declspec(thread) is not used).
24 // Force a reference to p_thread_callback_dllmain_typical_entry to prevent whole 24 // Force a reference to p_thread_callback_dllmain_typical_entry to prevent whole
25 // program optimization from discarding the variables. 25 // program optimization from discarding the variables.
26 26
27 #include <windows.h> 27 #include <windows.h>
28 28
29 #include "base/logging.h" 29 #include "base/compiler_specific.h"
30 #include "base/win/win_util.h"
30 31
31 // Indicate if another service is scanning the callbacks. When this becomes 32 // Indicate if another service is scanning the callbacks. When this becomes
32 // set to true, then DllMain() will stop supporting the callback service. This 33 // set to true, then DllMain() will stop supporting the callback service. This
33 // value is set to true the first time any of our callbacks are called, as that 34 // value is set to true the first time any of our callbacks are called, as that
34 // shows that some other service is handling callbacks. 35 // shows that some other service is handling callbacks.
35 static bool linker_notifications_are_active = false; 36 static bool linker_notifications_are_active = false;
36 37
37 // This will be our mostly no-op callback that we'll list. We won't 38 // This will be our mostly no-op callback that we'll list. We won't
38 // deliberately call it, and if it is called, that means we don't need to do any 39 // deliberately call it, and if it is called, that means we don't need to do any
39 // of the callbacks anymore. We expect such a call to arrive via a 40 // of the callbacks anymore. We expect such a call to arrive via a
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 #pragma data_seg(push, old_seg) 78 #pragma data_seg(push, old_seg)
78 // Use a typical possible name in the .CRT$XL? list of segments. 79 // Use a typical possible name in the .CRT$XL? list of segments.
79 #pragma data_seg(".CRT$XLB") 80 #pragma data_seg(".CRT$XLB")
80 PIMAGE_TLS_CALLBACK p_thread_callback_dllmain_typical_entry = on_callback; 81 PIMAGE_TLS_CALLBACK p_thread_callback_dllmain_typical_entry = on_callback;
81 #pragma data_seg(pop, old_seg) 82 #pragma data_seg(pop, old_seg)
82 83
83 #endif // _WIN64 84 #endif // _WIN64
84 } // extern "C" 85 } // extern "C"
85 86
87 NOINLINE static void CrashOnProcessDetach() {
88 *((int*)0) = 0x356;
89 }
86 90
87 // Make DllMain call the listed callbacks. This way any third parties that are 91 // Make DllMain call the listed callbacks. This way any third parties that are
88 // linked in will also be called. 92 // linked in will also be called.
89 BOOL WINAPI DllMain(PVOID h, DWORD reason, PVOID reserved) { 93 BOOL WINAPI DllMain(PVOID h, DWORD reason, PVOID reserved) {
94 if (DLL_PROCESS_DETACH == reason && base::win::ShouldCrashOnProcessDetach())
95 CrashOnProcessDetach();
96
90 if (DLL_THREAD_DETACH != reason && DLL_PROCESS_DETACH != reason) 97 if (DLL_THREAD_DETACH != reason && DLL_PROCESS_DETACH != reason)
91 return true; // We won't service THREAD_ATTACH calls. 98 return true; // We won't service THREAD_ATTACH calls.
92 99
93 if (linker_notifications_are_active) 100 if (linker_notifications_are_active)
94 return true; // Some other service is doing this work. 101 return true; // Some other service is doing this work.
95 102
96 for (PIMAGE_TLS_CALLBACK* it = &__xl_a; it < &__xl_z; ++it) { 103 for (PIMAGE_TLS_CALLBACK* it = &__xl_a; it < &__xl_z; ++it) {
97 if (*it == NULL || *it == on_callback) 104 if (*it == NULL || *it == on_callback)
98 continue; // Don't bother to call our own callback. 105 continue; // Don't bother to call our own callback.
99 (*it)(h, reason, reserved); 106 (*it)(h, reason, reserved);
100 } 107 }
101 return true; 108 return true;
102 } 109 }
103 110
104 static void NTAPI on_callback(PVOID h, DWORD reason, PVOID reserved) { 111 static void NTAPI on_callback(PVOID h, DWORD reason, PVOID reserved) {
105 // Do nothing. We were just a place holder in the list used to test that we 112 // Do nothing. We were just a place holder in the list used to test that we
106 // call all items. 113 // call all items.
107 // If we are called, it means that some other system is scanning the callbacks 114 // If we are called, it means that some other system is scanning the callbacks
108 // and we don't need to do so in DllMain(). 115 // and we don't need to do so in DllMain().
109 linker_notifications_are_active = true; 116 linker_notifications_are_active = true;
110 // Note: If some other routine some how plays this same game... we could both 117 // Note: If some other routine some how plays this same game... we could both
111 // decide not to do the scanning <sigh>, but this trick should suppress 118 // decide not to do the scanning <sigh>, but this trick should suppress
112 // duplicate calls on Vista, where the runtime takes care of the callbacks, 119 // duplicate calls on Vista, where the runtime takes care of the callbacks,
113 // and allow us to do the callbacks on XP, where we are currently devoid of 120 // and allow us to do the callbacks on XP, where we are currently devoid of
114 // callbacks (due to an explicit LoadLibrary call). 121 // callbacks (due to an explicit LoadLibrary call).
115 } 122 }
OLDNEW
« no previous file with comments | « no previous file | base/win/win_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698