← Back to context

Comment by tutfbhuf

5 years ago

Is it that this binary does some tricks to run on Linux, Mac, Windows, FreeBSD, OpenBSD, NetBSD, BIOS or does it really work on all operating systems including something like Plan 9 or even TempleOS?

And does it run on different architectures like ARMv6?

Native execution on x86_64 only. "Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS", where "BIOS" means that it will boot a machine and run on bare metal. On non x86_64 systems, the driver script will try to run the binary using QEMU (which has to be installed and on the path):

https://github.com/jart/cosmopolitan/blob/40291c9db386d8a952...

If i have understood how the portability works, it would be pretty straightforward to add support for another OS which uses the same ABI as the unices and has a compatible system call table - just a matter of adding a column to consts.sh (system call numbers in the nr section, constants from system headers in their appropriate sections) and adding any OS-specific system call rituals to systemfive.S.

Note that all system calls will go through the syscall interface. If your OS has some other way to make system calls, like Linux's vDSO or io_uring, that won't be used.

If your OS had a different system call table, like Windows, then you would need to write more bespoke code for it, like all the Windows wrappers:

https://github.com/jart/cosmopolitan/tree/0e85b136ae1beb0d2b...

You would then need to go through the Cosmopolitan libc and add implementations of its functions on top of your wrappers.