From ef546be4591cd3b3cf259a10872e07098c50e309 Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Mon, 4 Jun 2007 05:50:39 +0000 Subject: [PATCH] irc : Myrria (from linux xbox project) desc a bug in KiUserExceptionDispatcher and how to fix it. See issue #2279 for more details. svn path=/trunk/; revision=26985 --- reactos/dll/ntdll/main/i386/dispatch.S | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/reactos/dll/ntdll/main/i386/dispatch.S b/reactos/dll/ntdll/main/i386/dispatch.S index f6daf51e3e5..9ad3a141087 100644 --- a/reactos/dll/ntdll/main/i386/dispatch.S +++ b/reactos/dll/ntdll/main/i386/dispatch.S @@ -183,6 +183,30 @@ _KiRaiseUserExceptionDispatcher@0: .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]