|
|
Subscribe / Log in / New account

A Linux system running over JavaScript

Fabrice Bellard has posted an x86 emulator written entirely in JavaScript which enables one to boot a Linux system inside a web browser. There are some technical details available for those who want to know how it works. "The CPU is close to a 486 compatible x86 without FPU. The lack of FPU is not a problem when running Linux as Operating System because it contains a FPU emulator. In order to be able to run Linux, a complete MMU is implemented."

(Log in to post comments)

A Linux system running over JavaScript

Posted May 17, 2011 13:36 UTC (Tue) by lkundrak (subscriber, #43452) [Link]

I'm amazed at how fast it is.

A Linux system running over JavaScript

Posted May 17, 2011 14:50 UTC (Tue) by rsidd (subscriber, #2582) [Link]

Indeed, the boot seems faster than on a real 486, if my memory doesn't mislead. It of course doesn't probe hardware, but the boot messages seem to go by faster too. Perhaps not surprising: those were 66 MHz machines, and javascript emulator on a 3 GHz machine is likely faster...

A Linux system running over JavaScript

Posted May 17, 2011 14:53 UTC (Tue) by PhracturedBlue (subscriber, #4193) [Link]

Well, I got about 20 bogomips from /proc/cpuinfo when running on my laptop, but still, I agree, it feels very usable from a quick tour.

A Linux system running over JavaScript

Posted May 17, 2011 19:01 UTC (Tue) by sjlyall (guest, #4151) [Link]

I got around 20 BogoMips as well. Did a quick benchmark with a simple shell loop and it was 400 times slower than my PC ( 4822 BogoMips ).

According to the BogoMips website 20 is around a 486DX/40 ( That is 40MHz ) which is roughly the PC I had in 1994 (running Linux).

A Linux system running over JavaScript

Posted May 18, 2011 9:47 UTC (Wed) by dgm (subscriber, #49227) [Link]

Well, curiously I did get the same BogoMips (20.21), both in Firefox 4 and Chromium, on a virtual machine and on the host OS, which seems weird...

A Linux system running over JavaScript

Posted May 18, 2011 12:35 UTC (Wed) by gnb (subscriber, #5132) [Link]

Seems reasonable - if there's no attempt to sync. the emulated RTC to wall time, the bogomips calculation will just give emulated instructions per tick of the emulated clock, which should be independent of the browser or host (and even more useless than normal bogomips as a performance estimator).

A Linux system running over JavaScript

Posted May 17, 2011 15:01 UTC (Tue) by tjc (guest, #137) [Link]

> I'm amazed at how fast it is.

I'd be amazed even if it were slow!

A Linux system running over JavaScript

Posted May 17, 2011 15:05 UTC (Tue) by tjc (guest, #137) [Link]

...was slow. A little midlands creeping in there...

A Linux system running over JavaScript

Posted May 17, 2011 15:16 UTC (Tue) by endecotp (guest, #36428) [Link]

"were slow" is correct - it's the subjunctive.

A Linux system running over JavaScript

Posted May 17, 2011 15:19 UTC (Tue) by tseaver (guest, #1544) [Link]

"...if it were slow" is actually correct here, because the clause is subjunctive (a hypothetical-but-not-true case).

A Linux system running over JavaScript

Posted May 18, 2011 0:09 UTC (Wed) by JoeBuck (subscriber, #2330) [Link]

The subjunctive appears to be disappearing from American English at a rapid rate, and soon only Brits, pedantic Americans, and students of English as a second language will know what it is. Perhaps this is part of language evolution; around 1600 English still had Germanic verb endings (he maketh, thou makest) and they all went away.

Grammar pundits

Posted May 18, 2011 4:00 UTC (Wed) by ncm (subscriber, #165) [Link]

In fact they are both right, in England as elsewhere, and have been as long as there's been an English. "Were" makes it a subjunctive construction, where "was" just makes it trivially conditional. The subjunctive isn't really being lost, it's just falling out of fashion, as it's done before and may have many opportunities to do again.

In the meantime, do you drive a car, or an automobile, or a motor vehicle? Is that a gadget or a device? Is 'a' or 0x61 right? In all cases, the answer is (for inclusive interpretations of "or") yes.

Grammar pundits

Posted May 18, 2011 9:12 UTC (Wed) by pboddie (subscriber, #50784) [Link]

I think the original commenter's confusion lay in the observation that in various northern English dialects "were" has replaced "was" in various unconditional constructs, such as "I were going" and "he were eating", giving "was" fewer appearances than may have seemed fair. Having said that, I imagine that "was" could get introduced in the original case by speakers of those dialects.

Grammar pundits

Posted May 19, 2011 16:45 UTC (Thu) by tjc (guest, #137) [Link]

You are correct. Sorry for starting such an off-topic sub-thread. It were bad!

A Linux system running over JavaScript

Posted May 17, 2011 13:54 UTC (Tue) by mcg (guest, #66950) [Link]

Wonder if Apple will block this as being against the TOS, if it ever works on iOS? :-)

A Linux system running over JavaScript

Posted May 17, 2011 14:53 UTC (Tue) by michel (subscriber, #10186) [Link]

My head just exploded.

A Linux system running over JavaScript

Posted May 17, 2011 15:02 UTC (Tue) by clump (subscriber, #27801) [Link]

This opens a world of possibilities. I'm extremely impressed.

A Linux system running over JavaScript

Posted May 18, 2011 8:46 UTC (Wed) by robert_s (subscriber, #42402) [Link]

"This opens a world of possibilities."

Does it? I'm extremely worried if anyone plans on using this for something mainstream, as impressive as it is.

A Linux system running over JavaScript

Posted May 19, 2011 14:02 UTC (Thu) by clump (subscriber, #27801) [Link]

Why be worried? Is creating a virtual machine from a browser any more or less of a cause for concern than "normal" ways of starting virtual machines?

As per possibilities, the traditional ways of starting machines are (roughly): 1) bare metal, 2) subsets of bare metal, or 3) using relatively dedicated software to start virtual machines. Starting a virtual machine from a web browser is new way of starting virtual machines, with a very common denominator.

security interest

Posted May 18, 2011 11:57 UTC (Wed) by copsewood (subscriber, #199) [Link]

I imagine an early application will be more extensive fuzz testing of the Javascript sandbox security implementation. This will hopefully lead to better sandboxes. Unfortunately it's also likely to lead to more undisclosed zero day exploits being sold to intelligence agencies and crooks.

security interest

Posted May 18, 2011 12:14 UTC (Wed) by epa (subscriber, #39769) [Link]

I imagine an early application will be more extensive fuzz testing of the Javascript sandbox security implementation.
Doubtful. If you wanted to test Javascript security you'd do it by writing Javascript code directly, not by writing 386 machine code which runs in an emulated machine implemented in Javascript.

A Linux system running over JavaScript

Posted May 17, 2011 15:07 UTC (Tue) by markusw (guest, #53024) [Link]

Ugh.. wow.. okay, that's just plain crazy. Why would anybody ever want to emulate x86 on a browser? Or use more than 640k of memory, for that matter. I like crazy!

A Linux system running over JavaScript

Posted May 17, 2011 15:49 UTC (Tue) by mikov (guest, #33179) [Link]

Wow! Just wow. Fabrice Bellard is exceptional as usual. It is funny to check what percentage of one's friends (or relatives) can appreciate the pure awesomeness of it :-)

Alas, it doesn't run on my Nexus One ... :-(

A Linux system running over JavaScript

Posted May 17, 2011 16:08 UTC (Tue) by bjacob (subscriber, #58566) [Link]

Have you tried Firefox Mobile ? ;-)

A Linux system running over JavaScript

Posted May 18, 2011 10:55 UTC (Wed) by pointwood (guest, #2814) [Link]

I did and yes, it loads :)

I wasn't able to type any commands though.

A Linux system running over JavaScript

Posted May 17, 2011 16:23 UTC (Tue) by geertj (subscriber, #4116) [Link]

Agreed - Fabric Bellard is one of the most awesome hackers around. QEmu, ffmpeg, a tiny (100KB) c compiler, and having computed the most digits of Pi for a while in 2010 using a single desktop PC. Truly amazing.

A Linux system running over JavaScript

Posted May 17, 2011 16:06 UTC (Tue) by aogulla (guest, #29747) [Link]

I'm impressed. Got it to run on my Nokia N8!

A Linux system running over JavaScript

Posted May 17, 2011 19:11 UTC (Tue) by Hausvib6 (guest, #70606) [Link]

I've just tried rm -rf /. It works!

You can rm -rf /, but...

Posted May 21, 2011 0:55 UTC (Sat) by pr1268 (guest, #24648) [Link]

startx doesn't work. Darn. ;-)

You can rm -rf /, but...

Posted May 23, 2011 8:50 UTC (Mon) by arief (guest, #58729) [Link]

If you need startx there's that gtk work with backend engine that allow your gtk application to run inside browser.

Only run with HTML5 supporting browser though:

http://blogs.gnome.org/alexl/2011/03/15/gtk-html-backend-...

A Linux system running over JavaScript

Posted May 17, 2011 19:11 UTC (Tue) by Aissen (subscriber, #59976) [Link]

Anyone know the reason why Bellard stopped at the 4 years old 2.6.20 kernel ?

I tried reproducing what he did by re-compiling a kernel to run in the jslinux, it works with 2.6.20.21, but didn't work with 2.6.38.6. I didn't have time to bisect it.

So I guess it's something that was introduced after 2.6.20 that cannot be emulated by jslinux. Is it the tickless kernel ? The merging of i386 and x86_68 architectures ? The CFS scheduler ? Or something else ?

A Linux system running over JavaScript

Posted May 17, 2011 19:15 UTC (Tue) by tzafrir (subscriber, #11501) [Link]

FPU emulation. See the notes.

A Linux system running over JavaScript

Posted May 18, 2011 4:15 UTC (Wed) by jdub (subscriber, #27) [Link]

Why, was kernel FPU emulation removed?

A Linux system running over JavaScript

Posted May 18, 2011 19:10 UTC (Wed) by rahvin (guest, #16953) [Link]

How many x86 CPU's have you run into that don't have FPU's?

The simple reality is that such a piece of hardware hasn't existed for a very long time and I believe the kernel dev's took the opinion that it was causing needless pain to leave it in when no one was using it. Not to mention that there are still all those old kernels that can do it which IMO are much more suited to all that old hardware than the newer kernels. Finally, that the vast majority of people didn't even notice it was gone until someone built a fancy little emulator without FPU support is also indicative that they made the right decision in excising the code.

A Linux system running over JavaScript

Posted May 19, 2011 0:26 UTC (Thu) by Darkmere (subscriber, #53695) [Link]

What? They are all over the place, especially in the x86-embedded market, 486SX (VorteX86 and similar SoC chipsets) is a very capable little controller that works exceptionally well.

Also, FPU emulation works on newer kernels than 6.20, so that's just fine too.

A Linux system running over JavaScript

Posted May 19, 2011 7:13 UTC (Thu) by richard_weinberger (subscriber, #38938) [Link]

JSLinux has problems with newer kernels because it passes the kernel command line in an old-styled way.
Commit fa76dab9 (x86: clean up setup.h and the boot code) "broke" Linux >= 2.6.24 on JSLinux.

Fabrice Bellard has to update his linuxstart.bin bootloader...

Qemu security?

Posted May 17, 2011 19:19 UTC (Tue) by tbleher (guest, #48307) [Link]

Very impressive indeed!
There's just one thing that worried me when I read the technical details page:
> No segment limit and right checks when accessing memory (Linux does not rely on them for memory protection, so it is not an issue. The x86 emulator of QEMU has the same restriction).

Does that mean that a user process inside Qemu could scribble over the emulated kernel (i.e. no memory protection at all)? Or does this just mean that x86 segments are not implemented?

I'm not a native speaker, so I'm not sure if I parse the sentence correctly.

Qemu security?

Posted May 17, 2011 19:26 UTC (Tue) by flewellyn (subscriber, #5047) [Link]

The latter. The Linux kernel uses the MMU, not the segments, for memory protection.

A Linux system running over JavaScript

Posted May 17, 2011 23:06 UTC (Tue) by gevaerts (subscriber, #21521) [Link]

Maybe this is a "good" way to add Native Client support to firefox

A Linux system running over JavaScript

Posted May 19, 2011 21:45 UTC (Thu) by cmccabe (guest, #60281) [Link]

I "agree"

A Linux system running over JavaScript

Posted May 18, 2011 0:02 UTC (Wed) by karim (subscriber, #114) [Link]

Simply awesome

A Linux system running over JavaScript

Posted May 18, 2011 0:39 UTC (Wed) by mekinglong (guest, #62075) [Link]

Wow!Wow!Wow!

A Linux system running over JavaScript

Posted May 18, 2011 0:50 UTC (Wed) by kripkenstein (guest, #43281) [Link]

Doesn't work in newest dev versions of Firefox and Chrome. Perhaps some change with the typed arrays spec?

In Firefox I get "invalid arguments" as the error, but the whole file is on one line so hard to tell what the problem is.

A Linux system running over JavaScript

Posted May 18, 2011 6:50 UTC (Wed) by przemoc (guest, #67594) [Link]

Not sure whether it is the same problem in Chrome dev as in beta, but if the answer is yes, then you can track the issue here:

http://code.google.com/p/chromium/issues/detail?id=82828

A Linux system running over JavaScript

Posted May 18, 2011 16:22 UTC (Wed) by nlucas (subscriber, #33793) [Link]

They seem to have identified the problem as a bug on the javascript optimization compiler:

http://code.google.com/p/v8/issues/detail?id=1394#c2

A Linux system running over JavaScript

Posted May 26, 2011 7:18 UTC (Thu) by przemoc (guest, #67594) [Link]

Just a follow-up.

http://codereview.chromium.org/7037023

It's theoretically addressing v8 issue 1394, but in fact it's more about Chromium issue 82828. The problem of v12/13 was just briefly mentioned in "PC emulator is about 2 times slower using V8 than Jaeger Monkey" report and did not have deserving separate issue in v8 project.

> Fix bug in optimized compiler's switch-statement.
>
> In the case where the default-clause occurs as the first clause, the case-blocks were not wired up correctly.

So it was a matter of extracting non-NULL check equivalently from if block into inner if. That shouldn't be really needed in obtaining correct behavior though...

Speed deficiency (when compared to Fx) remains for the time being.

A Linux system running over JavaScript

Posted May 18, 2011 8:46 UTC (Wed) by meuh (guest, #22042) [Link]

The new Javascript engine benchmark is born !
Bogomips for all.

A Linux system running over JavaScript

Posted May 18, 2011 9:29 UTC (Wed) by gevaerts (subscriber, #21521) [Link]

Has nobody else noticed by now that it's around 20 bogomips everywhere?

I don't think bogomips will be more useful as a javascript benchmark than it was as a CPU benchmark.

A Linux system running over JavaScript

Posted May 18, 2011 10:35 UTC (Wed) by meuh (guest, #22042) [Link]

I have probably forgotten to add a <sarcasm> tag around my comment.

A Linux system running over JavaScript

Posted May 18, 2011 9:07 UTC (Wed) by mcon147 (subscriber, #56569) [Link]

So could grab some useful code in C/C++, compile it for x86-i486 without fpu, then my javascript/coffeescript code can use the console emulator to talk to it and use its output?

A Linux system running over JavaScript

Posted May 18, 2011 12:16 UTC (Wed) by epa (subscriber, #39769) [Link]

You can already compile things to Javascript using Emscripten.

A Linux system running over JavaScript

Posted May 18, 2011 14:40 UTC (Wed) by xxiao (subscriber, #9631) [Link]

this guy(ffmpeg founder, etc) is indeed a genius!

javascript keeps getting more powerful these days too, from browser to desktop to server side.

A Linux system running over JavaScript

Posted May 18, 2011 15:09 UTC (Wed) by dakt (guest, #74570) [Link]

This guy is amazing...true and rare role model in this industry...

A Linux system running over JavaScript

Posted May 18, 2011 17:43 UTC (Wed) by NightMonkey (subscriber, #23051) [Link]

Very creative work. Thanks for the great hacks, Fabrice Bellard! :)

A Linux system running over JavaScript

Posted May 18, 2011 18:11 UTC (Wed) by korpenkraxar (guest, #75003) [Link]

yo dawg, I herd you like browsing, so I put a server in your browser so you can serve while you browse :-)

A Linux system running over JavaScript

Posted May 18, 2011 20:19 UTC (Wed) by dag- (guest, #30207) [Link]

I'd like to see some sort of network interface (maybe tun/tap) so anyone/anywhere can run Linux and access network resources...

Thanks a lot, Fabrice ;-)

A Linux system running over JavaScript

Posted May 18, 2011 22:37 UTC (Wed) by ballombe (subscriber, #9523) [Link]

Agreed. Maybe Fabrice can reuse the nfeth kernel module.
Busybox already include wget.

A Linux system running over JavaScript

Posted May 20, 2011 11:55 UTC (Fri) by Tobu (subscriber, #24111) [Link]

What does nfeth do? I've found very little about it, except that it stands for "nat-feature" ethernet.

A Linux system running over JavaScript

Posted May 20, 2011 17:37 UTC (Fri) by Simetrical (guest, #53439) [Link]

JavaScript running as part of a web page doesn't have network access. All it can do is issue HTTP requests, and those only with substantial limitations. E.g., if you even want access to the raw response data, you need to use XMLHttpRequest, which normally only works same-origin (bellard.org can only send requests to bellard.org URLs). Web page JavaScript is never going to be able to use things like SSH to arbitrary hosts: otherwise merely visiting a website would let the owner use your machine for portscanning and so on. If it were ported to be a browser extension instead of just a web page, that might change things, but of course that takes away half the fun.

A Linux system running over JavaScript

Posted May 23, 2011 0:15 UTC (Mon) by dag- (guest, #30207) [Link]

Hosting on the server that provides the javascript does not seem like a show-stopper at all. For those people that contemplate using it, tunneling over JSON through some sort of proxy seems useful.

Don't dismiss it straight off...

A Linux system running over JavaScript

Posted May 23, 2011 14:16 UTC (Mon) by Simetrical (guest, #53439) [Link]

What do you propose, tunneling TCP over XMLHttpRequest? XHR requires you to submit the full request up front and doesn't give you the response until it's completely received, so you'd have to create and destroy an entire HTTP session every time you wanted to send or receive a single packet to or from the tunnel. I don't recommend you try running SSH this way -- the latency would likely be insufferable.

This might be feasible once WebSockets is usable again. But it would only work if the server trusts the client not to abuse it as an anonymous proxy. Realistically, as I said, it would be more plausible to write a version that works as a browser extension of some kind, while still being written entirely or almost entirely in JavaScript. Then you could conceivably have real networking access.

A Linux system running over JavaScript

Posted May 26, 2011 18:17 UTC (Thu) by dbarnes (guest, #75204) [Link]

Websockets were revised last month. Is it still not usable? If not, why?

A Linux system running over JavaScript

Posted May 26, 2011 22:23 UTC (Thu) by Simetrical (guest, #53439) [Link]

I meant that it's not usable in production, i.e., in cases where you can't ask users to use a specific browser version or reconfigure the one they use, or where you don't want to rewrite your server every couple of months to keep up with breaking wire protocol changes. It's usable for experimentation, and might be usable for production once multiple browsers implement the current version and leave it enabled by default.

A Linux system running over JavaScript

Posted May 19, 2011 8:26 UTC (Thu) by misiu_mp (guest, #41936) [Link]

Hmm, I tried it in chromium 12.0.718.0 and it hangs after "Freeing unused kernel memory". Then once I got panic and the other time mm/memory.c:117: bad pgd 002c2027.
Otherwise it just hangs there working hard on something. How can an emulator written in JS end up with bad memory? My system is otherwise as stable as ever but I'll have to check for bad ram some day when it's time to reboot.

A Linux system running over JavaScript

Posted May 19, 2011 19:27 UTC (Thu) by dtlin (subscriber, #36537) [Link]

V8 had a bug. It's been fixed but I don't think it's made it into a release yet.

A Linux system running over JavaScript

Posted May 19, 2011 18:52 UTC (Thu) by dashesy (guest, #74652) [Link]

Very impressive indeed!

A Linux system running over JavaScript

Posted May 19, 2011 21:39 UTC (Thu) by korpenkraxar (guest, #75003) [Link]

Haha! Didn't work for me at first due to using NoScript :-p

A Linux system running over JavaScript

Posted May 26, 2011 16:46 UTC (Thu) by dbarnes (guest, #75204) [Link]

I got Microcore 3.6 running on it, which uses the 2.6.33.3 kernel. I ran lighttpd and served pages to lynx. Screenshots and details are at
http://forum.tinycorelinux.net/index.php?topic=9740


Copyright © 2011, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds