带有__disable()和__enable()函数的C/C++代码无法在O1和Od的VS2019版本优化速度下编译



如果在Vs2019版本中Od/O1将获得以下错误:

Severity Code Description Project File Line Suppression State
error LNK2019 Unresolved external symbol _enable, referenced in function "long __cdecl ReadR3MemoryToR3ByCR3(void *,void *,unsigned __int64,void *)"
Severity Code Description Project File Line Suppression State
error LNK2019 Unresolved external symbol _disable, referenced in function "long __cdecl ReadR3MemoryToR3ByCR3(void *,void *,unsigned __int64,void *)"
void foo()
{
_disable();
__writecr3(targetCR3);
if (!MmIsAddressValid(readAddr))
{
__writecr3(currentCR3);
_enable();
KeLeaveCriticalRegion();
ExFreePoolWithTag(tempBuffer, 'buFF');
status = STATUS_INVALID_PARAMETER_2;
break;
}
memcpy(tempBuffer, readAddr, readSize);
__writecr3(currentCR3);
_enable();
}

但在vs2019下,调试和02版不会出现这种情况。

问题:为什么这个

__disable()__enalbe()是内联函数,需要在vs2019的项目配置中打开

属性->C/C++->优化->启用内联函数。

Release下的O1和Od优化没有启用此函数,因此编译失败。

参考链接:https://learn.microsoft.com/en-gb/cpp/intrinsics/compiler-intrinsics?view=msvc-170

相关内容

  • 没有找到相关文章

最新更新