Marcus Meissner : ntdll: Added debug registers test case.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Oct 2 14:59:47 CDT 2006


Module: wine
Branch: master
Commit: 3a6d53e5d09da1d09211985947344b426860cdf3
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=3a6d53e5d09da1d09211985947344b426860cdf3

Author: Marcus Meissner <marcus at jet.franken.de>
Date:   Sat Sep 30 15:09:55 2006 +0200

ntdll: Added debug registers test case.

---

 dlls/ntdll/tests/exception.c |   55 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c
index 64e683b..1d00816 100644
--- a/dlls/ntdll/tests/exception.c
+++ b/dlls/ntdll/tests/exception.c
@@ -37,6 +37,7 @@ #include "wine/test.h"
 #ifdef __i386__
 
 static struct _TEB * (WINAPI *pNtCurrentTeb)(void);
+static NTSTATUS  (WINAPI *pNtGetContextThread)(HANDLE,CONTEXT*);
 
 /* Test various instruction combinations that cause a protection fault on the i386,
  * and check what the resulting exception looks like.
@@ -227,11 +228,65 @@ static void test_prot_fault(void)
     pNtCurrentTeb()->Tib.ExceptionList = exc_frame.frame.Prev;
 }
 
+static DWORD dreg_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
+                      CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
+{
+    context->Eip += 2;	/* Skips the popl (%eax) */
+    context->Dr0 = 0;
+    context->Dr1 = 0;
+    context->Dr2 = 0;
+    context->Dr3 = 0;
+    context->Dr6 = 0;
+    context->Dr7 = 0x155;
+    return ExceptionContinueExecution;
+}
+
+static BYTE code[5] = {
+	0x31, 0xc0, /* xor    %eax,%eax */
+	0x8f, 0x00, /* popl   (%eax) - cause exception */
+        0xc3        /* ret */
+};
+
+static void test_debug_regs(void)
+{
+    CONTEXT ctx;
+    NTSTATUS res;
+    struct
+    {
+        EXCEPTION_REGISTRATION_RECORD frame;
+    } exc_frame;
+    void (*func)(void) = (void*)code;
+
+    pNtCurrentTeb = (void *)GetProcAddress( GetModuleHandleA("ntdll.dll"), "NtCurrentTeb" );
+    if (!pNtCurrentTeb)
+    {
+        trace( "NtCurrentTeb not found, skipping tests\n" );
+        return;
+    }
+    pNtGetContextThread = (void *)GetProcAddress( GetModuleHandleA("ntdll.dll"), "NtGetContextThread" );
+    if (!pNtGetContextThread)
+    {
+        trace( "NtGetContextThread not found, skipping tests\n" );
+        return;
+    }
+
+    exc_frame.frame.Handler = dreg_handler;
+    exc_frame.frame.Prev = pNtCurrentTeb()->Tib.ExceptionList;
+    pNtCurrentTeb()->Tib.ExceptionList = &exc_frame.frame;
+    func();
+    pNtCurrentTeb()->Tib.ExceptionList = exc_frame.frame.Prev;
+    ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
+    res = pNtGetContextThread(GetCurrentThread(), &ctx);
+    ok (res == STATUS_SUCCESS,"NtGetContextThread failed with %lx", res);
+    ok(ctx.Dr7 == 0x155,"failed to set debugregister 7 to 0x155");
+}
+
 #endif  /* __i386__ */
 
 START_TEST(exception)
 {
 #ifdef __i386__
     test_prot_fault();
+    test_debug_regs();
 #endif
 }




More information about the wine-cvs mailing list