Boot a linux kernel right inside your browser.
bellard.org
bellard.org
Fabrice uses this to implement an x86 interpreter -- it could not be done efficiently without typed arrays. However, it is still slow -- imagine what kind of advances could be made if a common bytecode was established that would be JIT'd by the JavaScript VM, and could be output directly by the emulator.
This is why so many people want to see the browser execution environment offer more complete, low-level APIs instead of high-level APIs locked to HTML/CSS and legacy browser technology. Efficiently supporting high-performance, high-complexity systems such as an x86 emulator (or a video game, or custom font rendering, or even an application framework) absolutely require efficient low-level APIs.
Its a pity that javascript is so in-grained in client-side web now, as its really a terrible bytecode... Hell, failing the above, I would have liked to see Lua as the default client-side language, rather than Javascript (for reasons I will mention shortly), but of course that will never happen now that Javascript has been the default for fifteen years.
The reasons I would like Lua as the default language, besides the fact that LuaJIT is very fast (certainly for number crunching code, especially if you use the FFI to operate on low level structs (I mean, without calling into C) - the FFI is also one of, if not the, simplest FFI I've seen in any language[1]), it is, at least under my impression, a much more consistent language, while being just as flexible, easy to learn and dynamic. The thing I dislike most about Javascript is that it has lots of little gotchas and inconsistencies. Having said that, though, perhaps Lua does too and I just haven't used it enough yet to get bitten by them. Then again, it didn't take long for this to happen in Javascript, so Lua does at least seem to be a little friendlier.
[1] Actually, I think Factor's FFI is similarly simple, if my memory serves me correctly
That said, I'd give a higher priority for the language in my browser to be safe: some kind of correctness guarantee would be nice. Or even, while we're at it, some kind of way to analyze the script and say "this script GETS from urls x,y, and posts data d to z"
local ffi = require("ffi")
int = ffi.new("int")
int = 10
print(int)
I also don't find the lack of macros in Lua as limiting as I do in other languages. For example, if I wanted to create an EDSL in Lua, I would have it parse a string at startup. For example, imagine a state machine DSL: fsm = my_dsl[[
start: foo
stop: quux
foo -> bar
foo -> baz
bar -> foo
baz -> quux
]]{ foo = function()
code for foo here
end,
bar = function()
code for bar here
end,
baz = function()
code for baz here
end,
quux = function()
code for quux here
end
}
fsm.run()
As a real-world example, here is some Lua code I'm using in a hobby game project: DEFINE(Traits.Position)[[
float x;
float y;
float z;
]]
DEFINE(Traits.Movement)[[
float x;
float y;
float z;
]]
DEFINE(Behaviors.do_movement){
input={Traits.Position, Traits.Movement},
output=Traits.Position,
frequency=0.01,
-- Update entities position
fn = function (pos, mov)
local delta = dark.timedelta
new_pos = Traits.Position.new()
new_pos.x = pos.x + (mov.x * delta)
new_pos.y = pos.y + (mov.y * delta)
new_pos.z = pos.z + (mov.z * delta)
return new_pos
end}
-- Create a sample entity
local entity = Entities.new()
entity.add(Traits.Position, {1.0, 0.0, 0.0})
entity.add(Traits.Movement, {0.0, -1.0, 0.0})
"That said, I'd give a higher priority for the language in my browser to be safe: some kind of correctness guarantee would be nice. Or even, while we're at it, some kind of way to analyze the script and say "this script GETS from urls x,y, and posts data d to z""I definitely agree with the above.
Gilad Bracha complains about this at http://gbracha.blogspot.com/2011/03/truthiness-is-out-there....
I'm beginning to believe NativeClient and PNaCl (LLVM on NaCl: http://nativeclient.googlecode.com/svn/data/site/pnacl.pdf) has the best shot at becoming this.
Google is already including NaCl in Chrome developer builds, so I wouldn't be surprised if they enabled it in releases by the end of the year, and started releasing Native Client applications soon after.
http://blog.chromium.org/2011/02/native-client-getting-ready...
Hopefully this was an inaccurate impression, because NaCl could have a huge impact on both the client and server
The best path to adoption would be for Google to very aggressively push NaCL as a Flash-like plugin. If they could get adoption -- through Unity3d on Facebook or something like that -- perhaps they'd win in the long run. If they just keep it part of Chrome it seems rather hopeless.
The problem is not that NaCl is insufficiently secure, but any vulnerability will be spun as "Google making your system insecure". I think an independent group doing the same thing would be no more or less secure, but wouldn't have the baggage that would come from being seen as a component of a much bigger entity.
Me too, although the biggest hurdles seem as much political as they are technical.
My hope is that Google can strong-arm NativeClient into active use, forcing otherwise recalcitrant browser makers (Mozilla, Apple, Microsoft) into adopting it.
I won't get into the details because there's tons of information out there (http://www.chromium.org/nativeclient/reference/research-pape...), but code must be compiled using a special NaCl compiler, then before it's executed the client runs it through the NaCl verifier to ensure it's safe to execute.
Of course it's possible there are bugs in NaCl, but Google won't enable it in Chrome by default until they're very confident it's secure.
It's possible that the design could be flawed, but the same is true for browser implementations and mobile application sandboxing.
1. More language independence
2. Great performance for games, video (think implementing codecs without the need for browser support), and for crazy things like this.
3. Most importantly, the ability to run actual desktop-like apps in the browser at near-native speeds, instead of the mess that is currently required to get web apps to behave like desktop apps. (Nowadays Rails and friends are hiding most of this mess, but it's still there.)
Strange that people actually think Java would be the saviour. Feel free to keep continue to use Java applets if you think they're superior tech, they should still be well supported.
1. When a user starts loading a page (read 'web app') the browser spawns a new JVM for that page. How long does this take? You can bring it down to the price of a fork if you keep a JVM running at all times.
2. Instead of running javascript that's embedded in the page, you compile and run Java/JRuby/Jython. Better yet -- have the server precompile the embedded code and send you the bytecode. Load it dynamically into the JVM and run it in the page's thread. With a modern JVM you get JIT for free and the code runs at near-native speeds.
3. Want long-running background tasks? No problem -- the JVM code can start its own threads. Suddenly AJAX, and all the other stuff we use to make web apps behave like desktop apps becomes trivial.
4. User leaves the page / web app? Kill the JVM.
You can actually call methods in a Java applet from Javascript and vice-versa. It just doesn't seem to be used very much:
http://download.oracle.com/javase/tutorial/deployment/applet...
> time java HelloWorld
Hello, World!
java HelloWorld 0.28s user 0.06s system 135% cpu 0.248 total
In any case, the JVM is just an example (although I still argue it can serve this purpose well). My main point is that the "correct" model for the web is a bytecode-running VM inside every browser that lets you do everything javascript does through APIs.* Takes way too long to load the JVM. Deal-breaker for many sites.
* Horrible (AWT) and complicated (Swing) UI toolkits that ignored any look-and-feel parity with the rest of the web site or even the web browser itself.
* The environment is controlled by Oracle. I don't think they're looking to compete with JS, Flash and Silverlight. Thus web applets (except for niche internal apps) are dead, RIP.
It's called the desktop and offers all the native and low-level stuff you can possibly imagine.
And the only people that want to see it, are the ones who have forgotten about it.
Maybe there is a middle ground between desktop software and browsers, but personally I'd like to keep them apart.
Actually, I'd say it's called 'mobile'; The desktop failed to solve the sandboxing problem.
> And the only people that want to see it, are the ones who have forgotten about it.
As a desktop-turned-mobile developer, I haven't forgotten anything.
Simply put, I want a future in which we aren't forced to re-implement our applications multiple times for disparate, proprietary mobile platforms.
I already lived through that on the desktop. The only reason I haven't embraced the web for application development is that the technology stack is, by comparison, hobbled.
> Maybe there is a middle ground between desktop software and browsers, but personally I'd like to keep them apart.
Treating the browser as the sacrosanct temple of HTML, CSS, and JavaScript is throwing away the limited opportunity browsers have to pre-empt Android and iOS as a first-class, standardized application platform.
1. The function of the desktop, the browser, and the mobile is not the same thing.
2. Desktops have not failed, as you claim, in sandboxing/security/virtualization; (especially when compared to browsers).
3. Turning the browser into the desktop (low level APIs), is in turn re-implementation of the desktop.
It wouldn't suck.
It seems that the plan for Qt 5 is to move the enitre Qt toolkit over to the "QML first" model - that is, QML becomes the default way to create interfaces, for both mobile and desktop apps, and native widgets are only used when you require them. They also want to better integrate webkit and web content. In a recent Qt desktop app of mine, I was already doing this: QML + webkit + native backend for the heavy lifting and it works very well. Be awesome to have it as the default in all environments.
FWIW, I think QML/JS would have made a greate HTML/CSS/JS alternative.
The HTML/CSS/JS dev model is fine as it is, there's no need to hope for nirvana grass-is-greener frameworks that don't exist. Learn HTML5 like the rest of us.
Web apps more or less solve all these problems (code can't be completely browser-agnostic, but it's close). Why not add also the benefits of desktop apps?
However, with more high-level code, in general there shouldn't be such a need. For example, RPython is very high-level, but is compiled into very efficient C. The same could be done for JavaScript (and to some degree already is).
The part I don't understand is, what environment does the Kernel need to think is there, and how is that done in JS?
- Loads the linux binary and the root memory disk image into 'memory' at the expected addresses (0x100000 and 0x400000, respectively)
- Sets the interpreted x86 CPU's EIP to the kernel's entry point
- Initializes additional requisite register state
- Starts execution.
Take a look at load_binary() and start() functions.
[edit] rickard already discussed this here: http://news.ycombinator.com/item?id=2555552
He is really impressive...
He is presumably working for a good company (or at least one that is good for him) and has time management skills himself.
That, and a brain to be envious of plus a supply of inspiration!
Seriously, who does Bellard work for?
He seems to leave virtually no trace (other than awesome software) on the Internet. I googled the shit out of him tonite...
Probably because he spends his time writing awesome software.
OTCC is an Obfuscated Tiny C Compiler for i386-linux. It generates FAST! i386 32 bit code (no bytecode) and it is powerful enough to compile itself. OTCC supports a strict subset of C. This subset is compilable by a standard ANSI C compiler. OTCC compiles, assembles, links and runs C code without the need of any other program.
http://www0.us.ioccc.org/2001/bellard.hint
(Note for those not familiar with the IOCCC: This is done in 2048 bytes)
I am always fond of such an analogy: in terms of efficiency, the greatest hackers has an algorithmic complexity of O(1); meanwhile, the majority of us may be O(n), if you can manage to get a O(log n) you can make into the club of good hackers. The tools, be it OS, programming languages, etc, are only a constant coefficient to that complexity, i.e., they can make you noticeably more efficient, but they won't improve your "greatness".
Indeed he also wrote QEMU.
Searching for "IOCC" returns nothing, and "IOCC Fabrice" returns a site that is caching HN in realtime, and it's your post.
Any help?
Welcome to JS/Linux
~ # emacs test.c
~ # cat test.c
void main(void) {
printf("Hello World!\n");
}
~ # tcc test.c -o hello
~ # ./hello
Hello World!
[Edit: just realized that there is already a 'hello.c' in the directory that shows just this with better diction.] ~ # f(){ f|f & };f
sh: can't fork
sh: can't fork
sh: can't fork
sh: can't fork
...My first encounter with his code was QEmu, when it was required to run the XO OLPC linux images. Society truly benefits when people like him are devoted in support of open source software.
I see so many use cases for this, but I don't fully understand what is going on behind the scenes. Maybe someone can shed some light on it:
1) How is the disk emulated. Is it a local image, or is it running on the backend?
2) Is there a remote possibility to get the networking up and running?
3) Can the disk image be externally accessed to be customized?2): See another thread here.
3): Check out cpux86.js. In the start() function at the very end, the following section might be enlighting (even though it is a bit obfuscated by a javascript compressor):
function start() {
[...]
If=32*1024*1024;
ya.phys_mem_resize(If);
ya.load_binary("vmlinux26.bin",0x00100000);
Jf=ya.load_binary("root.bin",0x00400000);
start=0x10000;
ya.load_binary("linuxstart.bin",start);
ya.eip=start;
The files vmlinux26.bin, root.bin and linuxstart.bin are fetched from the server.Nitpicking: the terminal emulation is messed up. It keeps resizing horizontally, and less gets confused. I'm sure the terminal emulator was fun to play with. A correct vt100 state machine implementation [1] would probably not be quite as fun [2]. There's a vt100.js library used by a couple projects that might improve things. [3]
[1] http://vt100.net/emu/dec_ansi_parser
When he adds X, we can run Firefox inside Linux inside Firefox inside Linux :')
Edit: seems the terminal emulator supports ANSI escape codes such as the 16 Linux colors, but not the XTerm 256 color mode (\e[38;5;CCm) or Konsole 24 bit (\e[38;2;RR;GG;BBm). Guess it could be easily added as it's HTML.
Skip the middle man, output gtk via html5 http://blogs.gnome.org/alexl/2011/03/15/gtk-html-backend-upd... (I don't actually know if it still has dependencies on X11 :P)
~ # ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 BHowever, wget is there, so all the building blocks are in place.
Reddit has a meme for that. ;) (downvote away, I've earned it!)
"I don't always write Linux Kernels"
"But when I do, it's in browser hosted Javascript"
wget is available, and it would be cool to piggy back the linux network stack through the browser.
cut & paste support is a must for any terminal
The space characters are very narrow. Needs to be monospace.
All fairly minor compared to the coolness of this.
Also this new code is not released under a free license, so by default as far he is not sure what he's going to do with the code the "open source way" is not the default. This is not a critique. I think Fabrice Bellard is a genius, but as an observer he seems interested in making a profit from his work like many other programmers.
Instead subjectively I've to admit today I no longer consider the GPL a completely free license, but this is another matter and may be related not to earning but to the meaning "free software" has for you. For me it is as simple as letting people to do everything with your code. IMHO the BSD license turns out to be better both for users AND for you to earn from your product later.
Monetizing OSS is hard and a lot of the time the possible revenue streams are a time-suck. He may not be interested in spending his own time and prefer just instead to licence his work as-is the norm for software producers.
From all I've read he's more than happy to receive invitations for licensing of his work, whether or not he'd accept a lump sum to Open Source some of his work is not known. Anyway this is all speculation, if you're genuinely curious you should email him (which is active as I received a reply from him today :)
He has remained independent doesn't work for academia or any mega-tech corp and continues to pursue his own interests. I think he has every right to carve out his own path and produce software as he sees fit.
Linux (none) 2.6.20 #3 Sat May 14 19:08:30 CEST 2011 i586 GNU/Linux
Last-Modified: Mon, 16 May 2011 21:14:50 GMT
"The browser as the operating."
Someone must buzzword the hell out of this and then create a new startup based on it.
~ # ./hello
Hello World
That is just too impressive for me to process.
# cat /proc/cpuinfo
...
f00f bug: yes
#
Hah!
20 bogomips by the way, at least on Chrome on a MacBook Pro.
I sense a whole new era of browser performance testing..
[... and] my unfinished but usable emacs clone QEmacs.
?!? I am wasting my life in comparison to this super-hacker.
Unfortunately, M-x spook does not, so he clearly still has some work to do for feature completeness.
I'd be curious to know if this is was intentional, or a side-effect of the emulation.
long main = 0xc8c70ff0;
That used to crash my old Pentium box.
int main (int argc, char **argv)
{
int f = open("/dev/android_accelerometer");
double ax = f.read();
double ay = f.read();
double az = f.read();
printf ("Current 3d acceleration: %d %d %d", ax, ay, az);
return 0;
} ~ # cat over.c
main () {
int i = 0x00ffffff;
while (i > 0) i--;
}
~ # tcc over.c -o out
~ # time ./out
real 0m 13.58s
user 0m 13.57s
sys 0m 0.01s
I love this stuff.Easily the best hack I've seen on HN.
Hmm if network emulation was added to the javascript VM you could combine it with this.
Loopback (which is present) is so much simpler.
Edit: Easier idea might be adding ttyS1 and connecting that to a websocket on the server. Combined with something like socat or ppp, that ought to work. Since the console is already ttyS0 and connected to the js terminal, it might be doable even with the obfuscated source.
#from a 2.6.38.6 vanilla tree
wget http://bellard.org/jslinux/config_linux-2.6.20 -O .config
yes "" | make oldconfig
# small edit in drivers/tty/serial/8250.c to copy Bellard's patch (http://bellard.org/jslinux/patch_linux-2.6.20)
make vmlinux
cp arch/x86/boot/vmlinux.bin /path/to/copy/of/jslinux/hosted/with/a/simple/httpd/
Edit: I just tried again with a 2.6.20.21 kernel using more or less the procedure showed above: it works! So it must be something with more recent kernels (scheduler ? dynticks ? merging of i386 and x86_68 arch in x86 ? something else ?) that is not emulated by jslinux. ~ # httpd
~ # telnet 127.0.0.1 80
get / http/1.0
HTTP/1.0 404 Not Found
Content-type: text/html
Date: Tue, 17 May 2011 20:10:52 GMT
Connection: close
<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD>
<BODY><H1>404 Not Found</H1>
The requested URL was not found
</BODY></HTML>
Connection closed by foreign host
~ #
Coolness!I have a bit of experience with this as a course helper in the introductory (CS106 series) CS classes at Stanford.
I think it could be a very cool platform for assignments in CS107 (where students are introduced to Unix and C programming) or CS110/CS140 (the core OS classes).
Instead of ssh-ing into a locked-down cluster computer, students could boot a machine in their browser and get root access. No setup, no configuration. Everyone gets an identical setup, which would be really nice for the people making the assignments. The main thing people would need is a way to save files to a persistent disk. Maybe a filesystem driver could be added that uses HTML5 Local Storage, or talks to a web service running on the class website?
Incidentally, students in CS140 are already using Fabrice Bellard's software. You write most of a very simple Unix kernel, testing and running it in QEMU.
# mkdir /sys; mount -t sysfs /sys /sys
That would allow you to look at the emulated hardware that is present.
Looks like only virtual devices are present -- ram, loopback network etc.Makes sense to me. The MVP here is cpu emulation.
https://chrome.google.com/webstore/detail/kkioiolcacgoihiiek...
wow!
cd /
rm -rf ./*
echo *I don't know what is the problem of the original 2.6.20 linux kernel with JS/Linux but with this new compilation work perfectly.
io scheduler cfq registered (default)
This is somewhat more direct than using Python in Linux on a JS-based emu.
/evil grin
Edit: This is damn cool.
/usr/bin has many goodies
vi, top, ps, grep, awk
well I'm sold.
I expect a response with a lot of emotion.
Josep.
reboot -f
Now if the virtual cpu does not implement that reboot behaviour, the likely result is just an endless recursion of fault handlers. So the script runs an endless loop, hanging Firefox until it notices this and stops it.
alias ll='ls -lh'That said, it's a phenomenal achievement, and should be a great way for websites to demonstrate command-line tools to people. :)
(also: browsers let you store more information with DOM Local Storage than you could in a cookie; If you could expose that to Linux as a block device...)
ERROR: your browser is too old to run JS/Linux.
You should use a recent browser such as Firefox 4.x or Google Chrome.
No, it isn't. Stop using user-agent matching and start using JavaScript feature detection instead.I downloaded a webkit nightly from here, and it works now. Also, of note, the nightly picks up all my Safari settings, so it's not too much of a pain.