Javascript-based PC emulator, running GNU/Linux


Fabrice Bellard has written a 32 bit x86 emulator in Javascript -- in plain English, he's created a virtual PC that runs inside your browser, using Javascript. And then (of course), he created a GNU/Linux variant that can run inside it -- so you can run a full-featured PC inside your browser. It's a pretty fabulous hack and has far-reaching implications: for example, you could theoretically run any program or OS inside your browser, even if you're using a locked-down platform that won't let you change the OS or install your own programs. And then there's stuff like installing MAME in a virtual browser machine, so that you can play all/any retrogames.
What's the use ?
I did it for fun, just because newer Javascript Engines are fast enough to do complicated things. Real use could be:

* Benchmarking of Javascript engines (how much time takes your Javascript engine to boot Linux ?). For this particular application, efficient handling of 32 bit signed and unsigned integers and of typed arrays is important.
* Client side processing using an x86 library, for example for cryptographic purposes. For such application, the x86 emulator can be modified to provide an API to load x86 dynamic libraries and to provide a js-ctypes like API to call the C/C++ functions from javascript.
* A more advanced version would allow to use old DOS PC software such as games.

JS Linux

Javascript PC Emulator - Technical Notes

(via Command Line)

28

  1. First you run an OS. Then you run a browser and, inside this browser, you run another PC emulator. Inception’d.

  2. Also, if you’re on a restricted network, the perfect gag to make your company’s System Administrator freak out.

  3. Given that Java has butt-fucked the IT industry and their duped customers, this is a welcome return to thin/smart client software.

    1. Java and Javascript are two different technologies. They both come with bad developers, and bad habbits. But Javascript is a bit less bad than Java.

  4. I haven’t read too far into it, but what’s to stop you from running a browser-based PC inside of your browser-based PC?

  5. This is very cool, but also has strict limitations. It runs only in very recent browsers, and is only acceptably fast because the emulated hardware is very, very limited. Networking has not been implemented at all. It’s potential uses are really restricted to the narrow lines Fabrice drew.

    Of course, if it implemented networking and some related tools, it could have some additional uses. But really, there are other tools to accomplish those ends anyway.

    1. A more complete processor implementation (for example, adding the rest of the 486 instruction set, so that DOS games can be played) wouldn’t slow it down significantly. This is the guy who wrote QEMU, he knows how to write high-performance emulators. For networking, there’s the problem that the browser’s ability to make network connections is severely limited.

  6. Fabrice Bellard is also the creator of ffmpeg and QEMU, two tools I use frequently.

  7. Fabrice Bellard is one of the outstanding developers in the world: http://en.wikipedia.org/wiki/Fabrice_Bellard.

    What is really amazing is that he is so productive in so many different area: numerical methods, machine emulation, and even compiler technology. (Although TinyCC is known primarily for being compact.) Finding someone so knowledgeable in one of these areas is difficult. The fact that he is so accomplished in three is just mind-boggling.

  8. All I have to say is that this just screams of awesomeness. And here I thought I was doing well just writing games in Javascript.

  9. Yo dawg, I heard you like open source operating systems, so I created a javascript emulator that will run GNU in ur Windows so you can GNU in your virtual window while you run Windows.

  10. Hmmm. Next step, get X working. Then, you can install a browser. From this browser, you go to a Javascript-based PC emulator. Infinite recursion now becomes possible.

    1. Why not take that one step further:

      Install VirtualBox in your Java/Browser OS VM, then load a different OS, load your browser and repeat…

      Or something like that…

      (If we ever have the ability to “plug in” to a virtual world it’s all going to turn into the Matrix. How do you REALLY know you aren’t in a virtual world.)

  11. The amazing thing about a dancing bear isn’t how well he dances, but that he can dance at all.

    Given the restrictions of the JavaScript sandbox, this emulator cannot be of much use, but damn, it sure is cool!

  12. how you know dude is the real deal:
    pre-emptively answering the question: “BDIRL?”

  13. After doing “ls /” “cat /etc/passwd” “tcc -o hello hello.c”, I did the obvious:

    rm -rf /

  14. While it’s crazy to be running emacs in Javascript, and this is an amazing piece of work, I can’t help but feel that Flash would’ve been a better target platform for this. It has better networking support (including sockets), faster execution time, can live outside a browser, and the SWF format is open source. Of course, open source advocates don’t like to admit that it is, and would rather shoehorn everything into “HTML5” solutions, even though it’s not really mature yet. Flash 11 is going to have support for true threads, so it could pretty much fully implement a Linux system.

    But hey, what Bellard did is quite impressive, and if he wants to make something for the hell of it, props to him.

    1. SWF might be “open” (for some degrees of “openness”), but to play it you’ll always need a plugin, and the only decent plugin you’ll ever have is the one produced by Adobe; which means Flash is, in practice, a proprietary technology.

      Btw, Bellard didn’t do this “for the hell of it”, but rather to explore the full potential (and limitations) of recent Javascript engines. Some people code crappy, flickering “interactive films”, Fabrice writes OS emulators.

      To people talking of running X and firefox etc: the terminal window you see is rendered with HTML, which is why its performance is acceptable. To emulate a full video driver you’d need to draw every single pixel in javascript (which is doable but probably too slow), or start dishing out browser-specific hacks to reach the physical hardware (which is probably not doable and certainly insane). So no, you’ll probably never see that. God knows we have enough problems running X with real hardware…

      Networking is another matter; with the right bridging it could be done, at least in very recent browsers.

    2. What I like best about Flash is how predictably it crashes the tabs it runs in, a much better solution than browser standards like JavaScript.

  15. Where’s the GNU? no gcc, no glibc, and he used busybox. This isn’t really GNU/Linux

  16. Well the obvious thing to do now is to have interchangeable images, so you could load up your home or office computer anywhere, instantly. The great thing is that they wouldn’t have to be turned on and online all the time, only when you are using it. It could simply update an online image when you logoff. Now give me a million dollars for the idea.

  17. I’m more worried about the security risks concerned with this. Running a complete OS while transmitting TCP communications would mean unlimited access to what you are doing. This program could expand the world of cloud computing (cloud Virtual PCs – think about it), but think of what could be stolen as you are working. All it would take is one redirection malware, and everything you have been working on is now someone else’s.

Comments are closed.