gpt4 book ai didi

android - 如何解决Android Arm64-v8内存操作(memcpy, GetByteArrayRegion, SetByteArrayRegion)崩溃

转载 作者:行者123 更新时间:2023-11-29 16:56:32 25 4
gpt4 key购买 nike

我有一个 Android 项目,有两个 JNI 函数来操作内存。(Github: android_memcpy_test )

否则,将编写一个 UnintTest(名为 ByteUtilTest)来验证这两个 JNI 函数。

当我在 ARM32-v7 下运行 UnintTest 时它成功了,但它在 ARM64-v8 下不起作用。

我已经花了 2 天时间解决这个问题但没有成功,任何帮助将不胜感激!


JNI 函数

JNI functions

单元测试

Unit Test

ARM64-v8下的错误日志

07-01 17:00:14.160 360-360/? I/DEBUG: pid: 2929, tid: 2952, name: roidJUnitRunner  >>> com.example.sanqian.android_memcpy_test <<<
07-01 17:00:14.160 360-360/? I/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xffffff918160c0
07-01 17:00:14.169 360-360/? I/DEBUG: x0 0000000012d701ec x1 ffffffff918160c0 x2 0000000000000008 x3 0000007f987fb000
07-01 17:00:14.169 360-360/? I/DEBUG: x4 0000007f987fed48 x5 0000007f9717d000 x6 0000000012d701ec x7 ffffffff918160c0
07-01 17:00:14.169 360-360/? I/DEBUG: x8 0000000000000001 x9 0000000012d701ec x10 59e6183118387b72 x11 0000000000000001
07-01 17:00:14.169 360-360/? I/DEBUG: x12 000000007020f958 x13 00000000fffffff8 x14 0000007f91791ac0 x15 0000000000000000
07-01 17:00:14.170 360-360/? I/DEBUG: x16 0000007f987fb0d8 x17 0000007f9bfbf888 x18 0000007f91791ac0 x19 0000000012d701e0
07-01 17:00:14.170 360-360/? I/DEBUG: x20 0000007f918135c0 x21 0000007f988a7000 x22 0000007f987fb000 x23 0000000000000000
07-01 17:00:14.170 360-360/? I/DEBUG: x24 0000000000000008 x25 0000000000000000 x26 0000007f91791e00 x27 0000000000000008
07-01 17:00:14.170 360-360/? I/DEBUG: x28 0000007f91791a58 x29 0000007f91791960 x30 0000007f985ebddc
07-01 17:00:14.170 360-360/? I/DEBUG: sp 0000007f91791960 pc 0000007f9bfbf8f0 pstate 0000000080000000
07-01 17:00:14.170 360-360/? I/DEBUG: backtrace:
07-01 17:00:14.170 360-360/? I/DEBUG: #00 pc 00000000000158f0 /system/lib64/libc.so (memcpy+104)
07-01 17:00:14.170 360-360/? I/DEBUG: #01 pc 000000000027cdd8 /system/lib64/libart.so (_ZN3art3JNI23SetPrimitiveArrayRegionIP11_jbyteArrayaNS_6mirror14PrimitiveArrayIaEEEEvP7_JNIEnvT_iiPKT0_+1016)
07-01 17:00:14.170 360-360/? I/DEBUG: #02 pc 00000000000eed68 /system/lib64/libart.so (_ZN3art8CheckJNI18SetByteArrayRegionEP7_JNIEnvP11_jbyteArrayiiPKa+136)
07-01 17:00:14.170 360-360/? I/DEBUG: #03 pc 000000000000076c /data/app/com.example.sanqian.android_memcpy_test.test-2/lib/arm64/libandroid_memcpy_test.so (Java_com_example_sanqian_android_1memcpy_1test_ByteUtil_copyByteArray+88)
07-01 17:00:14.170 360-360/? I/DEBUG: #04 pc 0000000000199a34 /data/dalvik-cache/arm64/data@app@com.example.sanqian.android_memcpy_test-2@base.apk@classes.dex

最佳答案

When I run UnintTest under ARM32-v7 it's success, but it doesn't work under ARM64-v8.

解决这个问题:

void *handle;
.
.
.
return (jint) handle;

指针可能适合 32 位内存模型中的 32 位整数。指针不要适合 64 位内存模型中的 32 位整数。

如果sizeof( jlong​​ ) >= sizeof( void * ),你可以返回一个jlong​​:

void *handle;
.
.
.
return (jlong) handle;

关于android - 如何解决Android Arm64-v8内存操作(memcpy, GetByteArrayRegion, SetByteArrayRegion)崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44859317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com