From 293d2850714fdeb46806b9e7ab848c98864d03f5 Mon Sep 17 00:00:00 2001 From: Dmitry Yunitsky Date: Tue, 19 Jan 2016 16:04:11 +0300 Subject: [PATCH] [android] Crashfix for x86 native exceptions bug. --- android/build.gradle | 5 +++++ android/jni/Application.mk | 17 ++++++++++------- tools/android/cxxabi.cc_patch | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 tools/android/cxxabi.cc_patch diff --git a/android/build.gradle b/android/build.gradle index 4fa6134a5c..ddb5092d44 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -376,3 +376,8 @@ task obbPush(dependsOn: ['obbGenerate', 'obbPushMain', 'obbPushPatch']) { commandLine android.getAdbExe(), 'push', propObbFontsOutput, "${obbPath}worlds.obb" } } + +task patchNdkR10E(type: Exec, description: 'Patches NDK r10e for bug described here https://code.google.com/p/android/issues/detail?id=179410') { + def cxxabiPath = "${android.getNdkDirectory().getAbsolutePath()}/sources/cxx-stl/gabi++/src/cxxabi.cc" + commandLine 'bash', '-c', "patch -p1 ${cxxabiPath} < ../tools/android/cxxabi.cc_patch" +} diff --git a/android/jni/Application.mk b/android/jni/Application.mk index e7de93f3c8..3cfe2d9e97 100644 --- a/android/jni/Application.mk +++ b/android/jni/Application.mk @@ -26,11 +26,14 @@ ifeq ($(NDK_DEBUG),1) else APP_OPTIM := release APP_CFLAGS += -DRELEASE -D_RELEASE -ifeq ($(PRODUCTION),1) - APP_CFLAGS += -DOMIM_PRODUCTION - # Temporary workaround for crashes on x86 arch when throwing C++ exceptions. - # More details here: https://code.google.com/p/android/issues/detail?id=179410 - # TODO: Check if this workaround is needed in newer NDK versions (after current one r10e). - LIBCXX_FORCE_REBUILD := trueifeq ($(PRODUCTION),1) -endif + ifeq ($(PRODUCTION),1) + APP_CFLAGS += -DOMIM_PRODUCTION + # Temporary workaround for crashes on x86 arch when throwing C++ exceptions, built with NDK r10e version. + # Requires patched NDK file "android-ndk-r10e/sources/cxx-stl/gabi++/src/cxxabi.cc" file, + # Patch can be found at "../tools/android/cxxabi.cc_patch". + # Gradle task patchNdkR10E will patch it for you. + # More details here: https://code.google.com/p/android/issues/detail?id=179410. + # TODO: Check if this workaround is needed in newer NDK versions. + LIBCXX_FORCE_REBUILD := true + endif endif diff --git a/tools/android/cxxabi.cc_patch b/tools/android/cxxabi.cc_patch new file mode 100644 index 0000000000..79412c529e --- /dev/null +++ b/tools/android/cxxabi.cc_patch @@ -0,0 +1,15 @@ +diff --git a/Users/yunik/devtools/android-sdk/ndk-bundle/sources/cxx-stl/gabi++/src/cxxabi.cc b/android/../tools/android/cxxabi.cc +index 3f428d9..9c0e8bc 100644 +--- a/Users/yunik/devtools/android-sdk/ndk-bundle/sources/cxx-stl/gabi++/src/cxxabi.cc ++++ b/android/../tools/android/cxxabi.cc +@@ -296,7 +296,9 @@ namespace __cxxabiv1 { + + extern "C" void *__cxa_allocate_exception(size_t thrown_size) _GABIXX_NOEXCEPT { + size_t size = thrown_size + sizeof(__cxa_exception); +- __cxa_exception *buffer = static_cast<__cxa_exception*>(malloc(size)); ++ // Bugfix for crashes appearing on stack unwinding, taken from https://android-review.googlesource.com/#/c/182443/ ++ //__cxa_exception *buffer = static_cast<__cxa_exception*>(malloc(size)); ++ __cxa_exception *buffer = static_cast<__cxa_exception*>(memalign(__alignof__(__cxa_exception), size)); + if (!buffer) { + // Since Android uses memory-overcommit, we enter here only when + // the exception object is VERY large. This will propably never happen.