Skip to content

Commit

Permalink
Refactor Android to use chrome_crashpad_handler
Browse files Browse the repository at this point in the history
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/+/1708838
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Reviewed-by: Michael Spang <spang@chromium.org>
Commit-Queue: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682364}
  • Loading branch information
vlad902 authored and Commit Bot committed Jul 30, 2019
1 parent 2c4bcb6 commit 0656f2c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 35 deletions.
4 changes: 2 additions & 2 deletions chrome/android/chrome_public_apk_tmpl.gni
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ template("chrome_public_common_apk_or_module_tmpl") {
if (!_is_monochrome && !_is_trichrome) {
deps += [
"//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",
]
if (!defined(loadable_modules)) {
loadable_modules = []
}
loadable_modules += [ "$root_out_dir/libcrashpad_handler.so" ]
loadable_modules += [ "$root_out_dir/libchrome_crashpad_handler.so" ]
}

if (_enable_multidex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def BuildFileMatchRegex(*file_matchers):
r'lib/.*/libchrome\.\d{4}\.\d{2,3}\.so', # libchrome placeholders
r'lib/.*/libchromium_android_linker\.so',
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\.align',
r'lib/.*/gdbserver',
Expand Down
4 changes: 2 additions & 2 deletions chromecast/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,10 @@ if (is_android) {
"//base:base_java",
"//chromecast/android:libcast_shell_android",
"//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"
enable_multidex = true
Expand Down
32 changes: 24 additions & 8 deletions components/crash/content/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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
# define custom UserStreamDataSources.
executable("chrome_crashpad_handler") {
Expand All @@ -222,15 +222,11 @@ if (is_mac) {
]

deps = [
"//components/gwp_asan/buildflags",
"//third_party/crashpad/crashpad/handler:handler",
":crashpad_handler_main",
"//third_party/crashpad/crashpad/handler",
]

if (enable_gwp_asan) {
deps += [ "//components/gwp_asan/crash_handler" ]
}

if (is_component_build) {
if (is_mac && is_component_build) {
ldflags = [
# The handler is in
# Chromium.app/Contents/Versions/X/Chromium Framework.framework/Versions/A/Helpers/
Expand All @@ -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
# link the export thunks directly into the test binary.
source_set("test_support") {
Expand Down
19 changes: 3 additions & 16 deletions components/crash/content/app/chrome_crashpad_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>

#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
// Forward declare this for macOS (it's only defined by crashpad on Android.)
extern "C" int CrashpadHandlerMain(int argc, char* argv[]);

int main(int argc, char* argv[]) {
crashpad::UserStreamDataSources user_stream_data_sources;
#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);
return CrashpadHandlerMain(argc, argv);
}
2 changes: 1 addition & 1 deletion components/crash/content/app/crashpad_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ bool GetHandlerPath(base::FilePath* exe_dir, base::FilePath* handler_path) {
if (!base::PathService::Get(base::DIR_MODULE, exe_dir)) {
return false;
}
*handler_path = exe_dir->Append("libcrashpad_handler.so");
*handler_path = exe_dir->Append("libchrome_crashpad_handler.so");
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions content/shell/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,20 @@ android_apk("content_shell_apk") {
"//base:base_java",
"//base:base_java_test_support",
"//components/crash/android:java",
"//components/crash/content/app:chrome_crashpad_handler_named_as_so",
"//content/public/android:content_java",
"//content/public/test/android:android_test_message_pump_support_java",
"//media/capture/video/android:capture_java",
"//net/android:net_java",
"//services/shape_detection:shape_detection_java",
"//third_party/crashpad/crashpad/handler:crashpad_handler_named_as_so",
"//third_party/mesa_headers",
"//ui/android:ui_java",
]
apk_name = "ContentShell"
android_manifest = content_shell_manifest
android_manifest_dep = ":content_shell_manifest"
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"
}

Expand Down
6 changes: 3 additions & 3 deletions docs/android_native_libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
to produce a dump.
* Chrome and ChromeModern (Android J through M):
* libcrashpad_handler.so is a standalone executable containing all of the
crash dumping code. It is stored compressed and extracted automatically by
the system, allowing it to be directly executed to produce a crash dump.
* libchrome_crashpad_handler.so is a standalone executable containing all of
the crash dumping code. It is stored compressed and extracted automatically
by the system, allowing it to be directly executed to produce a crash dump.
* Monochrome (N through P) and SystemWebView (L through P):
* 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
Expand Down

0 comments on commit 0656f2c

Please sign in to comment.