[NTDLL_APITEST] Add test for x86 RtlUnwind

This commit is contained in:
Timo Kreuzer 2024-01-08 19:53:28 +02:00
parent 382836f087
commit d52b70a73e
5 changed files with 146 additions and 0 deletions

View file

@ -94,6 +94,7 @@ extern void func_RtlRemovePrivileges(void);
extern void func_RtlUnicodeStringToAnsiString(void);
extern void func_RtlUnicodeStringToCountedOemString(void);
extern void func_RtlUnicodeToOemN(void);
extern void func_RtlUnwind(void);
extern void func_RtlUpcaseUnicodeStringToCountedOemString(void);
extern void func_RtlValidateUnicodeString(void);
extern void func_RtlxUnicodeStringToAnsiSize(void);
@ -201,6 +202,9 @@ const struct test winetest_testlist[] =
{ "StackOverflow", func_StackOverflow },
{ "TimerResolution", func_TimerResolution },
{ "UserModeException", func_UserModeException },
#ifdef _M_IX86
{ "RtlUnwind", func_RtlUnwind },
#endif
#ifdef _M_AMD64
{ "RtlCaptureContext", func_RtlCaptureContext },
#endif

View file

@ -7,6 +7,10 @@ list(APPEND SOURCE
if(ARCH STREQUAL "i386")
list(APPEND SOURCE
i386/RtlCaptureContext.c
i386/RtlUnwind.c
)
list(APPEND ASM_SOURCE
i386/RtlUnwind-asm.s
)
elseif(ARCH STREQUAL "amd64")
list(APPEND ASM_SOURCE

View file

@ -0,0 +1,76 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Test helper for x86 RtlUnwind
* COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <asm.inc>
#include <ks386.inc>
.code
EXTERN _g_InContext:DWORD
EXTERN _g_OutContext:DWORD
EXTERN _RtlUnwind@16:PROC
//
// VOID
// WINAPI
// RtlUnwindWrapper(
// _In_ PVOID TargetFrame,
// _In_ PVOID TargetIp,
// _In_ PEXCEPTION_RECORD ExceptionRecord,
// _In_ PVOID ReturnValue);
//
PUBLIC _RtlUnwindWrapper@16
FUNC _RtlUnwindWrapper@16
push ebp
mov ebp, esp
/* Save non-volatile registers */
push ebx
push esi
push edi
/* Load registers from the in-context */
mov eax, _g_InContext[CONTEXT_EAX]
mov ebx, _g_InContext[CONTEXT_EBX]
mov ecx, _g_InContext[CONTEXT_ECX]
mov edx, _g_InContext[CONTEXT_EDX]
mov esi, _g_InContext[CONTEXT_ESI]
mov edi, _g_InContext[CONTEXT_EDI]
/* Call the native function */
push dword ptr [ebp + 20] // ReturnValue
push dword ptr [ebp + 16] // ExceptionRecord
push dword ptr [ebp + 12] // TargetIp
push dword ptr [ebp + 8] // TargetFrame
call _RtlUnwind@16
/* Save registers in the out-context */
mov _g_OutContext[CONTEXT_EAX], eax
mov _g_OutContext[CONTEXT_EBX], ebx
mov _g_OutContext[CONTEXT_ECX], ecx
mov _g_OutContext[CONTEXT_EDX], edx
mov _g_OutContext[CONTEXT_ESI], esi
mov _g_OutContext[CONTEXT_EDI], edi
mov word ptr _g_OutContext[CONTEXT_SEGCS], cs
mov word ptr _g_OutContext[CONTEXT_SEGDS], ds
mov word ptr _g_OutContext[CONTEXT_SEGES], es
mov word ptr _g_OutContext[CONTEXT_SEGFS], fs
/* Restore non-volatile registers */
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 16
ENDFUNC
END

View file

@ -0,0 +1,58 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Test for x86 RtlUnwind
* COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <rtltests.h>
CONTEXT g_InContext;
CONTEXT g_OutContext;
VOID
WINAPI
RtlUnwindWrapper(
_In_ PVOID TargetFrame,
_In_ PVOID TargetIp,
_In_ PEXCEPTION_RECORD ExceptionRecord,
_In_ PVOID ReturnValue);
START_TEST(RtlUnwind)
{
BOOL IsWow64;
RtlZeroMemory(&g_InContext, sizeof(g_InContext));
RtlZeroMemory(&g_OutContext, sizeof(g_OutContext));
PEXCEPTION_REGISTRATION_RECORD ExcptReg = (PEXCEPTION_REGISTRATION_RECORD)__readfsdword(0);
ok(ExcptReg != NULL, "ExcpReg is NULL\n");
g_InContext.Eax = 0xabcd0001;
g_InContext.Ebx = 0xabcd0002;
g_InContext.Ecx = 0xabcd0003;
g_InContext.Edx = 0xabcd0004;
g_InContext.Esi = 0xabcd0005;
g_InContext.Edi = 0xabcd0006;
RtlUnwindWrapper(ExcptReg, NULL, NULL, (PVOID)0x12345678);
ok_eq_hex(g_OutContext.Eax, 0x12345678ul);
ok_eq_hex(g_OutContext.Ebx, 0ul);
ok_eq_hex(g_OutContext.Ecx, 0ul);
ok_eq_hex(g_OutContext.Edx, 0ul);
ok_eq_hex(g_OutContext.Esi, 0ul);
ok_eq_hex(g_OutContext.Edi, 0ul);
if (IsWow64Process(NtCurrentProcess(), &IsWow64) && IsWow64)
{
ok_eq_hex(g_OutContext.SegCs, 0x23ul);
ok_eq_hex(g_OutContext.SegDs, 0x2bul);
ok_eq_hex(g_OutContext.SegEs, 0x2bul);
ok_eq_hex(g_OutContext.SegFs, 0x53ul);
}
else
{
ok_eq_hex(g_OutContext.SegCs, 0x1bul);
ok_eq_hex(g_OutContext.SegDs, 0x23ul);
ok_eq_hex(g_OutContext.SegEs, 0x23ul);
ok_eq_hex(g_OutContext.SegFs, 0x3bul);
}
}

View file

@ -5,11 +5,15 @@
extern void func_RtlCaptureContext(void);
extern void func_RtlIntSafe(void);
extern void func_RtlUnwind(void);
const struct test winetest_testlist[] =
{
{ "RtlIntSafe", func_RtlIntSafe },
#ifdef _M_IX86
{ "RtlUnwind", func_RtlUnwind },
#endif
#ifdef _M_AMD64
{ "RtlCaptureContext", func_RtlCaptureContext },
#endif