Author: greatlrd Date: Mon Jun 4 09:50:39 2007 New Revision: 26985
URL: http://svn.reactos.org/svn/reactos?rev=26985&view=rev Log: irc : Myrria (from linux xbox project) desc a bug in KiUserExceptionDispatcher and how to fix it.
See issue #2279 for more details.
Modified: trunk/reactos/dll/ntdll/main/i386/dispatch.S
Modified: trunk/reactos/dll/ntdll/main/i386/dispatch.S URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/main/i386/dispatc... ============================================================================== --- trunk/reactos/dll/ntdll/main/i386/dispatch.S (original) +++ trunk/reactos/dll/ntdll/main/i386/dispatch.S Mon Jun 4 09:50:39 2007 @@ -183,6 +183,30 @@ .globl _KiUserExceptionDispatcher@8 _KiUserExceptionDispatcher@8:
+ /* clear the direct flag + * text from bug 2279 + * if it not clear it means that if an exception occurs while + * the direction flag is set (typically inside memmove), the + * exception handlers will be called with the direction flag still + * set. The Windows x86-32 and x86-64 ABI requires that the + * direction flag be Calling memset() with a compile-time constant + * size on both GCC and MSVC will result in inlining a "rep stosd" + * instruction. Because of the ABI, they will assume that the + * direction flag is clear and not emit a "cld" instruction. + * Using memset() in an exception handler therefore will + * corrupt memory if the exception occurred during a reverse copy + * such as a forward overlapping memmove(). + * + * For reliability and ease of debugging, please add "cld" to the beginning of + * KiUserExceptionDispatcher. Note that the same will be true of x86-64 whenever + * that happens. This does not affect continuing execution; the CONTEXT of the + * exception has the direction flag set and will be restored upon NtContinue. + * KiUserApcDispatcher and KiUserCallbackDispatcher need to be evaluated for this + * issue. + */ + + cld + /* Save the Context and Exception Records */ mov ecx, [esp+4] mov ebx, [esp]