Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to execute 32-bit code in 64-bit process by doing mode-switching?

In this page, http://www.x86-64.org/pipermail/discuss/2004-August/005020.html He said that there is a way to mix 32-bit code and 64-bit code in a application. He assumed the application is 32-bit (in compatibility mode) and then switch to 64-bit mode to execute 64-bit code and vice versa.

Assume my OS is 64-bit linux and my application is 64-bit. I do a far jump to switch to compatibility mode and execute 32-bit code. Does it can work correctly when I do a system call or function call ?

Is there any overhead of mode switching between compatibility mode and 64-bit mode ? I think one of the overhead is I need separate stack for 32-bit and 64-bit.

Could I integrate this idea into JVM, maybe I can dynamic generate 32-bit code in 64-bit JVM, and execute it by mode switching ?

like image 337
Hsiao-Hui Chiu Avatar asked Feb 22 '11 16:02

Hsiao-Hui Chiu


1 Answers

Open-coded syscalls should be fine, since your 32-bit code will use the 32-bit kernel entry point.

Function calls can only be made to other 32-bit code, of course. This includes libc - so your 32-bit code will either have to be self-contained, or you will have to provide thunks for the library functions that it needs. Remember that usually syscalls are not called directly - you normally go via a libc wrapper that will be unavailable to your 32-bit code.

There is certainly an overhead for switching between modes. You should consult your processor documentation to find out what it is.

like image 112
caf Avatar answered Sep 21 '22 05:09

caf