1 | ; $Id: except-x86-vcc-asm.asm 97866 2022-12-26 02:14:08Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - Visual C++ Compiler - x86 Exception Handler Support Code.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2022 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.alldomusa.eu.org.
|
---|
11 | ;
|
---|
12 | ; This program is free software; you can redistribute it and/or
|
---|
13 | ; modify it under the terms of the GNU General Public License
|
---|
14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ; License.
|
---|
16 | ;
|
---|
17 | ; This program is distributed in the hope that it will be useful, but
|
---|
18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ; General Public License for more details.
|
---|
21 | ;
|
---|
22 | ; You should have received a copy of the GNU General Public License
|
---|
23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | ;
|
---|
25 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 | ;*********************************************************************************************************************************
|
---|
40 | ;* Header Files *
|
---|
41 | ;*********************************************************************************************************************************
|
---|
42 | %include "iprt/asmdefs.mac"
|
---|
43 |
|
---|
44 |
|
---|
45 | ;*********************************************************************************************************************************
|
---|
46 | ;* Structures and Typedefs *
|
---|
47 | ;*********************************************************************************************************************************
|
---|
48 |
|
---|
49 | struc EH4_XCPT_REG_REC_T
|
---|
50 | .uSavedEsp resd 1 ; 0 / 0x00
|
---|
51 | .pXctpPtrs resd 1 ; 4 / 0x04
|
---|
52 | .XcptRec resd 2 ; 8 / 0x08
|
---|
53 | .uEncodedScopeTable resd 1 ; 16 / 0x10
|
---|
54 | .uTryLevel resd 1 ; 20 / 0x14
|
---|
55 | endstruc ; 24 / 0x18
|
---|
56 |
|
---|
57 |
|
---|
58 | ;;
|
---|
59 | ; Scope table record describing __try / __except / __finally blocks (aka
|
---|
60 | ; EH4_SCOPETABLE_RECORD).
|
---|
61 | ;
|
---|
62 | struc EH4_SCOPE_TAB_REC_T
|
---|
63 | .uEnclosingLevel resd 1
|
---|
64 | .pfnFilter resd 1
|
---|
65 | .pfnHandlerOrFinally resd 1
|
---|
66 | endstruc
|
---|
67 |
|
---|
68 | ;; Special EH4_SCOPE_TAB_REC_T::uEnclosingLevel used to terminate the chain.
|
---|
69 | %define EH4_TOPMOST_TRY_LEVEL 0xfffffffe
|
---|
70 |
|
---|
71 | ;;
|
---|
72 | ; Scope table used by _except_handler4 (aka EH4_SCOPETABLE).
|
---|
73 | ;
|
---|
74 | struc EH4_SCOPE_TAB_T
|
---|
75 | .offGSCookie resd 1
|
---|
76 | .offGSCookieXor resd 1
|
---|
77 | .offEHCookie resd 1
|
---|
78 | .offEHCookieXor resd 1
|
---|
79 | .aScopeRecords resb 12
|
---|
80 | endstruc
|
---|
81 |
|
---|
82 |
|
---|
83 | ;*********************************************************************************************************************************
|
---|
84 | ;* External Symbols *
|
---|
85 | ;*********************************************************************************************************************************
|
---|
86 | BEGINCODE
|
---|
87 | extern IMPNAME(RtlUnwind@16)
|
---|
88 | extern _rtVccEh4DoLocalUnwindHandler@16
|
---|
89 |
|
---|
90 |
|
---|
91 | ;*********************************************************************************************************************************
|
---|
92 | ;* Global Variables *
|
---|
93 | ;*********************************************************************************************************************************
|
---|
94 |
|
---|
95 | ;; Delcare rtVccEh4DoLocalUnwindHandler() in except-x86.cpp as a save exception handler.
|
---|
96 | ; This adds the symbol table number of the exception handler to the special .sxdata section.
|
---|
97 | safeseh _rtVccEh4DoLocalUnwindHandler@16
|
---|
98 |
|
---|
99 |
|
---|
100 | BEGINCODE
|
---|
101 | ;;
|
---|
102 | ; Calls the filter sub-function for a __finally statement.
|
---|
103 | ;
|
---|
104 | ; This sets all GRPs to zero, except for ESP, EBP and EAX.
|
---|
105 | ;
|
---|
106 | ; @param pfnFilter [ebp + 08h]
|
---|
107 | ; @param fAbend [ebp + 0ch]
|
---|
108 | ; @param pbFrame [ebp + 10h]
|
---|
109 | ;
|
---|
110 | BEGINPROC rtVccEh4DoFinally
|
---|
111 | push ebp
|
---|
112 | mov ebp, esp
|
---|
113 | push ebx
|
---|
114 | push edi
|
---|
115 | push esi
|
---|
116 |
|
---|
117 | ;; @todo we're not calling __NLG_Notify nor NLG_Call, which may perhaps confuse debuggers or something...
|
---|
118 |
|
---|
119 | xor edi, edi
|
---|
120 | xor esi, esi
|
---|
121 | xor edx, edx
|
---|
122 | xor ebx, ebx
|
---|
123 |
|
---|
124 | mov eax, [ebp + 08h] ; pfnFilter
|
---|
125 | movzx ecx, byte [ebp + 0ch] ; fAbend
|
---|
126 | mov ebp, [ebp + 10h] ; pbFrame
|
---|
127 |
|
---|
128 | call eax
|
---|
129 |
|
---|
130 | pop esi
|
---|
131 | pop edi
|
---|
132 | pop ebx
|
---|
133 | pop ebp
|
---|
134 | ret
|
---|
135 | ENDPROC rtVccEh4DoFinally
|
---|
136 |
|
---|
137 |
|
---|
138 | ;;
|
---|
139 | ; Calls the filter sub-function for an __except statement.
|
---|
140 | ;
|
---|
141 | ; This sets all GRPs to zero, except for ESP, EBP and ECX.
|
---|
142 | ;
|
---|
143 | ; @param pfnFilter [ebp + 08h]
|
---|
144 | ; @param pbFrame [ebp + 0ch]
|
---|
145 | ;
|
---|
146 | BEGINPROC rtVccEh4DoFiltering
|
---|
147 | push ebp
|
---|
148 | push ebx
|
---|
149 | push edi
|
---|
150 | push esi
|
---|
151 |
|
---|
152 | mov ecx, [esp + 5 * 4 + 0] ; pfnFilter
|
---|
153 | mov ebp, [esp + 5 * 4 + 4] ; pbFrame
|
---|
154 |
|
---|
155 | xor edi, edi
|
---|
156 | xor esi, esi
|
---|
157 | xor edx, edx
|
---|
158 | xor ebx, ebx
|
---|
159 | xor eax, eax
|
---|
160 |
|
---|
161 | call ecx
|
---|
162 |
|
---|
163 | pop esi
|
---|
164 | pop edi
|
---|
165 | pop ebx
|
---|
166 | pop ebp
|
---|
167 | ret
|
---|
168 | ENDPROC rtVccEh4DoFiltering
|
---|
169 |
|
---|
170 |
|
---|
171 | ;;
|
---|
172 | ; Resumes executing in an __except block (never returns).
|
---|
173 | ;
|
---|
174 | ; @param pfnHandler [ebp + 08h]
|
---|
175 | ; @param pbFrame [ebp + 0ch]
|
---|
176 | ;
|
---|
177 | BEGINPROC rtVccEh4JumpToHandler
|
---|
178 | ;
|
---|
179 | ; Since we're never returning there is no need to save anything here. So,
|
---|
180 | ; just start by loading parameters into registers.
|
---|
181 | ;
|
---|
182 | mov esi, [esp + 1 * 4 + 0] ; pfnFilter
|
---|
183 | mov ebp, [esp + 1 * 4 + 4] ; pbFrame
|
---|
184 |
|
---|
185 | %if 0
|
---|
186 | mov eax, esi
|
---|
187 | push 1
|
---|
188 | call NAME(_NLG_Notify)
|
---|
189 | %endif
|
---|
190 |
|
---|
191 | ;
|
---|
192 | ; Zero all GPRs except for ESP, EBP and ESI.
|
---|
193 | ;
|
---|
194 | xor edi, edi
|
---|
195 | xor edx, edx
|
---|
196 | xor ecx, ecx
|
---|
197 | xor ebx, ebx
|
---|
198 | xor eax, eax
|
---|
199 |
|
---|
200 | jmp esi
|
---|
201 | ENDPROC rtVccEh4JumpToHandler
|
---|
202 |
|
---|
203 |
|
---|
204 |
|
---|
205 | ;;
|
---|
206 | ; This does global unwinding via RtlUnwind.
|
---|
207 | ;
|
---|
208 | ; The interface kind of requires us to do this from assembly.
|
---|
209 | ;
|
---|
210 | ; @param pXcptRec [ebp + 08h]
|
---|
211 | ; @param pXcptRegRec [ebp + 0ch]
|
---|
212 | ;
|
---|
213 | BEGINPROC rtVccEh4DoGlobalUnwind
|
---|
214 | push ebp
|
---|
215 | mov ebp, esp
|
---|
216 |
|
---|
217 | ; Save all non-volatile registers.
|
---|
218 | push edi
|
---|
219 | push esi
|
---|
220 | push ebx
|
---|
221 |
|
---|
222 | ;
|
---|
223 | ; Call unwind function.
|
---|
224 | ;
|
---|
225 | push 0 ; ReturnValue
|
---|
226 | push dword [ebp + 08h] ; ExceptionRecord - pXcptRec
|
---|
227 | push .return ; TargetIp
|
---|
228 | push dword [ebp + 0ch] ; TargetFrame - pXcptRegRec
|
---|
229 | call IMP(RtlUnwind@16)
|
---|
230 |
|
---|
231 | ;
|
---|
232 | ; The RtlUnwind code will place us here if it doesn't return the regular way.
|
---|
233 | ;
|
---|
234 | .return:
|
---|
235 | ; Restore non-volatile registers.
|
---|
236 | pop ebx
|
---|
237 | pop esi
|
---|
238 | pop edi
|
---|
239 |
|
---|
240 | leave
|
---|
241 | ret
|
---|
242 | ENDPROC rtVccEh4DoGlobalUnwind
|
---|
243 |
|
---|