CPUID操作码指令返回的值正在更改。简单地说,,我怎样才能让瓦兰尊重实际的CPUID指令?
作为参考,当在一台我知道没有aes-ni指令集的旧计算机上检测到aes-ni支持时,发现了一些奇怪的错误。然而,这种行为显然正在改变多个值。
使用以下C代码,可以在valgrind-3.10.1中观察到这种行为:
#include <stdio.h>
int main() {
unsigned eax, ebx, ecx, edx;
eax = 1;
__asm__ volatile("cpuid"
: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
: "0" (eax), "2" (ecx)
);
if(ecx & (1<<25)) {
printf("aes-ni enabled (ecx=%08x)n", ecx);
} else {
printf("no aes-ni support (ecx=%08x)\n", ecx);
}
return 1;
}它以这样的方式编译和运行:
$ gcc -o test test.c
$ ./test
no aes-ni support (ecx=0098e3fd)
$ valgrind ./test
==25361== Memcheck, a memory error detector
==25361== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==25361== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==25361== Command: ./test
==25361==
aes-ni enabled (ecx=0298e3ff)
==25361==
==25361== HEAP SUMMARY:
==25361== in use at exit: 0 bytes in 0 blocks
==25361== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==25361==
==25361== All heap blocks were freed -- no leaks are possible
==25361==
==25361== For counts of detected and suppressed errors, rerun with: -v
==25361== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)请注意,相同的二进制文件通常返回0098e3fd,但是0298e3ff在val差下返回,这是错误的!
发布于 2018-02-11 20:52:01
在没有答案的几天后,瓦兰公司似乎无法允许正确的CPUID响应。
因为从本质上说,Valgrind是在虚拟环境中运行的,所以它将响应它所知道的虚拟处理器的CPUID信息,而不是系统的处理器。
由于@Joe的一条评论,下面的链接显示了关于这个问题的对话,可以追溯到2014年:https://sourceforge.net/p/valgrind/mailman/message/31960632/
简单地说,瓦伦公司可以选择将CPUID标志设置为运行时标志(如链接线程中所建议的那样),但到目前为止(2018年2月)还没有这样的标志。
https://stackoverflow.com/questions/48697579
复制相似问题