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

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

问题描述

在我的OS 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


推荐答案

CPU可以从64位执行模式切换到32位当它陷入内核上下文时,仍然可以构建32位内核以了解从64位用户空间应用程序传递的结构。

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.

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

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.

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

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天全站免登陆