是否可以通过模式切换在64位进程中执行32位代码? [英] Is it possible to execute 32-bit code in 64-bit process by doing mode-switching?

查看:75
本文介绍了是否可以通过模式切换在64位进程中执行32位代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此页面中, 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位代码要么必须是独立的,要么必须为其需要的库函数提供重排.请记住,通常不会直接调用系统调用-您通常通过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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆