OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // This module contains the necessary code to register the Breakpad exception | 5 // This module contains the necessary code to register the Breakpad exception |
6 // handler. This implementation is based on Chrome's crash reporting code. | 6 // handler. This implementation is based on Chrome's crash reporting code. |
7 | 7 |
8 #include "chrome_elf/breakpad.h" | 8 #include "chrome_elf/breakpad.h" |
9 | 9 |
10 #include <sddl.h> | |
11 | |
12 #include "base/macros.h" | 10 #include "base/macros.h" |
13 #include "breakpad/src/client/windows/handler/exception_handler.h" | 11 #include "breakpad/src/client/windows/handler/exception_handler.h" |
14 #include "chrome/common/chrome_version.h" | 12 #include "chrome/common/chrome_version.h" |
| 13 #include "chrome_elf/chrome_elf_reg.h" |
15 #include "chrome_elf/chrome_elf_util.h" | 14 #include "chrome_elf/chrome_elf_util.h" |
16 | 15 |
17 google_breakpad::ExceptionHandler* g_elf_breakpad = NULL; | 16 google_breakpad::ExceptionHandler* g_elf_breakpad = NULL; |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 const wchar_t kBreakpadProductName[] = L"Chrome"; | 20 const wchar_t kBreakpadProductName[] = L"Chrome"; |
22 const wchar_t kBreakpadVersionEntry[] = L"ver"; | 21 const wchar_t kBreakpadVersionEntry[] = L"ver"; |
23 const wchar_t kBreakpadProdEntry[] = L"prod"; | 22 const wchar_t kBreakpadProdEntry[] = L"prod"; |
24 const wchar_t kBreakpadPlatformEntry[] = L"plat"; | 23 const wchar_t kBreakpadPlatformEntry[] = L"plat"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 kBreakpadProcessEntry, process.c_str()); | 56 kBreakpadProcessEntry, process.c_str()); |
58 static google_breakpad::CustomInfoEntry channel_entry( | 57 static google_breakpad::CustomInfoEntry channel_entry( |
59 kBreakpadChannelEntry, channel.c_str()); | 58 kBreakpadChannelEntry, channel.c_str()); |
60 static google_breakpad::CustomInfoEntry entries[] = { | 59 static google_breakpad::CustomInfoEntry entries[] = { |
61 ver_entry, prod_entry, plat_entry, proc_entry, channel_entry}; | 60 ver_entry, prod_entry, plat_entry, proc_entry, channel_entry}; |
62 static google_breakpad::CustomClientInfo custom_info = { | 61 static google_breakpad::CustomClientInfo custom_info = { |
63 entries, arraysize(entries) }; | 62 entries, arraysize(entries) }; |
64 return &custom_info; | 63 return &custom_info; |
65 } | 64 } |
66 | 65 |
67 base::string16 GetUserSidString() { | |
68 // Get the current token. | |
69 HANDLE token = NULL; | |
70 base::string16 user_sid; | |
71 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)) | |
72 return user_sid; | |
73 | |
74 DWORD size = sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE; | |
75 BYTE user_bytes[sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE] = {}; | |
76 TOKEN_USER* user = reinterpret_cast<TOKEN_USER*>(user_bytes); | |
77 | |
78 wchar_t* sid_string = NULL; | |
79 if (::GetTokenInformation(token, TokenUser, user, size, &size) && | |
80 user->User.Sid && | |
81 ::ConvertSidToStringSid(user->User.Sid, &sid_string)) { | |
82 user_sid = sid_string; | |
83 ::LocalFree(sid_string); | |
84 } | |
85 | |
86 CloseHandle(token); | |
87 return user_sid; | |
88 } | |
89 | |
90 bool IsHeadless() { | 66 bool IsHeadless() { |
91 DWORD ret = ::GetEnvironmentVariable(L"CHROME_HEADLESS", NULL, 0); | 67 DWORD ret = ::GetEnvironmentVariable(L"CHROME_HEADLESS", NULL, 0); |
92 if (ret != 0) | 68 if (ret != 0) |
93 return true; | 69 return true; |
94 | 70 |
95 wchar_t* command_line = ::GetCommandLine(); | 71 wchar_t* command_line = ::GetCommandLine(); |
96 | 72 |
97 // Note: Since this is a pure substring search rather than a check for a | 73 // Note: Since this is a pure substring search rather than a check for a |
98 // switch, there is a small chance that this code will match things that the | 74 // switch, there is a small chance that this code will match things that the |
99 // Chrome code (which executes a similar check) does not. However, as long as | 75 // Chrome code (which executes a similar check) does not. However, as long as |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 if (!use_policy && IsHeadless()) { | 127 if (!use_policy && IsHeadless()) { |
152 pipe_name = kChromePipeName; | 128 pipe_name = kChromePipeName; |
153 } else if (use_policy ? | 129 } else if (use_policy ? |
154 enabled_by_policy : | 130 enabled_by_policy : |
155 (is_official_chrome_build && AreUsageStatsEnabled(exe_path))) { | 131 (is_official_chrome_build && AreUsageStatsEnabled(exe_path))) { |
156 // Build the pipe name. It can be one of: | 132 // Build the pipe name. It can be one of: |
157 // 32-bit system: \\.\pipe\GoogleCrashServices\S-1-5-18 | 133 // 32-bit system: \\.\pipe\GoogleCrashServices\S-1-5-18 |
158 // 32-bit user: \\.\pipe\GoogleCrashServices\<user SID> | 134 // 32-bit user: \\.\pipe\GoogleCrashServices\<user SID> |
159 // 64-bit system: \\.\pipe\GoogleCrashServices\S-1-5-18-x64 | 135 // 64-bit system: \\.\pipe\GoogleCrashServices\S-1-5-18-x64 |
160 // 64-bit user: \\.\pipe\GoogleCrashServices\<user SID>-x64 | 136 // 64-bit user: \\.\pipe\GoogleCrashServices\<user SID>-x64 |
161 base::string16 user_sid = IsSystemInstall(exe_path) ? kSystemPrincipalSid : | 137 base::string16 user_sid = IsSystemInstall(exe_path) |
162 GetUserSidString(); | 138 ? kSystemPrincipalSid |
| 139 : nt::GetCurrentUserSidString(); |
163 if (user_sid.empty()) | 140 if (user_sid.empty()) |
164 return; | 141 return; |
165 | 142 |
166 pipe_name = kGoogleUpdatePipeName; | 143 pipe_name = kGoogleUpdatePipeName; |
167 pipe_name += user_sid; | 144 pipe_name += user_sid; |
168 | 145 |
169 #if defined(_WIN64) | 146 #if defined(_WIN64) |
170 pipe_name += L"-x64"; | 147 pipe_name += L"-x64"; |
171 #endif | 148 #endif |
172 } else { | 149 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
183 google_breakpad::ExceptionHandler::HANDLER_ALL, | 160 google_breakpad::ExceptionHandler::HANDLER_ALL, |
184 dump_type, | 161 dump_type, |
185 pipe_name.c_str(), | 162 pipe_name.c_str(), |
186 GetCustomInfo()); | 163 GetCustomInfo()); |
187 | 164 |
188 if (g_elf_breakpad->IsOutOfProcess()) { | 165 if (g_elf_breakpad->IsOutOfProcess()) { |
189 // Tells breakpad to handle breakpoint and single step exceptions. | 166 // Tells breakpad to handle breakpoint and single step exceptions. |
190 g_elf_breakpad->set_handle_debug_exceptions(true); | 167 g_elf_breakpad->set_handle_debug_exceptions(true); |
191 } | 168 } |
192 } | 169 } |
OLD | NEW |