OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "components/crash/content/browser/crash_handler_host_linux.h" | 5 #include "components/crash/content/browser/crash_handler_host_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/linux_util.h" | 21 #include "base/linux_util.h" |
22 #include "base/location.h" | 22 #include "base/location.h" |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/path_service.h" | 24 #include "base/path_service.h" |
25 #include "base/posix/eintr_wrapper.h" | 25 #include "base/posix/eintr_wrapper.h" |
26 #include "base/rand_util.h" | 26 #include "base/rand_util.h" |
27 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
29 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
30 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
| 31 #include "base/threading/thread_task_runner_handle.h" |
31 #include "breakpad/src/client/linux/handler/exception_handler.h" | 32 #include "breakpad/src/client/linux/handler/exception_handler.h" |
32 #include "breakpad/src/client/linux/minidump_writer/linux_dumper.h" | 33 #include "breakpad/src/client/linux/minidump_writer/linux_dumper.h" |
33 #include "breakpad/src/client/linux/minidump_writer/minidump_writer.h" | 34 #include "breakpad/src/client/linux/minidump_writer/minidump_writer.h" |
34 #include "build/build_config.h" | 35 #include "build/build_config.h" |
35 #include "components/crash/content/app/breakpad_linux_impl.h" | 36 #include "components/crash/content/app/breakpad_linux_impl.h" |
36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
37 | 38 |
38 #if defined(OS_ANDROID) && !defined(__LP64__) | 39 #if defined(OS_ANDROID) && !defined(__LP64__) |
39 #include <sys/linux-syscalls.h> | 40 #include <sys/linux-syscalls.h> |
40 | 41 |
41 #define SYS_read __NR_read | 42 #define SYS_read __NR_read |
42 #endif | 43 #endif |
43 | 44 |
44 using content::BrowserThread; | 45 using content::BrowserThread; |
45 using google_breakpad::ExceptionHandler; | 46 using google_breakpad::ExceptionHandler; |
46 | 47 |
47 namespace breakpad { | 48 namespace breakpad { |
48 | 49 |
49 namespace { | 50 namespace { |
50 | 51 |
51 const size_t kNumFDs = 1; | 52 const size_t kNumFDs = 1; |
52 // The length of the control message: | 53 // The length of the control message: |
53 const size_t kControlMsgSize = | 54 const size_t kControlMsgSize = |
54 CMSG_SPACE(kNumFDs * sizeof(int)) + CMSG_SPACE(sizeof(struct ucred)); | 55 CMSG_SPACE(kNumFDs * sizeof(int)) + CMSG_SPACE(sizeof(struct ucred)); |
55 // The length of the regular payload: | 56 // The length of the regular payload: |
56 const size_t kCrashContextSize = sizeof(ExceptionHandler::CrashContext); | 57 const size_t kCrashContextSize = sizeof(ExceptionHandler::CrashContext); |
57 | 58 |
| 59 // Crashing thread might be in "running" state, i.e. after sys_sendmsg() and |
| 60 // before sys_read(). Retry 3 times with interval of 100 ms when translating |
| 61 // TID. |
| 62 const int kNumAttemptsTranslatingTid = 3; |
| 63 const int kRetryIntervalTranslatingTidInMs = 100; |
| 64 |
58 // Handles the crash dump and frees the allocated BreakpadInfo struct. | 65 // Handles the crash dump and frees the allocated BreakpadInfo struct. |
59 void CrashDumpTask(CrashHandlerHostLinux* handler, | 66 void CrashDumpTask(CrashHandlerHostLinux* handler, |
60 std::unique_ptr<BreakpadInfo> info) { | 67 std::unique_ptr<BreakpadInfo> info) { |
61 if (handler->IsShuttingDown() && info->upload) { | 68 if (handler->IsShuttingDown() && info->upload) { |
62 base::DeleteFile(base::FilePath(info->filename), false); | 69 base::DeleteFile(base::FilePath(info->filename), false); |
63 #if defined(ADDRESS_SANITIZER) | 70 #if defined(ADDRESS_SANITIZER) |
64 base::DeleteFile(base::FilePath(info->log_filename), false); | 71 base::DeleteFile(base::FilePath(info->log_filename), false); |
65 #endif | 72 #endif |
66 return; | 73 return; |
67 } | 74 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // namespaces also have /proc/[pid]/syscall, so we can look through | 280 // namespaces also have /proc/[pid]/syscall, so we can look through |
274 // |actual_crashing_pid|'s thread group and find the thread that's in the | 281 // |actual_crashing_pid|'s thread group and find the thread that's in the |
275 // read syscall with the right arguments. | 282 // read syscall with the right arguments. |
276 | 283 |
277 std::string expected_syscall_data; | 284 std::string expected_syscall_data; |
278 // /proc/[pid]/syscall is formatted as follows: | 285 // /proc/[pid]/syscall is formatted as follows: |
279 // syscall_number arg1 ... arg6 sp pc | 286 // syscall_number arg1 ... arg6 sp pc |
280 // but we just check syscall_number through arg3. | 287 // but we just check syscall_number through arg3. |
281 base::StringAppendF(&expected_syscall_data, "%d 0x%x %p 0x1 ", | 288 base::StringAppendF(&expected_syscall_data, "%d 0x%x %p 0x1 ", |
282 SYS_read, tid_fd, tid_buf_addr); | 289 SYS_read, tid_fd, tid_buf_addr); |
| 290 |
| 291 FindCrashingThreadAndDump(crashing_pid, |
| 292 expected_syscall_data, |
| 293 std::move(crash_context), |
| 294 std::move(crash_keys), |
| 295 #if defined(ADDRESS_SANITIZER) |
| 296 std::move(asan_report), |
| 297 #endif |
| 298 uptime, |
| 299 oom_size, |
| 300 signal_fd.release(), |
| 301 0); |
| 302 } |
| 303 |
| 304 void CrashHandlerHostLinux::FindCrashingThreadAndDump( |
| 305 pid_t crashing_pid, |
| 306 const std::string& expected_syscall_data, |
| 307 std::unique_ptr<char[]> crash_context, |
| 308 std::unique_ptr<CrashKeyStorage> crash_keys, |
| 309 #if defined(ADDRESS_SANITIZER) |
| 310 std::unique_ptr<char[]> asan_report, |
| 311 #endif |
| 312 uint64_t uptime, |
| 313 size_t oom_size, |
| 314 int signal_fd, |
| 315 int attempt) { |
283 bool syscall_supported = false; | 316 bool syscall_supported = false; |
284 pid_t crashing_tid = | 317 pid_t crashing_tid = base::FindThreadIDWithSyscall( |
285 base::FindThreadIDWithSyscall(crashing_pid, | 318 crashing_pid, expected_syscall_data, &syscall_supported); |
286 expected_syscall_data, | 319 ++attempt; |
287 &syscall_supported); | 320 if (crashing_tid == -1 && syscall_supported && |
| 321 attempt <= kNumAttemptsTranslatingTid) { |
| 322 LOG(WARNING) << "Could not translate tid, attempt = " << attempt |
| 323 << " retry ..."; |
| 324 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 325 FROM_HERE, |
| 326 base::Bind(&CrashHandlerHostLinux::FindCrashingThreadAndDump, |
| 327 base::Unretained(this), |
| 328 crashing_pid, |
| 329 expected_syscall_data, |
| 330 base::Passed(&crash_context), |
| 331 base::Passed(&crash_keys), |
| 332 #if defined(ADDRESS_SANITIZER) |
| 333 base::Passed(&asan_report), |
| 334 #endif |
| 335 uptime, |
| 336 oom_size, |
| 337 signal_fd, |
| 338 attempt), |
| 339 base::TimeDelta::FromMilliseconds(kRetryIntervalTranslatingTidInMs)); |
| 340 return; |
| 341 } |
| 342 |
| 343 |
288 if (crashing_tid == -1) { | 344 if (crashing_tid == -1) { |
289 // We didn't find the thread we want. Maybe it didn't reach | 345 // We didn't find the thread we want. Maybe it didn't reach |
290 // sys_read() yet or the thread went away. We'll just take a | 346 // sys_read() yet or the thread went away. We'll just take a |
291 // guess here and assume the crashing thread is the thread group | 347 // guess here and assume the crashing thread is the thread group |
292 // leader. If procfs syscall is not supported by the kernel, then | 348 // leader. If procfs syscall is not supported by the kernel, then |
293 // we assume the kernel also does not support TID namespacing and | 349 // we assume the kernel also does not support TID namespacing and |
294 // trust the TID passed by the crashing process. | 350 // trust the TID passed by the crashing process. |
295 LOG(WARNING) << "Could not translate tid - assuming crashing thread is " | 351 LOG(WARNING) << "Could not translate tid - assuming crashing thread is " |
296 "thread group leader; syscall_supported=" << syscall_supported; | 352 "thread group leader; syscall_supported=" << syscall_supported; |
297 crashing_tid = crashing_pid; | 353 crashing_tid = crashing_pid; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 387 |
332 | 388 |
333 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( | 389 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( |
334 worker_pool_token_, | 390 worker_pool_token_, |
335 FROM_HERE, | 391 FROM_HERE, |
336 base::Bind(&CrashHandlerHostLinux::WriteDumpFile, | 392 base::Bind(&CrashHandlerHostLinux::WriteDumpFile, |
337 base::Unretained(this), | 393 base::Unretained(this), |
338 base::Passed(&info), | 394 base::Passed(&info), |
339 base::Passed(&crash_context), | 395 base::Passed(&crash_context), |
340 crashing_pid, | 396 crashing_pid, |
341 signal_fd.release())); | 397 signal_fd)); |
342 } | 398 } |
343 | 399 |
344 void CrashHandlerHostLinux::WriteDumpFile(std::unique_ptr<BreakpadInfo> info, | 400 void CrashHandlerHostLinux::WriteDumpFile(std::unique_ptr<BreakpadInfo> info, |
345 std::unique_ptr<char[]> crash_context, | 401 std::unique_ptr<char[]> crash_context, |
346 pid_t crashing_pid, | 402 pid_t crashing_pid, |
347 int signal_fd) { | 403 int signal_fd) { |
348 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 404 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
349 worker_pool_token_)); | 405 worker_pool_token_)); |
350 | 406 |
351 // Set |info->distro| here because base::GetLinuxDistro() needs to run on a | 407 // Set |info->distro| here because base::GetLinuxDistro() needs to run on a |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 // no-ops. | 491 // no-ops. |
436 shutting_down_ = true; | 492 shutting_down_ = true; |
437 uploader_thread_->Stop(); | 493 uploader_thread_->Stop(); |
438 } | 494 } |
439 | 495 |
440 bool CrashHandlerHostLinux::IsShuttingDown() const { | 496 bool CrashHandlerHostLinux::IsShuttingDown() const { |
441 return shutting_down_; | 497 return shutting_down_; |
442 } | 498 } |
443 | 499 |
444 } // namespace breakpad | 500 } // namespace breakpad |
OLD | NEW |