x86应用程序如何检测到它正在以AMD64兼容模式运行? [英] How can an x86 application detect that it's running in AMD64 compatibility mode?
问题描述
通常,在不使用特定于操作系统的方法的情况下,x86应用程序如何才能检测到它正在以AMD64兼容模式而不是传统模式运行?
我知道我可以通过执行 smsw eax
或类似的非特权指令(用于检查是否为例如分页/缓存/...来获得用户空间中的 cr0
.),但在阅读了英特尔系统编程指南的9.8.5 初始化IA-32e模式后,我了解到这几乎没有用,因为通过 IA32_EFER启用了IA-32e模式
MSR,这是第3环代码无法访问的.那么,仍然有任何方法可以可靠地区分传统模式和兼容模式吗?
此 Intel的手册说SYSCALL将: 尽管这仅在您的操作系统首先支持使用32位代码中的SYSCALL的情况下有效.32位代码通常必须使用 根据维基百科(该超级用户帖子的出处),显然AMD64 CPU无法以这种方式工作,只有Intel EMT64 . https://en.wikipedia.org/wiki/X86-64#Recent_implementations没有提及其他有用的东西. In general, without using OS-specific methods, how can an x86 application detect that it's running in AMD64 compatibility mode instead of legacy mode? I know I can get This Superuser post points out that on Intel implementations, SYSCALL is supported in legacy mode, but not compatibility mode. This is technically OS specific, but you're not asking the OS for the answer, like just calling Intel's manual says SYSCALL will: Although this only works if you OS supports using SYSCALL from 32bit code in the first place. 32bit code normally has to use Apparently AMD64 CPUs don't work this way, only Intel EMT64, according to wikipedia (the source for that superuser post). https://en.wikipedia.org/wiki/X86-64#Recent_implementations doesn't mention anything else useful. 这篇关于x86应用程序如何检测到它正在以AMD64兼容模式运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! #UD如果IA32_EFER.SCE = 0.
int 80h
.不过,64位代码通常确实使用SYSCALL.cr0
in user space by just doing smsw eax
or similar non-privileged instruction (useful to check whether e.g. paging/cache/... is enabled), but after reading Intel's System Programming Guide section 9.8.5 Initializing IA-32e Mode, I learned that this is hardly useful, because IA-32e mode is enabled via IA32_EFER
MSR, which is inaccessible to ring 3 code. So is there still any way to reliably discriminate between legacy and compatibility modes?uname(2)
and looking at buf->machine
. If you know a "normal" system call, like gettimeofday or getpid, you can try it with this.#UD If IA32_EFER.SCE = 0.
int 80h
. 64bit code normally does use SYSCALL, though.