OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 #include "util/win/critical_section_with_debug_info.h" | |
16 | |
17 namespace crashpad { | |
18 | |
19 namespace { | |
20 | |
21 BOOL CrashpadInitializeCriticalSectionEx( | |
22 CRITICAL_SECTION* critical_section, | |
23 DWORD spin_count, | |
24 DWORD flags) { | |
25 static decltype(InitializeCriticalSectionEx)* initialize_critical_section_ex = | |
26 reinterpret_cast<decltype(InitializeCriticalSectionEx)*>(GetProcAddress( | |
27 LoadLibrary(L"kernel32.dll"), "InitializeCriticalSectionEx")); | |
28 if (!initialize_critical_section_ex) | |
29 return false; | |
30 return initialize_critical_section_ex(critical_section, spin_count, flags); | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 bool InitializeCriticalSectionWithDebugInfoIfPossible( | |
Mark Mentovai
2015/10/16 19:42:47
Add a test for this. All you have to do is call it
scottmg
2015/10/16 20:04:11
Done.
| |
36 CRITICAL_SECTION* critical_section) { | |
37 // On XP and Vista, a plain initialization causes the CRITICAL_SECTION to be | |
38 // allocated with .DebugInfo. On 8 and above, we can pass an additional flag | |
39 // to InitializeCriticalSectionEx() to force the .DebugInfo on. Before Win 8, | |
40 // that flag causes InitializeCriticalSectionEx() to fail. So, for XP, Vista, | |
41 // and 7 we use InitializeCriticalSection(), and for 8 and above, | |
42 // InitializeCriticalSectionEx() with the additional flag. | |
43 // | |
44 // TODO(scottmg): Try to find a solution for Win 7. It's unclear how to force | |
45 // it on for Win 7, however the Loader Lock does have .DebugInfo so there may | |
Mark Mentovai
2015/10/16 19:42:47
Since on Windows 7 (and older), the loader lock ha
scottmg
2015/10/16 20:04:11
Yes, we should have all of them on XP and Vista. W
| |
46 // be a way to do it. The comments in winnt.h imply that perhaps it's passed | |
47 // to InitializeCriticalSectionAndSpinCount() as the top bits of the spin | |
48 // count, but that doesn't appear to work. For now, we initialize a valid | |
49 // CRITICAL_SECTION, but without .DebugInfo. | |
50 | |
51 const DWORD version = GetVersion(); | |
52 const DWORD major_version = LOBYTE(LOWORD(version)); | |
53 const DWORD minor_version = HIBYTE(LOWORD(version)); | |
54 const bool win7_or_lower = | |
55 major_version < 6 || (major_version == 6 && minor_version <= 1); | |
56 | |
57 if (win7_or_lower) { | |
58 InitializeCriticalSection(critical_section); | |
59 return true; | |
60 } | |
61 | |
62 return CrashpadInitializeCriticalSectionEx( | |
63 critical_section, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); | |
64 } | |
65 | |
66 } // namespace crashpad | |
OLD | NEW |