How come a 32 bit kernel can run a 64 bit binary?

前端 未结 6 1949
太阳男子
太阳男子 2021-02-02 10:09

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 x         


        
6条回答
  •  余生分开走
    2021-02-02 10:21

    The 32 bit kernel that is capable of loading and running 64 bit binaries has to have some 64 bit code to handle memory mapping, program loading and a few other 64 bit issues.

    However, the scheduler and many other OS operations aren't required to work in the 64 bit mode in order to deal with other issues - it switches the processor to 32 bit mode and back as needed to handle drivers, tasks, memory allocation and mapping, interrupts, etc.

    In fact, most of the things that the OS does wouldn't necessarily perform any faster running at 64 bits - the OS is not a heavy data processor, and those portions that are (streams, disk I/O, etc) are likely converted to 64 bit (plugins to the OS anyway).

    But the bare kernel itself probably won't task switch any faster, etc, if it were 64 bit.

    This is especially the case when most people are still running 32 bit apps, so the mode switching isn't always needed, even though that's a low overhead operation, it does take some time.

    -Adam

提交回复
热议问题