How to determine when Android x86 emulates an ARM?

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

I use NEON instructions on ARMv7, but instead of cluttering the code with a conditional / duplicate source, I want to detect non-NEON ARMv7 in Java while the library is loading and instead load the v5 library: a slow processor is slow.

I found a message suggesting that I look for the "neon" function in / proc / cpuinfo, so I parse this and load libthing.so usually or libthing-v5.so if the device claims to be ARMv7 without NEON. This works well on ARM.

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

My current solution is to simply copy the x86 library to libthing.so and libthing-v5.so, so if x86 pretends to be an ARMv7 chip, NEON-free, it will still get the x86 library.

Besides preparing a tiny, standalone library for architecture discovery based on our own Yeppp or Android processors, is there a way to define a true local Java architecture?


@ ph0b: At the same time, I show Razr that the emulator decided that the application is installed as "ABI2 58" and that it needs to fake / proc / cpuinfo.

Given that both shared libraries are available from x86, as well as in armeabi * directories, I donโ€™t understand why the device decided to become ARM. I could ask my contact from 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 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 
+8
x86 arm android-ndk
source share
4 answers

I doubt x86 emulates ARM / proc / cpuinfo !?

In any case, to discover the local Java architecture, 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 search for neon only if CPU_ABI and CPU_ABI2 - arm * / armeabi-v7a

+3
source share

You cannot rely on proc / cpuinfo, getProperty ("os.arch") or Build.CPU_ABI (2). They are all fake if emulation is active. As I make the discovery, I parse / proc / cpuinfo, looking for the word "placeholder". This is in the line "Hardware:". Usually there is such a brand name as "Samsung" for Samsung Galaxy, but in the case of emulation of ARM on x86, I see that in the hardware line there is only "placeholder" in / proc / cpuinfo. I have not tested it on many device models, so I canโ€™t say how reliable this is.

+2
source share

You can also get the e_machine value defined in the ELF file header, such as the libc.so file, to determine which architecture is specified.

https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header

Code snippet:

 File libc = new File(Environment.getRootDirectory(), "lib/libc.so"); // or 'lib64' if 64 bit // assert libc file exsits RandomAccessFile file = new RandomAccessFile(libc, "r"); file.seek(0x12); // 'e_machine' offset byte[] buf = new byte[2]; // 2 bytes size file.readFully(buf); int em = (buf[0] & 0xff) | ((buf[1] & 0xff) << 8); file.close(); if(em == 0x03 || em == 0x3E) { // x86! } 

When Build.CPU_ABI indicates that you are running on ARM, but conflicts with x86 em , it emulates!

+1
source share

As terrible as it sounds, if you have a different list of native libs for ARM and x86, then devices like the will automatically switch to running the application under the ARM emulator.

https://software.intel.com/en-us/forums/android-applications-on-intel-architecture/topic/518471

0
source share

All Articles