From ac7fd8737515818d8f089c4b8bc4f41126afae31 Mon Sep 17 00:00:00 2001 From: Raman Budny Date: Wed, 20 Nov 2019 17:08:12 +0300 Subject: [PATCH] Force alignment of generated JVM called functions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL effectively expands the zone of influence of https://webrtc-review.googlesource.com/64160, forcing 16-byte stack alignment of generated JNI methods for the Android x86 platform. Bug: webrtc:9085 Change-Id: Idc40c00ea3fb52dbbbeac7b58ceda2a9a44733d8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/159928 Commit-Queue: Sami Kalliomäki Reviewed-by: Sami Kalliomäki Cr-Commit-Position: refs/heads/master@{#29858} --- AUTHORS | 3 ++- sdk/android/src/jni/jni_generator_helper.h | 9 +++++++++ sdk/android/src/jni/jni_helpers.h | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index d76148e8d2..df32313b3d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -82,6 +82,8 @@ Michel Promonet Min Wang Ramprakash Jelari CZ Theng +Miguel Paris +Raman Budny &yet LLC <*@andyet.com> Agora IO <*@agora.io> @@ -109,7 +111,6 @@ Videxio AS <*@videxio.com> Vidyo, Inc. <*@vidyo.com> Vonage Holdings Corp. <*@vonage.com> Wire Swiss GmbH <*@wire.com> -Miguel Paris Vewd Software AS <*@vewd.com> Highfive, Inc. <*@highfive.com> CoSMo Software Consulting, Pte Ltd <*@cosmosoftware.io> diff --git a/sdk/android/src/jni/jni_generator_helper.h b/sdk/android/src/jni/jni_generator_helper.h index e6d6f7ef15..a5497e1635 100644 --- a/sdk/android/src/jni/jni_generator_helper.h +++ b/sdk/android/src/jni/jni_generator_helper.h @@ -27,7 +27,16 @@ #define BASE_EXPORT #define JNI_REGISTRATION_EXPORT __attribute__((visibility("default"))) + +#if defined(WEBRTC_ARCH_X86) +// Dalvik JIT generated code doesn't guarantee 16-byte stack alignment on +// x86 - use force_align_arg_pointer to realign the stack at the JNI +// boundary. crbug.com/655248 +#define JNI_GENERATOR_EXPORT \ + __attribute__((force_align_arg_pointer)) extern "C" JNIEXPORT JNICALL +#else #define JNI_GENERATOR_EXPORT extern "C" JNIEXPORT JNICALL +#endif #define CHECK_EXCEPTION(jni) \ RTC_CHECK(!jni->ExceptionCheck()) \ diff --git a/sdk/android/src/jni/jni_helpers.h b/sdk/android/src/jni/jni_helpers.h index 38b0d7edf4..7a2f27b99d 100644 --- a/sdk/android/src/jni/jni_helpers.h +++ b/sdk/android/src/jni/jni_helpers.h @@ -23,8 +23,17 @@ // Convenience macro defining JNI-accessible methods in the org.webrtc package. // Eliminates unnecessary boilerplate and line-wraps, reducing visual clutter. +#if defined(WEBRTC_ARCH_X86) +// Dalvik JIT generated code doesn't guarantee 16-byte stack alignment on +// x86 - use force_align_arg_pointer to realign the stack at the JNI +// boundary. crbug.com/655248 +#define JNI_FUNCTION_DECLARATION(rettype, name, ...) \ + __attribute__((force_align_arg_pointer)) extern "C" JNIEXPORT rettype \ + JNICALL Java_org_webrtc_##name(__VA_ARGS__) +#else #define JNI_FUNCTION_DECLARATION(rettype, name, ...) \ extern "C" JNIEXPORT rettype JNICALL Java_org_webrtc_##name(__VA_ARGS__) +#endif namespace webrtc { namespace jni {