From 278d03a42c13439046285350a7bed3e536bdc612 Mon Sep 17 00:00:00 2001 From: Yura Yaroshevich Date: Fri, 23 Mar 2018 11:47:19 +0300 Subject: [PATCH] Force alignment of JVM called functions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:9050 Change-Id: I5a064769dac857d2a6afb5f28c556bbcca21f8c6 Reviewed-on: https://webrtc-review.googlesource.com/64160 Reviewed-by: Henrik Andreassson Reviewed-by: Sami Kalliomäki Commit-Queue: Sami Kalliomäki Cr-Commit-Position: refs/heads/master@{#22578} --- modules/audio_device/android/audio_manager.cc | 1 + modules/audio_device/android/audio_record_jni.cc | 2 ++ modules/audio_device/android/audio_track_jni.cc | 2 ++ modules/utility/include/helpers_android.h | 9 +++++++++ 4 files changed, 14 insertions(+) diff --git a/modules/audio_device/android/audio_manager.cc b/modules/audio_device/android/audio_manager.cc index 63020bb7ec..98a2afd20c 100644 --- a/modules/audio_device/android/audio_manager.cc +++ b/modules/audio_device/android/audio_manager.cc @@ -236,6 +236,7 @@ int AudioManager::GetDelayEstimateInMilliseconds() const { return delay_estimate_in_milliseconds_; } +JNI_FUNCTION_ALIGN void JNICALL AudioManager::CacheAudioParameters(JNIEnv* env, jobject obj, jint sample_rate, diff --git a/modules/audio_device/android/audio_record_jni.cc b/modules/audio_device/android/audio_record_jni.cc index 7e4654ecdd..02d74486e0 100644 --- a/modules/audio_device/android/audio_record_jni.cc +++ b/modules/audio_device/android/audio_record_jni.cc @@ -229,6 +229,7 @@ int32_t AudioRecordJni::EnableBuiltInNS(bool enable) { return j_audio_record_->EnableBuiltInNS(enable) ? 0 : -1; } +JNI_FUNCTION_ALIGN void JNICALL AudioRecordJni::CacheDirectBufferAddress(JNIEnv* env, jobject obj, jobject byte_buffer, @@ -249,6 +250,7 @@ void AudioRecordJni::OnCacheDirectBufferAddress(JNIEnv* env, direct_buffer_capacity_in_bytes_ = static_cast(capacity); } +JNI_FUNCTION_ALIGN void JNICALL AudioRecordJni::DataIsRecorded(JNIEnv* env, jobject obj, jint length, diff --git a/modules/audio_device/android/audio_track_jni.cc b/modules/audio_device/android/audio_track_jni.cc index 4469450a9a..f8f254a883 100644 --- a/modules/audio_device/android/audio_track_jni.cc +++ b/modules/audio_device/android/audio_track_jni.cc @@ -204,6 +204,7 @@ void AudioTrackJni::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) { audio_device_buffer_->SetPlayoutChannels(channels); } +JNI_FUNCTION_ALIGN void JNICALL AudioTrackJni::CacheDirectBufferAddress(JNIEnv* env, jobject obj, jobject byte_buffer, @@ -227,6 +228,7 @@ void AudioTrackJni::OnCacheDirectBufferAddress(JNIEnv* env, RTC_LOG(INFO) << "frames_per_buffer: " << frames_per_buffer_; } +JNI_FUNCTION_ALIGN void JNICALL AudioTrackJni::GetPlayoutData(JNIEnv* env, jobject obj, jint length, diff --git a/modules/utility/include/helpers_android.h b/modules/utility/include/helpers_android.h index 2ee577ceea..808b347ee7 100644 --- a/modules/utility/include/helpers_android.h +++ b/modules/utility/include/helpers_android.h @@ -20,6 +20,15 @@ RTC_CHECK(!jni->ExceptionCheck()) \ << (jni->ExceptionDescribe(), jni->ExceptionClear(), "") +#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. bugs.webrtc.org/9050 +#define JNI_FUNCTION_ALIGN __attribute__((force_align_arg_pointer)) +#else +#define JNI_FUNCTION_ALIGN +#endif + namespace webrtc { // Return a |JNIEnv*| usable on this thread or NULL if this thread is detached.