[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Calling x86 code from 64-bit code

Xavier Roche <rocheml@httrack.com> writes:

> [Reposting - the news gateway seems to be read-only]
> Hi folks,
> I am not sure this issue has been discussed before: is it possible - and
> how - to call 32-bit x86 native code from a 64-bit function ?
> Some folks could have the need to link (mostyl proprietary) 32-bit code
> on opteron systems, from 64-bit bytecode.
> I imagine that function prototypes will have to be compatible, but the
> most annoying problem will be link and pointers.
> ldd accepts to link x86 and x86-64 bytecode with a warning ; but I'm not
> sure this is really sane (and of course the code is not valid after
> link) - how to handle this?
> Is there a way to create 32-bit compatible address space inside 64-bit
> code? (shared memory ?)
> Something like:
> typedef uint32 ptr32;
> extern ptr32 bar(ptr32 address, int32 foobar);
> ptr32 addr32 = FooAllocate(sizeof(myStructure));
> void* addr64 = FooGet64Ptr(addr32);
> .. do something inside addr64
> ptr32 result = bar(addr32, 42);
> void* result64 = FooCopyFrom32bitAddrSpace(result32);
> .. do something with result64
> Any thoughts?

The easiest would be to allocate the program completly in the 32 bit
address space. Converting pointers is then just a matter of extending
them. Actually using 32 bit code and the full 64bit address space
would be rather complex and you would have to copy data around a lot.

The reverse idea has come up already, to compile libraries for 64bit
but with the ia32 interface. If you find something usable for the
problem let us know.


Reply to: