Commit 0656f2cb authored by Vlad Tsyrklevich's avatar Vlad Tsyrklevich Committed by Commit Bot

Refactor Android to use chrome_crashpad_handler

Instead of using crashpad's crashpad_handler, refactor Android to use
our own custom chrome_crashpad_handler (also used by macOS) and have it
also pass through the CrashpadHandlerMain entry point so that it picks
up any custom crashpad hooks we want to install.

CQ-DEPEND=CL:1707405

Bug: 973167
Change-Id: Id6d91a35ce12e547b4a7c92d07f869c96afae797
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1708838Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Commit-Queue: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682364}
parent 2c4bcb68
...@@ -199,13 +199,13 @@ template("chrome_public_common_apk_or_module_tmpl") { ...@@ -199,13 +199,13 @@ template("chrome_public_common_apk_or_module_tmpl") {
if (!_is_monochrome && !_is_trichrome) { if (!_is_monochrome && !_is_trichrome) {
deps += [ deps += [
"//chrome/android:chrome_public_v8_assets", "//chrome/android:chrome_public_v8_assets",
"//third_party/crashpad/crashpad/handler:crashpad_handler_named_as_so", "//components/crash/content/app:chrome_crashpad_handler_named_as_so",
"//third_party/icu:icu_assets", "//third_party/icu:icu_assets",
] ]
if (!defined(loadable_modules)) { if (!defined(loadable_modules)) {
loadable_modules = [] loadable_modules = []
} }
loadable_modules += [ "$root_out_dir/libcrashpad_handler.so" ] loadable_modules += [ "$root_out_dir/libchrome_crashpad_handler.so" ]
} }
if (_enable_multidex) { if (_enable_multidex) {
......
...@@ -25,7 +25,7 @@ CHROME_SPECIFIC = BuildFileMatchRegex( ...@@ -25,7 +25,7 @@ CHROME_SPECIFIC = BuildFileMatchRegex(
r'lib/.*/libchrome\.\d{4}\.\d{2,3}\.so', # libchrome placeholders r'lib/.*/libchrome\.\d{4}\.\d{2,3}\.so', # libchrome placeholders
r'lib/.*/libchromium_android_linker\.so', r'lib/.*/libchromium_android_linker\.so',
r'lib/.*/libchromeview\.so', # placeholder library r'lib/.*/libchromeview\.so', # placeholder library
r'lib/.*/libcrashpad_handler\.so', r'lib/.*/libchrome_crashpad_handler\.so',
r'lib/.*/crazy\.libchrome\.so', r'lib/.*/crazy\.libchrome\.so',
r'lib/.*/crazy\.libchrome\.align', r'lib/.*/crazy\.libchrome\.align',
r'lib/.*/gdbserver', r'lib/.*/gdbserver',
......
...@@ -663,10 +663,10 @@ if (is_android) { ...@@ -663,10 +663,10 @@ if (is_android) {
"//base:base_java", "//base:base_java",
"//chromecast/android:libcast_shell_android", "//chromecast/android:libcast_shell_android",
"//chromecast/browser/android:cast_shell_java", "//chromecast/browser/android:cast_shell_java",
"//third_party/crashpad/crashpad/handler:crashpad_handler_named_as_so", "//components/crash/content/app:chrome_crashpad_handler_named_as_so",
] ]
loadable_modules = [ "$root_out_dir/libcrashpad_handler.so" ] loadable_modules = [ "$root_out_dir/libchrome_crashpad_handler.so" ]
command_line_flags_file = "castshell-command-line" command_line_flags_file = "castshell-command-line"
enable_multidex = true enable_multidex = true
......
...@@ -213,7 +213,7 @@ if (is_win) { ...@@ -213,7 +213,7 @@ if (is_win) {
} }
} }
if (is_mac) { if (is_mac || is_android) {
# We build a chromium-specific crashpad_handler executable so that we can # We build a chromium-specific crashpad_handler executable so that we can
# define custom UserStreamDataSources. # define custom UserStreamDataSources.
executable("chrome_crashpad_handler") { executable("chrome_crashpad_handler") {
...@@ -222,15 +222,11 @@ if (is_mac) { ...@@ -222,15 +222,11 @@ if (is_mac) {
] ]
deps = [ deps = [
"//components/gwp_asan/buildflags", ":crashpad_handler_main",
"//third_party/crashpad/crashpad/handler:handler", "//third_party/crashpad/crashpad/handler",
] ]
if (enable_gwp_asan) { if (is_mac && is_component_build) {
deps += [ "//components/gwp_asan/crash_handler" ]
}
if (is_component_build) {
ldflags = [ ldflags = [
# The handler is in # The handler is in
# Chromium.app/Contents/Versions/X/Chromium Framework.framework/Versions/A/Helpers/ # Chromium.app/Contents/Versions/X/Chromium Framework.framework/Versions/A/Helpers/
...@@ -257,6 +253,26 @@ if (is_mac) { ...@@ -257,6 +253,26 @@ if (is_mac) {
} }
} }
if (is_android) {
# There is not any normal way to package native executables in an Android APK.
# It is normal to package native code as a loadable module but Android's APK
# installer will ignore files not named like a shared object, so give the
# handler executable an acceptable name.
copy("chrome_crashpad_handler_named_as_so") {
deps = [
":chrome_crashpad_handler",
]
sources = [
"$root_out_dir/chrome_crashpad_handler",
]
outputs = [
"$root_out_dir/libchrome_crashpad_handler.so",
]
}
}
# This source set provides the functionality required for tests, which on Windows # This source set provides the functionality required for tests, which on Windows
# link the export thunks directly into the test binary. # link the export thunks directly into the test binary.
source_set("test_support") { source_set("test_support") {
......
...@@ -2,22 +2,9 @@ ...@@ -2,22 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <memory> // Forward declare this for macOS (it's only defined by crashpad on Android.)
extern "C" int CrashpadHandlerMain(int argc, char* argv[]);
#include "components/gwp_asan/buildflags/buildflags.h"
#include "third_party/crashpad/crashpad/handler/handler_main.h"
#include "third_party/crashpad/crashpad/handler/user_stream_data_source.h"
#if BUILDFLAG(ENABLE_GWP_ASAN)
#include "components/gwp_asan/crash_handler/crash_handler.h"
#endif
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
crashpad::UserStreamDataSources user_stream_data_sources; return CrashpadHandlerMain(argc, argv);
#if BUILDFLAG(ENABLE_GWP_ASAN)
user_stream_data_sources.push_back(
std::make_unique<gwp_asan::UserStreamDataSource>());
#endif
return crashpad::HandlerMain(argc, argv, &user_stream_data_sources);
} }
...@@ -397,7 +397,7 @@ bool GetHandlerPath(base::FilePath* exe_dir, base::FilePath* handler_path) { ...@@ -397,7 +397,7 @@ bool GetHandlerPath(base::FilePath* exe_dir, base::FilePath* handler_path) {
if (!base::PathService::Get(base::DIR_MODULE, exe_dir)) { if (!base::PathService::Get(base::DIR_MODULE, exe_dir)) {
return false; return false;
} }
*handler_path = exe_dir->Append("libcrashpad_handler.so"); *handler_path = exe_dir->Append("libchrome_crashpad_handler.so");
return true; return true;
} }
......
...@@ -170,12 +170,12 @@ android_apk("content_shell_apk") { ...@@ -170,12 +170,12 @@ android_apk("content_shell_apk") {
"//base:base_java", "//base:base_java",
"//base:base_java_test_support", "//base:base_java_test_support",
"//components/crash/android:java", "//components/crash/android:java",
"//components/crash/content/app:chrome_crashpad_handler_named_as_so",
"//content/public/android:content_java", "//content/public/android:content_java",
"//content/public/test/android:android_test_message_pump_support_java", "//content/public/test/android:android_test_message_pump_support_java",
"//media/capture/video/android:capture_java", "//media/capture/video/android:capture_java",
"//net/android:net_java", "//net/android:net_java",
"//services/shape_detection:shape_detection_java", "//services/shape_detection:shape_detection_java",
"//third_party/crashpad/crashpad/handler:crashpad_handler_named_as_so",
"//third_party/mesa_headers", "//third_party/mesa_headers",
"//ui/android:ui_java", "//ui/android:ui_java",
] ]
...@@ -183,7 +183,7 @@ android_apk("content_shell_apk") { ...@@ -183,7 +183,7 @@ android_apk("content_shell_apk") {
android_manifest = content_shell_manifest android_manifest = content_shell_manifest
android_manifest_dep = ":content_shell_manifest" android_manifest_dep = ":content_shell_manifest"
shared_libraries = [ ":libcontent_shell_content_view" ] shared_libraries = [ ":libcontent_shell_content_view" ]
loadable_modules = [ "$root_out_dir/libcrashpad_handler.so" ] loadable_modules = [ "$root_out_dir/libchrome_crashpad_handler.so" ]
command_line_flags_file = "content-shell-command-line" command_line_flags_file = "content-shell-command-line"
} }
......
...@@ -19,9 +19,9 @@ This doc outlines some tricks / gotchas / features of how we ship native code in ...@@ -19,9 +19,9 @@ This doc outlines some tricks / gotchas / features of how we ship native code in
dump is requested (e.g. after a crash), a Crashpad handler process is started dump is requested (e.g. after a crash), a Crashpad handler process is started
to produce a dump. to produce a dump.
* Chrome and ChromeModern (Android J through M): * Chrome and ChromeModern (Android J through M):
* libcrashpad_handler.so is a standalone executable containing all of the * libchrome_crashpad_handler.so is a standalone executable containing all of
crash dumping code. It is stored compressed and extracted automatically by the crash dumping code. It is stored compressed and extracted automatically
the system, allowing it to be directly executed to produce a crash dump. by the system, allowing it to be directly executed to produce a crash dump.
* Monochrome (N through P) and SystemWebView (L through P): * Monochrome (N through P) and SystemWebView (L through P):
* All of the Crashpad code is linked into the package's main native library * All of the Crashpad code is linked into the package's main native library
(e.g. libmonochrome.so). When a dump is requested, /system/bin/app_process (e.g. libmonochrome.so). When a dump is requested, /system/bin/app_process
......
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