Date: Wed, 22 Aug 2007 18:08:27 -0700 From: Peter Wemm <peter@wemm.org> To: amd64@freebsd.org Subject: Evil hack. Running 64 bit code in a 32 bit application. Proof-of-concept. Message-ID: <200708221808.28272.peter@wemm.org>
next in thread | raw e-mail | index | archive | help
We have a problem at work. Old apps that we run on amd64 boxes. For various reasons, a recompile usually isn't an option. (don't ask) One question that keeps coming up, is "Can we somehow use large mmap areas and keep the rest unchanged?" Well, the answer is yes. On the FreeBSD/amd64 kernel, we expose both 32 bit and 64 bit %cs segment descriptors to applications. We context switch all 64 bits of registers, even on 32 bit apps. Even signals seem to be workable. (%cs is reloaded for 32 bit mode on 32 bit apps). The proof of concept code is here: http://people.freebsd.org/~peter/emm64/ It is cheap and nasty, but does a simple 64 bit operation in a 32 bit app. Most of the difficulty is convincing binutils to not have a heart attack while linking it. The second part of the puzzle is a kernel module to allow mmaping above the 4GB boundary. Then we can do an API to access the high memory data, just a glorified 64 bit memcpy to/from 32 bit space. We have a bunch of code at work that does this via socket/pipe rpc to an external 64 bit proxy process. Being able to directly mmap saves context switches and has less IPC overhead. Anyway, it is there FYI, and for your amusement. I'll be doing something more realistic with it at work over the next few days. -- Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com "All of this is for nothing if we don't go to the stars" - JMS/B5
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708221808.28272.peter>