1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test for x86 RtlUnwind
5 * COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8 #include <rtltests.h>
9
10 CONTEXT g_InContext;
11 CONTEXT g_OutContext;
12
13 VOID
14 WINAPI
15 RtlUnwindWrapper(
16 _In_ PVOID TargetFrame,
17 _In_ PVOID TargetIp,
18 _In_ PEXCEPTION_RECORD ExceptionRecord,
19 _In_ PVOID ReturnValue);
20
START_TEST(RtlUnwind)21 START_TEST(RtlUnwind)
22 {
23 BOOL IsWow64;
24
25 RtlZeroMemory(&g_InContext, sizeof(g_InContext));
26 RtlZeroMemory(&g_OutContext, sizeof(g_OutContext));
27
28 PEXCEPTION_REGISTRATION_RECORD ExcptReg = (PEXCEPTION_REGISTRATION_RECORD)__readfsdword(0);
29 ok(ExcptReg != NULL, "ExcpReg is NULL\n");
30
31 g_InContext.Eax = 0xabcd0001;
32 g_InContext.Ebx = 0xabcd0002;
33 g_InContext.Ecx = 0xabcd0003;
34 g_InContext.Edx = 0xabcd0004;
35 g_InContext.Esi = 0xabcd0005;
36 g_InContext.Edi = 0xabcd0006;
37 RtlUnwindWrapper(ExcptReg, NULL, NULL, (PVOID)0x12345678);
38 ok_eq_hex(g_OutContext.Eax, 0x12345678ul);
39 ok_eq_hex(g_OutContext.Ebx, 0ul);
40 ok_eq_hex(g_OutContext.Ecx, 0ul);
41 ok_eq_hex(g_OutContext.Edx, 0ul);
42 ok_eq_hex(g_OutContext.Esi, 0ul);
43 ok_eq_hex(g_OutContext.Edi, 0ul);
44 if (IsWow64Process(NtCurrentProcess(), &IsWow64) && IsWow64)
45 {
46 ok_eq_hex(g_OutContext.SegCs, 0x23ul);
47 ok_eq_hex(g_OutContext.SegDs, 0x2bul);
48 ok_eq_hex(g_OutContext.SegEs, 0x2bul);
49 ok_eq_hex(g_OutContext.SegFs, 0x53ul);
50 }
51 else
52 {
53 ok_eq_hex(g_OutContext.SegCs, 0x1bul);
54 ok_eq_hex(g_OutContext.SegDs, 0x23ul);
55 ok_eq_hex(g_OutContext.SegEs, 0x23ul);
56 ok_eq_hex(g_OutContext.SegFs, 0x3bul);
57 }
58 }
59