[PATCH v2 5/5] ntdll/tests: Use __ASM_GLOBAL_FUNC to define the breakpoint function.

Zebediah Figura z.figura12 at gmail.com
Thu Jun 24 11:14:38 CDT 2021


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/ntdll/tests/exception.c | 61 ++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 30 deletions(-)

diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c
index 8f23677064b..f459bd97741 100644
--- a/dlls/ntdll/tests/exception.c
+++ b/dlls/ntdll/tests/exception.c
@@ -194,6 +194,8 @@ static BOOL     is_wow64;
 static BOOL have_vectored_api;
 static int test_stage;
 
+void __cdecl do_breakpoint(void);
+
 #if defined(__i386__) || defined(__x86_64__)
 static void test_debugger_xstate(HANDLE thread, CONTEXT *ctx, int stage)
 {
@@ -1204,8 +1206,8 @@ static void test_debugger(DWORD cont_status)
                 {
                     ok(de.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT,
                        "expected EXCEPTION_BREAKPOINT, got %08x\n", de.u.Exception.ExceptionRecord.ExceptionCode);
-                    ok((char *)ctx.Eip == (char *)code_mem_address + 2,
-                       "expected Eip = %p, got 0x%x\n", (char *)code_mem_address + 2, ctx.Eip);
+                    ok((char *)ctx.Eip == (char *)do_breakpoint + 2,
+                       "expected Eip = %p, got 0x%x\n", (char *)do_breakpoint + 2, ctx.Eip);
 
                     if (stage == 10) continuestatus = DBG_EXCEPTION_NOT_HANDLED;
                 }
@@ -3885,8 +3887,8 @@ static void test_debugger(DWORD cont_status)
                 {
                     ok(de.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT,
                        "expected EXCEPTION_BREAKPOINT, got %08x\n", de.u.Exception.ExceptionRecord.ExceptionCode);
-                    ok((char *)ctx.Rip == (char *)code_mem_address + 2,
-                       "expected Rip = %p, got %p\n", (char *)code_mem_address + 2, (char *)ctx.Rip);
+                    ok((char *)ctx.Rip == (char *)do_breakpoint + 2,
+                       "expected Rip = %p, got %p\n", (char *)do_breakpoint + 2, (char *)ctx.Rip);
                     if (stage == 10) continuestatus = DBG_EXCEPTION_NOT_HANDLED;
                 }
                 else if (stage == 11 || stage == 12 || stage == 13)
@@ -6964,6 +6966,19 @@ static void test_ripevent(DWORD numexc)
     pRtlRemoveVectoredExceptionHandler(vectored_handler);
 }
 
+__ASM_GLOBAL_FUNC( do_breakpoint,
+#if defined(__i386__) || defined(__x86_64__)
+    ".byte 0xcd,0x03\n\t" /* force generating a two-byte int $0x3 */
+    "ret"
+#elif defined(__arm__)
+    "udf #0xfe\n\t"
+    "bx lr"
+#elif defined(__aarch64__)
+    "brk #0xf000\n\t"
+    "ret"
+#endif
+);
+
 static DWORD breakpoint_exceptions;
 
 static LONG CALLBACK breakpoint_handler(EXCEPTION_POINTERS *ExceptionInfo)
@@ -6975,32 +6990,32 @@ static LONG CALLBACK breakpoint_handler(EXCEPTION_POINTERS *ExceptionInfo)
        rec->ExceptionCode, EXCEPTION_BREAKPOINT);
 
 #ifdef __i386__
-    ok(ExceptionInfo->ContextRecord->Eip == (DWORD)code_mem + 1,
-       "expected Eip = %x, got %x\n", (DWORD)code_mem + 1, ExceptionInfo->ContextRecord->Eip);
+    ok(ExceptionInfo->ContextRecord->Eip == (DWORD)do_breakpoint + 1,
+       "expected Eip = %x, got %x\n", (DWORD)do_breakpoint + 1, ExceptionInfo->ContextRecord->Eip);
     ok(rec->NumberParameters == (is_wow64 ? 1 : 3),
        "ExceptionParameters is %d instead of %d\n", rec->NumberParameters, is_wow64 ? 1 : 3);
     ok(rec->ExceptionInformation[0] == 0,
        "got ExceptionInformation[0] = %lx\n", rec->ExceptionInformation[0]);
-    ExceptionInfo->ContextRecord->Eip = (DWORD)code_mem + 2;
+    ExceptionInfo->ContextRecord->Eip = (DWORD)do_breakpoint + 2;
 #elif defined(__x86_64__)
-    ok(ExceptionInfo->ContextRecord->Rip == (DWORD_PTR)code_mem + 1,
-       "expected Rip = %lx, got %lx\n", (DWORD_PTR)code_mem + 1, ExceptionInfo->ContextRecord->Rip);
+    ok(ExceptionInfo->ContextRecord->Rip == (DWORD_PTR)do_breakpoint + 1,
+       "expected Rip = %lx, got %lx\n", (DWORD_PTR)do_breakpoint + 1, ExceptionInfo->ContextRecord->Rip);
     ok(rec->NumberParameters == 1,
        "ExceptionParameters is %d instead of 1\n", rec->NumberParameters);
     ok(rec->ExceptionInformation[0] == 0,
        "got ExceptionInformation[0] = %lx\n", rec->ExceptionInformation[0]);
-    ExceptionInfo->ContextRecord->Rip = (DWORD_PTR)code_mem + 2;
+    ExceptionInfo->ContextRecord->Rip = (DWORD_PTR)do_breakpoint + 2;
 #elif defined(__arm__)
-    ok(ExceptionInfo->ContextRecord->Pc == (DWORD)code_mem + 1,
-       "expected pc = %x, got %x\n", (DWORD)code_mem + 1, ExceptionInfo->ContextRecord->Pc);
+    ok(ExceptionInfo->ContextRecord->Pc == (DWORD)do_breakpoint + 1,
+       "expected pc = %x, got %x\n", (DWORD)do_breakpoint + 1, ExceptionInfo->ContextRecord->Pc);
     ok(rec->NumberParameters == 1,
        "ExceptionParameters is %d instead of 1\n", rec->NumberParameters);
     ok(rec->ExceptionInformation[0] == 0,
        "got ExceptionInformation[0] = %lx\n", rec->ExceptionInformation[0]);
     ExceptionInfo->ContextRecord->Pc += 2;
 #elif defined(__aarch64__)
-    ok(ExceptionInfo->ContextRecord->Pc == (DWORD_PTR)code_mem,
-       "expected pc = %lx, got %lx\n", (DWORD_PTR)code_mem, ExceptionInfo->ContextRecord->Pc);
+    ok(ExceptionInfo->ContextRecord->Pc == (DWORD_PTR)do_breakpoint,
+       "expected pc = %lx, got %lx\n", (DWORD_PTR)do_breakpoint, ExceptionInfo->ContextRecord->Pc);
     ok(rec->NumberParameters == 1,
        "ExceptionParameters is %d instead of 1\n", rec->NumberParameters);
     ok(rec->ExceptionInformation[0] == 0,
@@ -7012,28 +7027,15 @@ static LONG CALLBACK breakpoint_handler(EXCEPTION_POINTERS *ExceptionInfo)
     return (rec->ExceptionCode == EXCEPTION_BREAKPOINT) ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH;
 }
 
-#if defined(__i386__) || defined(__x86_64__)
-static const BYTE breakpoint_code[] = { 0xcd, 0x03, 0xc3 };   /* int $0x3; ret */
-#elif defined(__arm__)
-static const DWORD breakpoint_code[] = { 0xdefe, 0x4770 };  /* udf #0xfe; bx lr */
-#elif defined(__aarch64__)
-static const DWORD breakpoint_code[] = { 0xd43e0000, 0xd65f03c0 };  /* brk #0xf000; ret */
-#endif
-
 static void test_breakpoint(DWORD numexc)
 {
-    DWORD (CDECL *func)(void) = code_mem;
     void *vectored_handler;
 
-    memcpy(code_mem, breakpoint_code, sizeof(breakpoint_code));
-#ifdef __arm__
-    func = (void *)((char *)code_mem + 1);  /* thumb */
-#endif
     vectored_handler = pRtlAddVectoredExceptionHandler(TRUE, &breakpoint_handler);
     ok(vectored_handler != 0, "RtlAddVectoredExceptionHandler failed\n");
 
     breakpoint_exceptions = 0;
-    func();
+    do_breakpoint();
     ok(breakpoint_exceptions == numexc, "int $0x3 generated %u exceptions, expected %u\n",
        breakpoint_exceptions, numexc);
 
@@ -7066,8 +7068,7 @@ static void test_debuggee_xstate(void)
 
     if (!pRtlGetEnabledExtendedFeatures || !pRtlGetEnabledExtendedFeatures(1 << XSTATE_AVX))
     {
-        memcpy(code_mem, breakpoint_code, sizeof(breakpoint_code));
-        func();
+        do_breakpoint();
         return;
     }
 
-- 
2.30.2




More information about the wine-devel mailing list