Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Is it possible to change endianness mid-execution on ARM (Android/Linux)?





I am wondering if it is possible to change the endianness of a running application mid-execution on the ARM platform. As some of you know, ARM is bi-endian (supporting both big and little) and I am wondering if on Android (or linux in general) if it is possible to either set a single application to use a different endianness at execution or if it is possible to change the processor endianness mid-execution.

To head off some of the possible responses to this. Changing endianness (if possible on the application level) is almost assuredly a bad idea but I am building tools for the ARM platform and I am wondering if an application that I am using a set tools on could possibly do this. Also even if doing so could cause catastrophic consequences to other applications/OS I would like to know if it can be done by an application.

So far from my view of ARM it appears that only the OS can set the mode of the processor in this regard. However I have yet to find a definitive answer on this question. Thanks in Advance!

like image 614
NothingMore Avatar asked Mar 17 '23 22:03


1 Answers

It is (on ARMv7 and older hardware at least) certainly possible, but your sentiment is entirely correct - anyone else, please, please, for the sake of sanity, forward-compatibility and angry kernel developers, don't do this in Linux/Android - use REV, REV16, REVSH or VREV on data as appropriate.

The SETEND instruction, introduced in ARMv6, allows switching the endianness of the current execution state at any privilege level, however from ARMv8 it is deprecated, disabled by default, and likely to disappear entirely in future. Supporting mixed-endianness in hardware is optional in ARMv8.

Despite being a terrible idea, it's apparently commonplace enough in Android apps currently in the wild (among possible other uses, it's supposedly the fastest way to implement strcmp() on ARM11, and maybe also Cortex-A8) that SETEND emulation for 32-bit tasks has recently had to be added to the arm64 kernel, so chances are your tools should at least be aware of it, too.

like image 129
Notlikethat Avatar answered Apr 06 '23 09:04