Commit 14d509ec authored by Joshua Peraza's avatar Joshua Peraza Committed by Commit Bot

android: Enable sampling crashpad dumps for WebView

Both the browser and child processes determine whether they will
produce crash dumps at initialization. When crash dumping is disabled
for the browser, no signal handler is installed. Child processes with
crash dumping disabled will still install a signal handler so the
browser and any observers can be notified of the crash, but the child
process will send a byte along with its message to the CrashHandlerHost
noting whether a dump should be produced.

Change-Id: I7acde16b604ecdcad124cb95677e127fc099e0e8
Reviewed-on: https://chromium-review.googlesource.com/c/1298651
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612959}
parent cfc449cd
...@@ -107,6 +107,8 @@ class AwCrashReporterClient : public ::crash_reporter::CrashReporterClient { ...@@ -107,6 +107,8 @@ class AwCrashReporterClient : public ::crash_reporter::CrashReporterClient {
*sanitize_stacks = true; *sanitize_stacks = true;
} }
unsigned int GetCrashDumpPercentageForWebView() override { return 100; }
private: private:
int dump_fd_; int dump_fd_;
int crash_signal_fd_; int crash_signal_fd_;
......
...@@ -148,6 +148,10 @@ bool CrashReporterClient::ReportingIsEnforcedByPolicy(bool* breakpad_enabled) { ...@@ -148,6 +148,10 @@ bool CrashReporterClient::ReportingIsEnforcedByPolicy(bool* breakpad_enabled) {
} }
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
unsigned int CrashReporterClient::GetCrashDumpPercentageForWebView() {
return 100;
}
int CrashReporterClient::GetAndroidMinidumpDescriptor() { int CrashReporterClient::GetAndroidMinidumpDescriptor() {
return 0; return 0;
} }
......
...@@ -153,6 +153,11 @@ class CrashReporterClient { ...@@ -153,6 +153,11 @@ class CrashReporterClient {
virtual bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled); virtual bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled);
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Used by WebView to sample crashes without generating the unwanted dumps. If
// the returned value is less than 100, crash dumping will be sampled to that
// percentage.
virtual unsigned int GetCrashDumpPercentageForWebView();
// Returns the descriptor key of the android minidump global descriptor. // Returns the descriptor key of the android minidump global descriptor.
virtual int GetAndroidMinidumpDescriptor(); virtual int GetAndroidMinidumpDescriptor();
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/posix/global_descriptors.h" #include "base/posix/global_descriptors.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/crash/content/app/crash_reporter_client.h" #include "components/crash/content/app/crash_reporter_client.h"
...@@ -86,7 +87,9 @@ class SandboxedHandler { ...@@ -86,7 +87,9 @@ class SandboxedHandler {
return instance; return instance;
} }
bool Initialize() { bool Initialize(bool dump_at_crash) {
request_dump_ = dump_at_crash ? 1 : 0;
SetSanitizationInfo(crash_reporter::GetCrashReporterClient(), SetSanitizationInfo(crash_reporter::GetCrashReporterClient(),
&sanitization_); &sanitization_);
server_fd_ = base::GlobalDescriptors::GetInstance()->Get( server_fd_ = base::GlobalDescriptors::GetInstance()->Get(
...@@ -113,15 +116,17 @@ class SandboxedHandler { ...@@ -113,15 +116,17 @@ class SandboxedHandler {
socklen_t optlen = sizeof(optval); socklen_t optlen = sizeof(optval);
setsockopt(handlers_socket.get(), SOL_SOCKET, SO_PASSCRED, &optval, optlen); setsockopt(handlers_socket.get(), SOL_SOCKET, SO_PASSCRED, &optval, optlen);
iovec iov; iovec iov[2];
iov.iov_base = &signo; iov[0].iov_base = &signo;
iov.iov_len = sizeof(signo); iov[0].iov_len = sizeof(signo);
iov[1].iov_base = &request_dump_;
iov[1].iov_len = sizeof(request_dump_);
msghdr msg; msghdr msg;
msg.msg_name = nullptr; msg.msg_name = nullptr;
msg.msg_namelen = 0; msg.msg_namelen = 0;
msg.msg_iov = &iov; msg.msg_iov = iov;
msg.msg_iovlen = 1; msg.msg_iovlen = base::size(iov);
char cmsg_buf[CMSG_SPACE(sizeof(int))]; char cmsg_buf[CMSG_SPACE(sizeof(int))];
msg.msg_control = cmsg_buf; msg.msg_control = cmsg_buf;
...@@ -164,6 +169,7 @@ class SandboxedHandler { ...@@ -164,6 +169,7 @@ class SandboxedHandler {
SanitizationInformation sanitization_; SanitizationInformation sanitization_;
int server_fd_; int server_fd_;
unsigned char request_dump_;
DISALLOW_COPY_AND_ASSIGN(SandboxedHandler); DISALLOW_COPY_AND_ASSIGN(SandboxedHandler);
}; };
...@@ -365,7 +371,7 @@ class HandlerStarter { ...@@ -365,7 +371,7 @@ class HandlerStarter {
return instance; return instance;
} }
base::FilePath Initialize() { base::FilePath Initialize(bool dump_at_crash) {
base::FilePath database_path; base::FilePath database_path;
base::FilePath metrics_path; base::FilePath metrics_path;
std::string url; std::string url;
...@@ -389,6 +395,13 @@ class HandlerStarter { ...@@ -389,6 +395,13 @@ class HandlerStarter {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
if (!base::PathExists(handler_path)) { if (!base::PathExists(handler_path)) {
use_java_handler_ = true; use_java_handler_ = true;
}
if (!dump_at_crash) {
return database_path;
}
if (use_java_handler_) {
std::vector<std::string> env; std::vector<std::string> env;
if (!BuildEnvironmentWithApk(&env)) { if (!BuildEnvironmentWithApk(&env)) {
return database_path; return database_path;
...@@ -531,17 +544,24 @@ base::FilePath PlatformCrashpadInitialization( ...@@ -531,17 +544,24 @@ base::FilePath PlatformCrashpadInitialization(
DCHECK(!embedded_handler); DCHECK(!embedded_handler);
DCHECK(exe_path.empty()); DCHECK(exe_path.empty());
bool dump_at_crash = true;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
base::android::SetJavaExceptionCallback(SetJavaExceptionInfo); base::android::SetJavaExceptionCallback(SetJavaExceptionInfo);
unsigned int dump_percentage =
GetCrashReporterClient()->GetCrashDumpPercentageForWebView();
if (dump_percentage < 100 && rand() % 100 >= dump_percentage) {
dump_at_crash = false;
}
#endif // OS_ANDROID #endif // OS_ANDROID
if (browser_process) { if (browser_process) {
HandlerStarter* starter = HandlerStarter::Get(); HandlerStarter* starter = HandlerStarter::Get();
return starter->Initialize(); return starter->Initialize(dump_at_crash);
} }
crashpad::SandboxedHandler* handler = crashpad::SandboxedHandler::Get(); crashpad::SandboxedHandler* handler = crashpad::SandboxedHandler::Get();
bool result = handler->Initialize(); bool result = handler->Initialize(dump_at_crash);
DCHECK(result); DCHECK(result);
return base::FilePath(); return base::FilePath();
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -569,15 +570,18 @@ void CrashHandlerHost::Init() { ...@@ -569,15 +570,18 @@ void CrashHandlerHost::Init() {
bool CrashHandlerHost::ReceiveClientMessage(int client_fd, bool CrashHandlerHost::ReceiveClientMessage(int client_fd,
base::ScopedFD* handler_fd) { base::ScopedFD* handler_fd) {
int signo; int signo;
iovec iov; unsigned char request_dump;
iov.iov_base = &signo; iovec iov[2];
iov.iov_len = sizeof(signo); iov[0].iov_base = &signo;
iov[0].iov_len = sizeof(signo);
iov[1].iov_base = &request_dump;
iov[1].iov_len = sizeof(request_dump);
msghdr msg; msghdr msg;
msg.msg_name = nullptr; msg.msg_name = nullptr;
msg.msg_namelen = 0; msg.msg_namelen = 0;
msg.msg_iov = &iov; msg.msg_iov = iov;
msg.msg_iovlen = 1; msg.msg_iovlen = base::size(iov);
char cmsg_buf[CMSG_SPACE(sizeof(int)) + CMSG_SPACE(sizeof(ucred))]; char cmsg_buf[CMSG_SPACE(sizeof(int)) + CMSG_SPACE(sizeof(ucred))];
msg.msg_control = cmsg_buf; msg.msg_control = cmsg_buf;
...@@ -617,6 +621,14 @@ bool CrashHandlerHost::ReceiveClientMessage(int client_fd, ...@@ -617,6 +621,14 @@ bool CrashHandlerHost::ReceiveClientMessage(int client_fd,
NotifyCrashSignalObservers(child_pid, signo); NotifyCrashSignalObservers(child_pid, signo);
#if defined(OS_ANDROID)
if (!request_dump) {
return false;
}
#else
DCHECK(request_dump);
#endif
handler_fd->reset(child_fd.release()); handler_fd->reset(child_fd.release());
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment