c++ - 无法在 GCC 的 VC++ 版本中获得预期结果
问题描述
我需要将用 gcc 编写的 vm 检测代码转换为 vc++
这是代码
static inline unsigned long long rdtsc_diff_vmexit() {
unsigned long long ret, ret2;
unsigned eax, edx;
__asm__ volatile("rdtsc" : "=a" (eax), "=d" (edx));
ret = ((unsigned long long)eax) | (((unsigned long long)edx) << 32);
/* vm exit forced here. it uses: eax = 0; cpuid; */
__asm__ volatile("cpuid" : /* no output */ : "a"(0x00));
/**/
__asm__ volatile("rdtsc" : "=a" (eax), "=d" (edx));
ret2 = ((unsigned long long)eax) | (((unsigned long long)edx) << 32);
return ret2 - ret;}
我找到了一些在 vc++ 中执行相同操作的示例,如下所示
BOOL rdtsc_diff_vmexit(){
ULONGLONG tsc1 = 0;
ULONGLONG tsc2 = 0;
ULONGLONG avg = 0;
INT cpuInfo[4] = {};
// Try this 10 times in case of small fluctuations
for (INT i = 0; i < 10; i++)
{
tsc1 = __rdtsc();
__cpuid(cpuInfo, 0);
tsc2 = __rdtsc();
// Get the delta of the two RDTSC
avg += (tsc2 - tsc1);
}
// We repeated the process 10 times so we make sure our check is as much reliable as we can
avg = avg / 10;
return (avg < 1000 && avg > 0) ? FALSE : TRUE;}
但问题是如果在虚拟框中运行 GCC 版本返回 true,而 vc++ 返回 false,请告诉我有什么问题。想知道 gcc asm 代码是否可以为 VC++ 重写?
解决方案
推荐阅读
- angular - 是否可以通过 url 从 angular 获取页面 html 内容
- windows - Windows shell 将项目添加到受保护的文件夹 {2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}
- jira - 您如何在 JQL 中的“Assigned PO”字段中进行搜索?
- python - 如何在 Python 中解析 XML 并将信息存储在字典中
- bash - 移动文件特定文件夹
- c# - 如何将日志记录添加到 Blazor 服务器端组件?
- ios - Route 53 路由策略和 IOS 应用程序
- python - 如何在python中漂亮地打印四叉树?
- latex - 如何改进乳胶表
- python - 在 pip/conda install numpy 之后没有名为“numpy”的模块