From 83a24af5459696c3905fe476ca86c7b34e75650f Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Wed, 12 Apr 2017 11:50:10 +0100 Subject: [PATCH 1/2] Binder: Be forceful about a forceful exit. We were previously using exit(1) when code servicing an IPC threw any subclass of Error. That made it much harder to diagnose cases where that happened because : - exit runs global destructors, which might prove problematic (see linked bug). - such exits are often due to bugs in application code (things like AssertionErrors being thrown) but aren't flagged as such by our infrastructure, or by humans for that matter. To address both issues, use FatalError() so that the runtime can dump more useful information to the logs before it aborts. Test: manual Bug: 36813403 Change-Id: I5826090229109dc7cb19f0c3571c609f990cd36a (cherry picked from commit d64abfcf93b59500a0dba1626e73861848eb4407) --- core/jni/android_util_Binder.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp index abcd1e7049efb..1aed501335c41 100644 --- a/core/jni/android_util_Binder.cpp +++ b/core/jni/android_util_Binder.cpp @@ -192,18 +192,12 @@ static void report_exception(JNIEnv* env, jthrowable excep, const char* msg) if (env->IsInstanceOf(excep, gErrorOffsets.mClass)) { /* - * It's an Error: Reraise the exception, detach this thread, and - * wait for the fireworks. Die even more blatantly after a minute - * if the gentler attempt doesn't do the trick. - * - * The GetJavaVM function isn't on the "approved" list of JNI calls - * that can be made while an exception is pending, so we want to - * get the VM ptr, throw the exception, and then detach the thread. + * It's an Error: Reraise the exception and ask the runtime to abort. + * This will dump the pending exception as well as all thread traces + * to the log. */ env->Throw(excep); - env->ExceptionDescribe(); - ALOGE("Forcefully exiting"); - exit(1); + env->FatalError("java.lang.Error thrown during binder transaction."); } bail: From cfd0f9beeed9c1934b47a2914533cdd06c9f79e3 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Tue, 18 Apr 2017 17:48:39 +0100 Subject: [PATCH 2/2] Binder: Log details of pending exception. This was accidentally removed by change d64abfcf93b59500a0d. Test: manual; verify exception trace is printed in logs. Bug: 36813403 Bug: 37435516 Change-Id: I73ae8de167c457d56fddb85943a8f08f8913f0f7 (cherry picked from commit ccc9fad9e6abfa3cf082567669cc5d03ec7a3086) --- core/jni/android_util_Binder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp index 1aed501335c41..de67c50e71959 100644 --- a/core/jni/android_util_Binder.cpp +++ b/core/jni/android_util_Binder.cpp @@ -193,10 +193,10 @@ static void report_exception(JNIEnv* env, jthrowable excep, const char* msg) if (env->IsInstanceOf(excep, gErrorOffsets.mClass)) { /* * It's an Error: Reraise the exception and ask the runtime to abort. - * This will dump the pending exception as well as all thread traces - * to the log. */ env->Throw(excep); + ALOGE("java.lang.Error thrown during binder transaction (stack trace follows) : "); + env->ExceptionDescribe(); env->FatalError("java.lang.Error thrown during binder transaction."); }