Color Us Impressed: Redbean Runs a Web Server on Six Operating Systems

The holy grail of computing is to have some way to distribute a program to any computer. This is one of those totally unachievable goals, but many have tried with varying degrees of success.  People naturally think of Java, but even before that there was UCSD’s P-code and many other attempts to pull off the same trick. We were impressed, though, with Redbean 2.0 which uses a single executable file to run a webserver — or possibly other things — on six different operating systems. If the six operating systems were all flavors of Linux or Windows that wouldn’t be very interesting. But thanks to APE — the Actually Portable Executable — format, you can run under Windows, Linux, MacOS, OpenBSD, NetBSD, and FreeBSD.


This is quite a feat when you realize that most of these take wildly different file formats. There is one small problem: you can’t use much of anything on the host operating system. However, if you look at Redbean, you’ll see there is quite a lot you can do.



The APE loader takes advantage of some quirks. Under Windows, the executable is just that — an executable. Otherwise, there is a small shell script that the APE loader can use to map the executable into memory and do the ELF loading. You might say, “Wait! I don’t have the APE loader.” That’s OK. Each APE program has the 4K loader embedded in it that it will use if necessary.


Of course, it works because, at the bottom, the x86 instructions are the same across all the platforms. Since it is hard to call out to the underlying system, there is a libc, Cosmopolitan, that you can include. There are other modules, includin ..

Support the originator by clicking the read the rest link below.