为什么 32 位内核可以运行 64 位二进制文​​件? [英] How come a 32 bit kernel can run a 64 bit binary?

查看:30
本文介绍了为什么 32 位内核可以运行 64 位二进制文​​件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 OS X 机器上,内核是 32 位二进制文​​件,但它可以运行 64 位二进制文​​件.这是如何工作的?

<前>cristi:~ diciu$ 文件 ./a.out./a.out: Mach-O 64 位可执行文件 x86_64cristi:~ diciu$ 文件/mach_kernel/mach_kernel:具有 2 种架构的 Mach-O 通用二进制文件/mach_kernel(用于 i386 架构):Mach-O 可执行文件 i386/mach_kernel(用于体系结构 ppc):Mach-O 可执行 ppc克里斯蒂:~ diciu$ ./a.out克里斯蒂:~ diciu$ echo $?1

解决方案

CPU 在陷入内核上下文时可以从 64 位执行模式切换到 32 位,并且仍然可以构建 32 位内核来理解结构从 64 位用户空间应用传入.

MacOS X 内核无论如何都不会直接从用户应用程序中取消引用指针,因为它驻留在自己的单独地址空间中.例如,ioctl 调用中的用户空间指针必须首先解析为其物理地址,然后在内核地址空间中创建新的虚拟地址.ioctl 中的指针是 64 位还是 32 位并不重要,内核不会在任何一种情况下直接取消引用它.

因此混合 32 位内核和 64 位二进制文​​件可以工作,反之亦然.您不能做的是将 32 位库与 64 位应用程序混合使用,因为它们之间传递的指针将被截断.MacOS X 在每个版本中都提供了更多 32 位和 64 位版本的框架.

On my OS X box, the kernel is a 32 bit binary and yet it can run a 64 bit binary. How does this work?

cristi:~ diciu$ file ./a.out
./a.out: Mach-O 64-bit executable x86_64
cristi:~ diciu$ file /mach_kernel
/mach_kernel: Mach-O universal binary with 2 architectures
/mach_kernel (for architecture i386):   Mach-O executable i386
/mach_kernel (for architecture ppc):    Mach-O executable ppc
cristi:~ diciu$ ./a.out
cristi:~ diciu$ echo $?
1

解决方案

The CPU can be switched from 64 bit execution mode to 32 bit when it traps into kernel context, and a 32 bit kernel can still be constructed to understand the structures passed in from 64 bit user-space apps.

The MacOS X kernel does not directly dereference pointers from the user app anyway, as it resides its own separate address space. A user-space pointer in an ioctl call, for example, must first be resolved to its physical address and then a new virtual address created in the kernel address space. It doesn't really matter whether that pointer in the ioctl was 64 bits or 32 bits, the kernel does not dereference it directly in either case.

So mixing a 32 bit kernel and 64 bit binaries can work, and vice-versa. The thing you cannot do is mix 32 bit libraries with a 64 bit application, as pointers passed between them would be truncated. MacOS X supplies more of its frameworks in both 32 and 64 bit versions in each release.

这篇关于为什么 32 位内核可以运行 64 位二进制文​​件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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