问题描述
我正在Windows上编写一个用户空间文件系统驱动程序,而字节序转换是我一直在处理的事情,因为此特定文件系统始终以little-endian格式存储值,并且驱动程序应将其转换为(如有必要)正在运行的CPU。但是,我发现自己想知道是否还要担心字节序转换,因为据我所知,台式机Windows仅支持小字节序体系结构(IA32,x86-84等),因此也支持磁盘上的little-endian值是完美的sans转换。这种观察是否准确?如果可以,那么假设Windows将始终在低端字节顺序的硬件上运行通常是否可以接受?此外,是否有可能(在2011年)在大端仿真器或类似设备上运行Windows,以便甚至可以对端序问题进行测试?
I'm writing a userspace filesystem driver on Windows and endianness conversions are something I've been dealing with, as this particular filesystem always stores values in little-endian format and the driver is expected to convert them (if necessary) for the CPU it's running on. However, I find myself wondering if I even need to worry about endianness conversions, since as far as I can tell, desktop Windows only supports little-endian architectures (IA32, x86-84, etc.), and therefore, the on-disk little-endian values are perfectly fine sans conversion. Is this observation accurate, and if so, is it generally acceptable to make the assumption that Windows will always be running on little-endian hardware? Additionally, is it even possible (in 2011) to run Windows on a big-endian emulator or something, such that one could even test for endianness issues?
编辑:为了更加清楚,我的代码当前的工作方式是,在启动时进行字节序检查,然后每次从磁盘上加载值时,都会通过内联函数,如果体系结构为big-endian,则使用内在函数更改字节序。问题是,我不知道我是否会错过一个或多个我需要进行转换的地方,而查看是否被搞砸的最简单方法是在大端架构上运行程序。因此,我很想知道(a)是否有必要进行这些检查,因为Windows通常不会在小端平台上运行(无论如何,今天还是),并且(b)如何测试代码,因为我想不出一种在大端架构上运行Windows的方法,并且手动反转磁盘上的 all 的多字节值仍然涉及
For additional clarity, the way my code currently works, I do an endianness check at startup time, and then every time I load a value off the disk, I run it through an inline function that uses an intrinsic to change endianness if the architecture is big-endian. The problem is, I don't know if I might have missed one or more of those places where I needed to do a conversion and the easiest way to see if I screwed up is to run the program on a big-endian architecture. So I'm interested in knowing (a) if it's even necessary to do these checks since Windows doesn't ordinarily run on little-endian platforms (today anyway), and (b) how I could possibly test my code, seeing as I can't think of a way to run Windows on a big-endian architecture, and manually reversing all the multibyte values on disk still involves a manual process that I might well screw up.
推荐答案
您会看到的所有Windows版本都是little-endian,是的。 NT内核实际上在大端架构上运行。
All versions of Windows that you'll see are little-endian, yes. The NT kernel actually runs on a big-endian architecture even today.
这篇关于我可以安全地认为Windows安装将始终是低位优先的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!