<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>FreiK's WebLog : Bugs</title><link>http://blogs.msdn.com/freik/archive/tags/Bugs/default.aspx</link><description>Tags: Bugs</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How to use RtlUnwindEx</title><link>http://blogs.msdn.com/freik/archive/2007/03/15/how-to-use-rtlunwindex.aspx</link><pubDate>Thu, 15 Mar 2007 18:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1887999</guid><dc:creator>Kevin Frei</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/freik/comments/1887999.aspx</comments><wfw:commentRss>http://blogs.msdn.com/freik/commentrss.aspx?PostID=1887999</wfw:commentRss><wfw:comment>http://blogs.msdn.com/freik/rsscomments.aspx?PostID=1887999</wfw:comment><description>&lt;P&gt;Disclaimer:&amp;nbsp; I've never actually written an unwind personality routine, so take what's here with a grain of salt.&lt;/P&gt;
&lt;P&gt;A few days back, I spent 30 minutes defending the C++ runtime's exception handling personality routine to the guy that has the less than enviable job of supporting the .Net Framework's exception handling personality routine.&amp;nbsp; The eventual point to be learned is that the documentation for RtlUnwindEx is abysmal, and can cause the VC 8.0 C++ runtime to leak objects left and right.&lt;/P&gt;
&lt;P&gt;The problem revolves around the C++ team's decision (which I fully support) to cause code compiled with /EHs or /EHsc flags to only invoke destructors when a C++ exception occurs.&amp;nbsp; This means that if you take a hardware exception, call RaiseException yourself, or call&amp;nbsp;longjmp&amp;nbsp;none of your C++ destructors between the point of exception and the handler will be invoked. I've talked about why this is a good idea, but I'll sum it up with this:&amp;nbsp; If that scenario seems bad to you, then you should be compiling your code with /EHa.&lt;/P&gt;
&lt;P&gt;Anyway, back to the issue:&amp;nbsp; Say I'm writing a 'personality routine' which will be inovked by the OS when an exception occurs.&amp;nbsp; If you're writing the kind that requires that your handler initiates the second phase of unwind, you need to call RtlUnwindEx.&amp;nbsp; The documentation, which is arguably&amp;nbsp;bad (it's little more that a function declaration), indicates that the EXCEPTION_RECORD structure to pass in is &lt;EM&gt;optional&lt;/EM&gt;.&amp;nbsp; And that's true:&amp;nbsp; the functions on the stack will still be unwound.&amp;nbsp; But the personality routines for those functions might want to actually know that they're being invoked due to an exception, and not for something like a longjmp.&amp;nbsp; So, if you have an exception record that &lt;EM&gt;could &lt;/EM&gt;be passed to the RtlUnwindEx function, you &lt;EM&gt;should&lt;/EM&gt;.&amp;nbsp; If you don't, another personality routine might assume that there's not an exception to examine, and might decide to do something like NOT invoke the destructors for the object on the stack.&lt;/P&gt;
&lt;P&gt;BTW - this bug exists only on x86, and only when you're crossing a managed code -&amp;gt; native code boundary, in particularly weird scenarios.&amp;nbsp; And I hope it's getting fixed :-)&lt;/P&gt;
&lt;P mce_keep="true"&gt;-Kev&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1887999" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/freik/archive/tags/Developer+Info/default.aspx">Developer Info</category><category domain="http://blogs.msdn.com/freik/archive/tags/Bugs/default.aspx">Bugs</category></item><item><title>Bug in x86 inline assembly to watch out for</title><link>http://blogs.msdn.com/freik/archive/2006/10/17/bug-in-x86-inline-assembly-to-watch-out-for.aspx</link><pubDate>Tue, 17 Oct 2006 23:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:836118</guid><dc:creator>Kevin Frei</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/freik/comments/836118.aspx</comments><wfw:commentRss>http://blogs.msdn.com/freik/commentrss.aspx?PostID=836118</wfw:commentRss><wfw:comment>http://blogs.msdn.com/freik/rsscomments.aspx?PostID=836118</wfw:comment><description>&lt;P&gt;Imagine this very lame code:&lt;/P&gt;&lt;PRE&gt;int main() {}

void BugAsm() 
{
   __asm {
        MOV     [ESP+12],OFFSET main
   }
}

void(*BugAsmPt)()=&amp;amp;BugAsm; // this is just to make sure the function is not removed by /OPT:REF

&lt;/PRE&gt;
&lt;P&gt;Now imagine your significantly less lame code doing something similar.&lt;BR&gt;Now imagine that the compiler crashes with a bizzare message about "x86\code.c" something or other.&lt;/P&gt;
&lt;P&gt;Well, you can fix this problem by changing the assembly code to this:&lt;/P&gt;
&lt;P&gt;mov DWORD PTR[esp+12], OFFSET main&lt;/P&gt;
&lt;P&gt;Another unfixed bug, worked around :-|&lt;/P&gt;
&lt;P&gt;-Kev&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=836118" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/freik/archive/tags/Bugs/default.aspx">Bugs</category></item><item><title>ML64 bug to watch out for</title><link>http://blogs.msdn.com/freik/archive/2006/07/20/673120.aspx</link><pubDate>Thu, 20 Jul 2006 23:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:673120</guid><dc:creator>Kevin Frei</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/freik/comments/673120.aspx</comments><wfw:commentRss>http://blogs.msdn.com/freik/commentrss.aspx?PostID=673120</wfw:commentRss><wfw:comment>http://blogs.msdn.com/freik/rsscomments.aspx?PostID=673120</wfw:comment><description>If you're porting your application to x64, and you use much in the way of __asm in your x86 code, you're likely to start looking at ml64 - the 64 bit version of Masm.&amp;nbsp; The reason you're likely to do this is that the x64 compiler doesn't support __asm blocks in C code.&amp;nbsp; So you can either use the compiler intrinsic functions [and there are a lot of 'em, and they're all documented relatively well], or you have to use ml64.&amp;nbsp; For folks that aren't new to Masm, you're also likely to try to use some of the nifty little time-saver features of Masm to automatically generate prologue's and epilogues for your functions.&amp;nbsp; For ML64, DO NOT DO THIS!&lt;br&gt;Here's an example:&lt;br&gt;&lt;font face="Courier New"&gt;.DATA&lt;br&gt;.CODE&lt;br&gt;testfunc PROC uses rbx&lt;br&gt;xor rbx, rbx&lt;br&gt;ret&lt;br&gt;testfunc ENDP&lt;br&gt;END&lt;br&gt;&lt;font face="Times New Roman"&gt;There are 2 problems with the code that ML64 generates.&amp;nbsp; #1:&amp;nbsp; There is no .xdata of any sort.&amp;nbsp; No unwind directives are emitted, despite the fact that you're allocating stack, and saving a nonvolatile register.&amp;nbsp; #2:&amp;nbsp; The epilogue is invalid - it uses the 'leave' instruction, which is ineffecient, but also just plain illegal in an x64 function epilogue.&amp;nbsp; The stack unwind routines will not properly recognize the instruction sequence as an epilogue, so the debugger and the EH routines will all fail [the EH routines will just terminate your process if an exception occurs while testfunc is on the stack].&lt;br&gt;&lt;br&gt;BTW - Here's the &lt;a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101239"&gt;link&lt;/a&gt; to the customer bug.&amp;nbsp; It came in about 3 months too soon for serious consideration for VC8, so we punted it to the next version, but now it's pushed out until we get some more resources for investment in MASM.&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=673120" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/freik/archive/tags/Bugs/default.aspx">Bugs</category></item></channel></rss>