Chromium Code Reviews| 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> |
| 11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 12 #include <sys/syscall.h> | 12 #include <sys/syscall.h> |
| 13 #include <unistd.h> | 13 #include <unistd.h> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
| 19 #include "base/files/scoped_file.h" | 19 #include "base/files/scoped_file.h" |
| 20 #include "base/format_macros.h" | 20 #include "base/format_macros.h" |
| 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/platform_thread.h" | |
| 30 #include "base/threading/thread.h" | 31 #include "base/threading/thread.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 kNumRetriesTranslatingTid = 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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); |
| 283 bool syscall_supported = false; | 290 bool syscall_supported = false; |
| 284 pid_t crashing_tid = | 291 pid_t crashing_tid = -1; |
| 285 base::FindThreadIDWithSyscall(crashing_pid, | 292 for (int i = 0; i < kNumRetriesTranslatingTid; ++i) { |
| 286 expected_syscall_data, | 293 crashing_tid = base::FindThreadIDWithSyscall(crashing_pid, |
| 287 &syscall_supported); | 294 expected_syscall_data, |
| 295 &syscall_supported); | |
|
Lei Zhang
2016/07/22 23:37:36
If |syscall_supported| comes back false, this shou
wzhong
2016/07/23 00:25:11
Acknowledged.
wzhong
2016/07/25 15:12:43
Done.
| |
| 296 if (crashing_tid != -1) | |
| 297 break; | |
| 298 | |
| 299 base::PlatformThread::Sleep( | |
|
Lei Zhang
2016/07/22 23:37:36
It's not good to sleep on the IO (AKA IPC) thread
wzhong
2016/07/23 00:25:11
Good point. It should be doable although context n
wzhong
2016/07/23 00:30:11
Actually I'd still prefer PostDelayedTask().
wzhong
2016/07/25 15:12:43
Done.
| |
| 300 base::TimeDelta::FromMilliseconds(kRetryIntervalTranslatingTidInMs)); | |
| 301 } | |
| 288 if (crashing_tid == -1) { | 302 if (crashing_tid == -1) { |
| 289 // We didn't find the thread we want. Maybe it didn't reach | 303 // 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 | 304 // 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 | 305 // guess here and assume the crashing thread is the thread group |
| 292 // leader. If procfs syscall is not supported by the kernel, then | 306 // leader. If procfs syscall is not supported by the kernel, then |
| 293 // we assume the kernel also does not support TID namespacing and | 307 // we assume the kernel also does not support TID namespacing and |
| 294 // trust the TID passed by the crashing process. | 308 // trust the TID passed by the crashing process. |
| 295 LOG(WARNING) << "Could not translate tid - assuming crashing thread is " | 309 LOG(WARNING) << "Could not translate tid - assuming crashing thread is " |
| 296 "thread group leader; syscall_supported=" << syscall_supported; | 310 "thread group leader; syscall_supported=" << syscall_supported; |
| 297 crashing_tid = crashing_pid; | 311 crashing_tid = crashing_pid; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 // no-ops. | 449 // no-ops. |
| 436 shutting_down_ = true; | 450 shutting_down_ = true; |
| 437 uploader_thread_->Stop(); | 451 uploader_thread_->Stop(); |
| 438 } | 452 } |
| 439 | 453 |
| 440 bool CrashHandlerHostLinux::IsShuttingDown() const { | 454 bool CrashHandlerHostLinux::IsShuttingDown() const { |
| 441 return shutting_down_; | 455 return shutting_down_; |
| 442 } | 456 } |
| 443 | 457 |
| 444 } // namespace breakpad | 458 } // namespace breakpad |
| OLD | NEW |