[Boost-bugs] [Boost C++ Libraries] #9985: boost::atomic<double> causing program crash

Subject: [Boost-bugs] [Boost C++ Libraries] #9985: boost::atomic<double> causing program crash
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-05-01 14:23:28

#9985: boost::atomic<double> causing program crash
 Reporter: Daniel Vernon <daniel.vernon@…> | Owner: timblechmann
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: atomic
  Version: Boost 1.55.0 | Severity: Problem
 Keywords: boost atomic double crash |
 Using Visual Studio 2012 to compile the following C++ code:-

 double desiredPresentationSpeed = 1.0f;

 boost::atomic<double> m_configuredPresentationRate;

 m_configuredPresentationRate = desiredPresentationSpeed;

 return S_OK;

 The compiler outputs the following warning for a Release build:-

 ''' 76>c:\sdks\boost_1_55_0\boost\atomic\detail\windows.hpp(1598):
 warning C4731:
 'AVDecoders::CVideoDecoderHandler::ConfigurePresentationSpeed' : frame
 pointer register 'ebx' modified by inline assembly code

 And the program subsequently crashes on the third line above. This is
 because the ebx register is modified by the boost::atomic code (in this
 case at 010DE08E in the asm code below) and the program then
 crashes further down when the 'pop ebx' is executed (at 010DE0AE), because
 the esp register has been set incorrectly (on the previous line) using the
 value now in ebx.

         m_configuredPresentationRate = desiredPresentationSpeed;
 010DE064 mov eax,dword ptr [desiredPresentationSpeed]
 010DE067 mov dword ptr [ebp-10h],eax
 010DE06A mov eax,dword ptr [ebp-4]
 010DE06D mov dword ptr [ebp-0Ch],eax
 010DE070 lea eax,[ecx+1B7Ch]
 010DE076 mov dword ptr [ebp-4],eax
 010DE079 test al,7
 010DE07B jne
 010DE07D mov edx,dword ptr [ebp-4]
 010DE080 movq xmm4,mmword ptr [ebp-10h]
 010DE085 movq mmword ptr [edx],xmm4
 010DE089 jmp
 010DE08B mov edi,dword ptr [ebp-4]
 010DE08E mov ebx,dword ptr [ebp-10h]
 010DE091 mov ecx,dword ptr [ebp-0Ch]
 010DE094 mov eax,dword ptr [edi]
 010DE096 mov edx,dword ptr [edi+4]
 010DE099 lea esp,[esp]
 010DE0A0 lock cmpxchg8b qword ptr [edi]
 010DE0A4 jne

         return S_OK;
 010DE0A6 xor eax,eax
 010DE0A8 pop edi
 010DE0A9 mov esp,ebp
 010DE0AB pop ebp
 010DE0AC mov esp,ebx
 010DE0AE pop ebx
 010DE0AF ret 4

 The boost code in question can be found here, under template
 "platform_store64" :-

 This Microsoft page [http://msdn.microsoft.com/en-
 us/library/k1a8ss06(v=vs.110).aspx] states "To ensure code runs correctly,
 do not modify EBX in asm code if the function requires dynamic stack
 alignment as it could modify the frame pointer. Either move the eight-byte
 aligned types out of the function, or avoid using EBX."

 So it looks as though a simple fix would be to add a 'push ebx' and 'pop
 ebx' in the final _asm code block, to preserve the value of ebx.

Ticket URL: <https://svn.boost.org/trac/boost/ticket/9985>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC