如何检测 Android x86 何时模拟 ARM? [英] How can I detect when Android x86 is emulating ARM?

查看:25
本文介绍了如何检测 Android x86 何时模拟 ARM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JNI 库,可以在大多数 Android 设备(ARMv5、ARMv7 和 x86)上运行良好.

I have a JNI library that runs well on most Android devices - ARMv5, ARMv7, and x86.

我在 ARMv7 上使用 NEON 指令,但我想在库加载时检测 Java 中的非 NEON ARMv7,而不是用条件/重复源使代码混乱,并改为加载 v5 库:CPU 速度慢慢.

I'm using NEON instructions on ARMv7, but instead of cluttering the code with conditional/duplicated source, I want to detect a non-NEON ARMv7 in Java at library load time, and load the v5 library instead: slow CPU is slow.

我发现一个帖子建议我在/proc/cpuinfo 中寻找neon"功能,所以我正在解析它,并通常加载 libthing.so,或者 libthing-v5.so 如果设备声称是没有 NEON 的 ARMv7.这在 ARM 上运行良好.

I found a post suggesting that I look for the 'neon' feature in /proc/cpuinfo, so I'm parsing that, and loading libthing.so usually, or libthing-v5.so if the device claims to be an ARMv7 without NEON. This works nicely on ARM.

不幸的是,x86 不仅模拟 ARM/proc/cpuinfo(!),如果它决定不理解 NEON,它还会从 armeabiv7a 目录中挖掘出 libthing-v5.so,并使用它,因为没有不是 x86 目录中的一个.

Unfortunately not only does x86 emulate an ARM /proc/cpuinfo(!), if it decides it doesn't understand NEON then it also digs out the libthing-v5.so from the armeabiv7a directory, and uses it because there isn't one in the x86 directory.

我目前的解决方法只是将 x86 库复制到 libthing.so 和 libthing-v5.so,因此如果 x86 假装是无 NEON 的 ARMv7 芯片,它无论如何都会获得 x86 库.

My current workaround is just to copy the x86 library to both libthing.so and libthing-v5.so so if x86 is pretending to be a NEON-free ARMv7 chip, it'll get the x86 library anyway.

除了基于 Yeppp 或 Android 自己的 cpu 特性构建一个我自己的小型独立架构检测库之外,还有没有办法从 Java 中确定真正的本地架构?

Aside from cooking up a tiny standalone architecture-detecting library of my own based on Yeppp or Android's own cpufeatures, is there a way to determine the genuine local architecture from Java?

@ph0b:这是 Razr i 的输出,表明模拟器已决定应用程序已安装为ABI2 58",并且需要伪造/proc/cpuinfo.

@ph0b: Herewith the output of the Razr i, showing that the emulator has decided that the application has been installed as an 'ABI2 58', and that it needs to fake out /proc/cpuinfo.

鉴于 x86 和 armeabi* 目录都可以使用这两个共享库,我不明白为什么该设备决定成为 ARM.我可能会询问我在英特尔的联系人.

Given that both shared libraries are available from x86 as well as the armeabi* directories, I don't understand why the device has decided to be an ARM. I might ask my contact at Intel about this.

06-05 10:58:41.360 17807 18053 D dalvikvm: Trying to load lib /data/data/com.company.android/lib/libmp.so 0x42409cb0
06-05 10:58:41.360 17807 18053 D dalvikvm: Added shared lib /data/data/com.company.android/lib/libmp.so 0x42409cb0
06-05 10:58:41.370 17807 18053 D dalvikvm: No JNI_OnLoad found in /data/data/com.company.android/lib/libmp.so 0x42409cb0, skipping init
06-05 10:58:41.420 17807 18053 D         : Searching package installed with ABI2 with Uid: 10109 
06-05 10:58:41.420 17807 18053 D         : Apps with ABI2 58 accessing /proc/cpuinfo 
06-05 10:58:41.430 17807 18053 I System.out: #Here's most of /proc/cpuinfo
06-05 10:58:41.430 17807 18053 I System.out: #Thu Jun 05 10:58:41 GMT+01:00 2014
06-05 10:58:41.430 17807 18053 I System.out: Serial=0000000000000001
06-05 10:58:41.430 17807 18053 I System.out: Revision=0001
06-05 10:58:41.430 17807 18053 I System.out: CPU=revision\t\: 1
06-05 10:58:41.430 17807 18053 I System.out: BogoMIPS=1500
06-05 10:58:41.430 17807 18053 I System.out: Hardware=placeholder
06-05 10:58:41.430 17807 18053 I System.out: Features=vfp swp half thumb fastmult edsp vfpv3 
06-05 10:58:41.430 17807 18053 I System.out: Processor=ARMv7 processor rev 1 (v7l)
06-05 10:58:41.430 17807 18053 I NativeWahooLibrary: Detected ARMv7 processor rev 1 (v7l) (=ARMv7, true) with (neon@-1) vfp swp half thumb fastmult edsp vfpv3 
06-05 10:58:41.430 17807 18053 D dalvikvm: Trying to load non-neon lib /data/data/com.company.android/lib/libwahoo-v5.so 0x42409cb0

推荐答案

我怀疑 x86 模拟了 ARM/proc/cpuinfo !?

I doubt the x86 emulates an ARM /proc/cpuinfo !?

无论如何,为了从 Java 中检测本地架构,您可以依赖 Build.CPU_ABIBuild.CPU_ABI2:http://developer.android.com/reference/android/os/Build.html#CPU_ABI,然后继续解析/proc/cpuinfo 以仅在 CPU_ABI 和 CPU_ABI2 为 arm*/armeabi-v7a 时查找 neon

Anyway, in order to detect the local architecture from Java, you can rely on Build.CPU_ABI and Build.CPU_ABI2: http://developer.android.com/reference/android/os/Build.html#CPU_ABI, and then continue parsing /proc/cpuinfo to look for neon only if CPU_ABI and CPU_ABI2 are arm*/armeabi-v7a

这篇关于如何检测 Android x86 何时模拟 ARM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆