Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Linux binary under OS X

Is it possible to create a Linux compatibility layer inside OS X?

Someone have created xbinary, which is essentially an OS X port of binfmt_misc as a kext, here: http://www.osxbook.com/software/xbinary/. Extending from the idea here, I am guessing if it is possible to create a Linux compatibility layer inside OS X:

  • xbinary is obviously what makes the kernel accepts ELF. When an ELF is encountered ...
  • A port of ld-linux.so which itself is a Mach-O binary is started, loading ELF libraries (Mach-O libraries can also be used, to some extent).
  • Another kext that catches Linux syscalls (int 80h on x86 and amd64 systems) and translates them into corresponding OS X syscalls in kernel, or let the ld-linux.so replace all syscalls with a small function call in another library that translates them in userland.
like image 962
Maxthon Chan Avatar asked Apr 25 '14 18:04

Maxthon Chan


1 Answers

I think you would also need to make OS X support Linux personality so that the syscalls behave identically to those of Linux (if present)

Other than that a binary might depend on a VDSO shim present in higher randges of address space, which is usually taken care of by libc implementation on Linux

Many other subtleties are possible...

like image 93
rostamn739 Avatar answered Sep 29 '22 21:09

rostamn739