updated 23rd July 2004 @ 17:42 EDT
Call me crazy, but I've wanted to run a linux binary natively under windows for a while now; kinda like wine, but in reverse.
Well, the other day I was browsing through the MSDN docs (as you do) and discovered that it is possible to install a "vectored" exception handler. A quick bit of test code later, and I discovered that I can trap "int 0x80" instructions using this technique--those are used by linux binaries to initiate syscalls.
A couple of days hacking later, and I have a very small linux kernel emulation environment; it's split into two parts--low.dll (the kernel code) and low.exe (the bootstrap). The usage is quite simple; from your command prompt, run the linux binary of choice by prefixing the command line with "low.exe":
low.exe linuxsmallapp one two three four
The code from the named linux binary is loaded (low.dll includes an ELF loader) and bootstraps the process by faking an execve() syscall. When the syscall returns, the code resumes execution inside the loaded module. The code is running natively on your processor; and syscalls happen in userspace (just like the binary) although they run under a separate stack inside the win32 exception handler code. So, this is almost like kernel space.
What I have now is good enough to run my simple hello world application. It doesn't yet handle dynamic elf executables--they need to be statically linked. Thanks to Tal Peer, I have a collection of statically compiled coreutils from gentoo; they start up fine, but die somewhere in the stdio part of libc. I'm trying to track down the problem.
If anyone has any insight into why this might be (maybe windows is doing stuff for software interrupt number 128? before it calls my exception handler?), I'd like to hear it :-)
[Update] If you're interested in playing with it, please don't expect to acheive much at this stage. You can download it here.
Pretty cool thing! Really! Would like to test some stuff with that, if you got something to view!
Btw, the RSS feed of your blog seems broken. It contains broken archive links:
http://zlog.thebrainroom.netarchives/22_Linux_on_windows.html
That should be only a problem in S9Y configuration, IMHO. Check your Website-Variable!
Regards, Toby
Yeah, it's kinda neat, although annoying that any real binary I try segfaults. When I get a bit of time over the next couple of days, I'll put up a little download of this for people to test.
RSS should be fixed now; thanks.
Wez Furlong [1] started reading through some documents at MSDN and finally ended up with a small Linux kernel emulator for Windows. Amazing story ;-) [1] http://zlog.thebrainroom.net/archives/22_Linux_on_windows.html
looks like an interesting project.. i'll take a look at it as as soon as there is time: linux on windows (via circle.ch)...
Just came across http://www.colinux.org/.
looks like an interesting project.. i'll take a look at it as as soon as there is time: linux on windows (via circle.ch) [update 20030126: there seem to exist other, similar projects: colinux (german introduction by symlink), umlwin32 ]...
Try Bosch. Emulates a PC. Even boots! Ussually used to try another OS on top of an already running OS. E.g. You can install and run linux on on Bosch running in a Windows environment.
ERRATA Should be bochs not bosch. Sorry. Aside from bochs and colinux ( above) there's, WinLinux, Cygwin( ? correct spelling?), Lnx4Win.
John
I know this might be controversial to post here, but I run various Operating systems in Virtual PC 2004 - and I'm just so happy with it. I almost forget the host operating system is Windows ;)
You might want to have a look at Line :
http://line.sourceforge.net/
LINE Is Not an Emulator
LINE executes unmodified Linux applications on Windows by intercepting Linux system calls. The Linux applications themselves are not emulated. They run directly on the CPU just like all other Windows applications.
Yeah, I found line a couple of weeks ago; the architecture is similar, but has a critical flaw (IMO)-line runs on top of cygwin, which I find a little too slow, and was one of the reasons I started dabbling in this area.
it must be hard to provide all the APIs that exist on Linux (for Windows). Won't this just turn into one of those giant projects that will get to 30%, but then be impossible to finish (in commercial quality)?
linux on windows .. this i gotta see. what will the think of next :)
Leggo due post di Wez Furlong, stasera. Il primo, che racconta del progetto controcorrente di Wez "Linux on windows", è del 19 marzo. Il secondo, di 5 giorni prima, re
I am just wondering, because, I thought this was how cygwin did its stuff...
the problem is with the drivers. Cygwin only provides some library functions
First off, really cool idea. Second, check out http://www.packetstormsecurity.org/groups/teso/reducebind.c which converts a dynamic binary to a static one.
