Android应用集成HWAddress Sanitizer后启动失败,wrap.sh遭信号11终止
HWASAN集成后wrap.sh因信号11反复终止问题
我按照Android官方文档集成HWAddress Sanitizer,运行应用时出现wrap.sh执行失败的情况,进程多次被信号11终止并重复启动。
当前wrap.sh代码
#!/system/bin/sh echo "wrap Running with HWASAN $@" LD_HWASAN=1 exec "$@"
错误日志输出
11-14 18:17:25.908 22617 22617 I wrap.sh : wrap.sh terminated by signal 11 11-14 18:17:26.023 22769 22769 I wrap.sh : wrap Running with HWASAN /system/bin/app_process64 -Xcompiler-option --generate-mini-debug-info /system/bin --application --nice-name=com.xhey.xcamera com.android.internal.os.WrapperInit 81 33 android.app.ActivityThread seq=3055 11-14 18:17:29.401 2716 2840 D ViewRootImplExtImpl: wrapConfigInfoIntoFlags rotation=0, smallestScreenWidthDp=360, relayoutAsync=false, newFlags=23592960, title=Splash Screen com.xhey.xcamera 11-14 18:17:31.475 22769 22769 I wrap.sh : wrap.sh terminated by signal 11 11-14 18:17:31.582 22981 22981 I wrap.sh : wrap Running with HWASAN /system/bin/app_process64 -Xcompiler-option --generate-mini-debug-info /system/bin --application --nice-name=com.xhey.xcamera com.android.internal.os.WrapperInit 81 33 android.app.ActivityThread seq=3056 11-14 18:17:34.909 2716 2840 D ViewRootImplExtImpl: wrapConfigInfoIntoFlags rotation=0, smallestScreenWidthDp=360, relayoutAsync=false, newFlags=23592960, title=Splash Screen com.xhey.xcamera 11-14 18:17:36.908 22981 22981 I wrap.sh : wrap.sh terminated by signal 11 11-14 18:17:37.020 23128 23128 I wrap.sh : wrap Running with HWASAN /system/bin/app_process64 -Xcompiler-option --generate-mini-debug-info /system/bin --application --nice-name=com.xhey.xcamera com.android.internal.os.WrapperInit 81 33 android.app.ActivityThread seq=3057 11-14 18:17:40.367 2716 2840 D ViewRootImplExtImpl: wrapConfigInfoIntoFlags rotation=0, smallestScreenWidthDp=360, relayoutAsync=false, newFlags=23592960, title=Splash Screen com.xhey.xcamera 11-14 18:17:42.461 23128 23128 I wrap.sh : wrap.sh terminated by signal 11 11-14 18:17:42.564 23298 23298 I wrap.sh : wrap Running with HWASAN /system/bin/app_process64 -Xcompiler-option --generate-mini-debug-info /system/bin --application --nice-name=com.xhey.xcamera com.android.internal.os.WrapperInit 81 33 android.app.ActivityThread seq=3058 11-14 18:17:45.858 2716 2840 D ViewRootImplExtImpl: wrapConfigInfoIntoFlags rotation=0, smallestScreenWidthDp=360, relayoutAsync=false, newFlags=23592960, title=Splash Screen com.xhey.xcamera 11-14 18:17:47.890 23298 23298 I wrap.sh : wrap.sh terminated by signal 11 11-14 18:17:48.004 23467 23467 I wrap.sh : wrap Running with HWASAN /system/bin/app_process64 -Xcompiler-option --generate-mini-debug-info /system/bin --application --nice-name=com.xhey.xcamera com.android.internal.os.WrapperInit 81 33 android.app.ActivityThread seq=3059 11-14 18:17:51.348 2716 2840 D ViewRootImplExtImpl: wrapConfigInfoIntoFlags rotation=0, smallestScreenWidthDp=360, relayoutAsync=false, newFlags=23592960, title=Splash Screen com.xhey.xcamera 11-14 18:17:53.442 23467 23467 I wrap.sh : wrap.sh terminated by signal 11 11-14 18:17:53.556 23648 23648 I wrap.sh : wrap Running with HWASAN /system/bin/app_process64 -Xcompiler-option --generate-mini-debug-info /system/bin --application --nice-name=com.xhey.xcamera com.android.internal.os.WrapperInit 81 33 android.app.ActivityThread seq=3060
排查与解决思路
信号11是段错误(SIGSEGV),说明进程访问了非法内存地址,针对HWASAN集成场景,可按以下步骤排查:
- 检查设备兼容性:HWASAN要求Android 10(API 29)及以上版本,且设备CPU需支持ARMv8.1-Memory Tagging Extension(MTE)。可通过
adb shell getprop ro.product.cpu.abilist64查看CPU架构,确认是否支持MTE。 - 验证NDK版本:确保使用r21及以上版本的NDK,建议用最新稳定版,低版本NDK对HWASAN的支持存在缺陷。
- 调整wrap.sh脚本:部分场景下直接设置
LD_HWASAN=1会导致系统进程加载异常,可尝试修改脚本为:#!/system/bin/sh exec /system/bin/sh -c 'LD_HWASAN=1 exec "$@"' -- "$@" - 确认编译配置:确保所有Native库都用HWASAN编译,混合普通编译与HWASAN编译的库会引发兼容性问题。在gradle中开启HWASAN:
android { defaultConfig { externalNativeBuild { cmake { arguments "-DANDROID_HWASAN=ON" } } } } - 禁用冲突工具:如果同时启用了ASAN等其他内存调试工具,会与HWASAN冲突,需关闭后再测试。
内容的提问来源于stack exchange,提问作者leizh007
相关产品推荐
相关产品推荐

