Evil hack. Running 64 bit code in a 32 bit application.
peter at wemm.org
Wed Aug 22 18:26:22 PDT 2007
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:
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 at wemm.org; peter at FreeBSD.org; peter at yahoo-inc.com
"All of this is for nothing if we don't go to the stars" - JMS/B5
More information about the freebsd-amd64