1/*
2 * PROJECT:     ReactOS api tests
3 * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE:     Test helper for x86 RtlUnwind
5 * COPYRIGHT:   Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8#include <asm.inc>
9#include <ks386.inc>
10
11.code
12
13EXTERN _g_InContext:DWORD
14EXTERN _g_OutContext:DWORD
15EXTERN _RtlUnwind@16:PROC
16
17//
18// VOID
19// WINAPI
20// RtlUnwindWrapper(
21//     _In_ PVOID TargetFrame,
22//     _In_ PVOID TargetIp,
23//     _In_ PEXCEPTION_RECORD ExceptionRecord,
24//     _In_ PVOID ReturnValue);
25//
26PUBLIC _RtlUnwindWrapper@16
27FUNC _RtlUnwindWrapper@16
28
29    push ebp
30    mov ebp, esp
31
32    /* Save non-volatile registers */
33    push ebx
34    push esi
35    push edi
36
37    /* Load registers from the in-context */
38    mov eax, _g_InContext[CONTEXT_EAX]
39    mov ebx, _g_InContext[CONTEXT_EBX]
40    mov ecx, _g_InContext[CONTEXT_ECX]
41    mov edx, _g_InContext[CONTEXT_EDX]
42    mov esi, _g_InContext[CONTEXT_ESI]
43    mov edi, _g_InContext[CONTEXT_EDI]
44
45    /* Call the native function */
46    push dword ptr [ebp + 20] // ReturnValue
47    push dword ptr [ebp + 16] // ExceptionRecord
48    push dword ptr [ebp + 12] // TargetIp
49    push dword ptr [ebp + 8]  // TargetFrame
50    call _RtlUnwind@16
51
52    /* Save registers in the out-context */
53    mov _g_OutContext[CONTEXT_EAX], eax
54    mov _g_OutContext[CONTEXT_EBX], ebx
55    mov _g_OutContext[CONTEXT_ECX], ecx
56    mov _g_OutContext[CONTEXT_EDX], edx
57    mov _g_OutContext[CONTEXT_ESI], esi
58    mov _g_OutContext[CONTEXT_EDI], edi
59    mov word ptr _g_OutContext[CONTEXT_SEGCS], cs
60    mov word ptr _g_OutContext[CONTEXT_SEGDS], ds
61    mov word ptr _g_OutContext[CONTEXT_SEGES], es
62    mov word ptr _g_OutContext[CONTEXT_SEGFS], fs
63
64    /* Restore non-volatile registers */
65    pop edi
66    pop esi
67    pop ebx
68
69    mov esp, ebp
70    pop ebp
71    ret 16
72
73ENDFUNC
74
75
76END
77