是否可以通过模式切换在 64 位进程中执行 32 位代码? [英] Is it possible to execute 32-bit code in 64-bit process by doing mode-switching?
问题描述
在此页面中,http://www.x86-64.org/pipermail/discuss/2004-August/005020.html他说有一种方法可以在应用程序中混合 32 位代码和 64 位代码.他假设应用程序是 32 位(在兼容模式下),然后切换到 64 位模式以执行 64 位代码,反之亦然.
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.
假设我的操作系统是 64 位 linux,我的应用程序是 64 位.我做了一个远跳转以切换到兼容模式并执行 32 位代码.当我进行系统调用或函数调用时它是否可以正常工作?
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 ?
在兼容模式和 64 位模式之间进行模式切换是否有任何开销?我认为开销之一是我需要为 32 位和 64 位单独的堆栈.
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.
能不能把这个想法整合到JVM中,也许我可以在64位JVM中动态生成32位代码,并通过模式切换来执行?
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 ?
推荐答案
开放编码的系统调用应该没问题,因为您的 32 位代码将使用 32 位内核入口点.
Open-coded syscalls should be fine, since your 32-bit code will use the 32-bit kernel entry point.
当然,只能对其他 32 位代码进行函数调用.这包括 libc
- 所以你的 32 位代码要么必须是自包含的,要么你必须为它需要的库函数提供 thunk.请记住,系统调用通常不会直接调用 - 您通常通过 libc
包装器进行调用,该包装器对您的 32 位代码不可用.
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.
这篇关于是否可以通过模式切换在 64 位进程中执行 32 位代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!