是否可以在 ARM(Android/Linux)上更改字节顺序? [英] Is it possible to change endianness mid-execution on ARM (Android/Linux)?

查看:27
本文介绍了是否可以在 ARM(Android/Linux)上更改字节顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在 ARM 平台上更改正在运行的应用程序中途执行的字节序.正如你们中的一些人所知,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.

阻止对此的一些可能的反应.更改字节顺序(如果可能在应用程序级别)几乎肯定是一个坏主意,但我正在为 ARM 平台构建工具,我想知道我正在使用一组工具的应用程序是否可以做到这一点.此外,即使这样做可能会对其他应用程序/操作系统造成灾难性后果,我想知道它是否可以由应用程序完成.

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.

到目前为止,从我对 ARM 的看法来看,似乎只有操作系统可以在这方面设置处理器的模式.但是我还没有找到关于这个问题的明确答案.提前致谢!

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!

推荐答案

这肯定是可能的(至少在 ARMv7 和更旧的硬件上),但你的观点是完全正确的 - 请其他人,,为了理智、向前兼容和愤怒的内核开发人员,不要在 Linux/Android 中这样做 - 使用 REVREV16REVSHVREV 视情况而定.

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.

SETEND 指令,在 ARMv6 中引入,允许在任何特权级别切换当前执行状态的字节顺序,但是从 ARMv8 开始,它已被弃用,默认禁用,并且将来可能会完全消失.在 ARMv8 中支持硬件混合字节序是可选的.

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.

尽管这是一个糟糕的想法,但它显然在目前广泛使用的 Android 应用程序中已经司空见惯(在可能的其他用途中,它被认为是在 ARM11 和 Cortex 上实现 strcmp() 的最快方法-A8) 32 位任务的 SETEND 仿真最近必须是 添加到 arm64 内核,因此您的工具至少也应该意识到这一点.

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.

这篇关于是否可以在 ARM(Android/Linux)上更改字节顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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