gpt4 book ai didi

visual-c++ - 读指令上的写访问冲突

转载 作者:行者123 更新时间:2023-12-03 17:23:17 27 4
gpt4 key购买 nike

我们在我们的产品中使用 SQLite 库,突然在使用不同的编译器版本(Visual C++)重新编译后,它开始在客户计算机上崩溃。

崩溃是

ExceptionAddress: 0710eadd (sqlite3!sqlite3_transfer_bindings+0x0004e5bd)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 00000001
Parameter[1]: 07148688
Attempt to write to address 07148688

导致崩溃的代码如下(sqlite3MutexInit 的一部分):
0710ead0 b804811407      mov     eax, 0x07148104
0710ead5 b97c861407 mov ecx, 0x0714867c
0710eada 0f44c8 cmove ecx, eax
0710eadd f30f7e410c movq xmm0, mmword ptr [ecx+0Ch]

对应的C代码:
if( sqlite3GlobalConfig.bCoreMutex ){
pFrom = sqlite3DefaultMutex();
}else{
pFrom = sqlite3NoopMutex();
}
memcpy(pTo, pFrom, offsetof(sqlite3_mutex_methods, xMutexAlloc));

它不是特别重要,但在我们的例子中 sqlite3GlobalConfig.bCoreMutex 设置为 1。

问题在于,在这种特殊情况下,地址 07148688 处的内存是可读的,并且指令应该读取它,而不是写入它。

我们有两台机器的内存转储,在这两种情况下都发生在 Athlon XP 处理器上(系列/型号/步进:6/10/0、6/8/1)。

使用多个 Visual C++ 版本(2012、2013 和 2013 Update 1)重新编译会产生略微不同的代码(错误地址处的 movq 与 movdqu 指令),但崩溃始终发生。

这可能是由我们遇到的处理器或编译器错误引起的吗?

最佳答案

较旧的 AMD Athlon(和 Pentium III)处理器显然不支持这种形式的 movq,它是随 SSE2 指令引入的。我在 GCC discussion 中引用了 Anders Carlsson :

Looking at the Intel reference documentation available from ftp://download.intel.com/design/Pentium4/manuals/25366614.pdf MOVQ has the following opcodes:

0F 6F /r MOVQ mm, mm/m64      Move quadword from mm/m64 to mm. 
0F 7F /r MOVQ mm/m64, mm Move quadword from mm to mm/m64.
F3 0F 7E MOVQ xmm1, xmm2/m64 Move quadword from xmm2/mem64 to xmm1.
66 0F D6 MOVQ xmm2/m64, xmm1 Move quadword from xmm1 to xmm2/mem64.

and since the two latter instructions are unsupported on AMD and Pentium III you would need some other way to move data between the xmm registers and memory.



不再提供英特尔引用文档; movq 指令的另一个引用是 http://x86.renejeschke.de/html/file_module_x86_id_201.html .不过,我没有 AMD Athlon XP 来测试它。

关闭 SSE2 优化应该可以解决问题。 SSE2指令集在VS2012及以后是默认的,/arch编译器标志控制使用哪个指令集;见 http://msdn.microsoft.com/en-us/library/7t5yh4fd%28v=vs.110%29.aspx .

关于visual-c++ - 读指令上的写访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21256792/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com