Search code examples
linux-kernelkernelposixdarwinxnu

Run Linux exectuable on another POSIX kernel


Is it theoretically possible to execute built for one POSIX kernel (Linux for example) on second (Darwin's XNU for example)
And why it isn't possible?

If it's because of libraries and/or shared objects, maybe it's possible to leave just kernel and it's dependencies from whole second OS and use everything else from first?

So you'll have only kernel and drivers from second OS, and you can chroot to some place and you'll be able to run any executable for first?

Or Can we make some kind of dynamic wrapper or static translator?

UPD: Ok, I've found something similar, but there is just cursory recommendations, maybe someone could make it more clear?


Solution

  • There are just so many details that have to be right in order for programs to run. The libraries and shared objects is the first issue, but even if you replace all of those, the system call interface differs from OS to OS.

    And by system call interface, I don't mean the function prototypes, I mean how user-space tasks invoke system calls in the kernel. Even on x86, there are different ways to implement the trap that transitions into kernel mode, and different ways to transmit the system call argument details to the kernel. The details of this are typically built into the libraries/shared objects.

    So yes, it's theoretically possible to create a wrapping/translation layer, but that's a lot of work, and it's very difficult to get all the details right. This is one reason why virtualization has become so popular in recent years.