1 | ; $Id: except-x86-vcc-asm.asm 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - Visual C++ Compiler - x86 Exception Handler Support Code.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2022-2023 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.virtualbox.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 | ;* Defined Constants And Macros *
|
---|
47 | ;*********************************************************************************************************************************
|
---|
48 |
|
---|
49 | ;; @def WITH_NLG_STUFF
|
---|
50 | ; Enabled NLG debugger hooks/whatever - no idea how it's used.
|
---|
51 | ;
|
---|
52 | ; So far vsdebugeng.manimpl.dll in the VS2019 remote debugger directory is the
|
---|
53 | ; only component with any _NLG_ strings in it. Could not find any references
|
---|
54 | ; to _NLG_ in windbg.
|
---|
55 | %define WITH_NLG_STUFF 1
|
---|
56 |
|
---|
57 |
|
---|
58 | ;*********************************************************************************************************************************
|
---|
59 | ;* Structures and Typedefs *
|
---|
60 | ;*********************************************************************************************************************************
|
---|
61 |
|
---|
62 | struc EH4_XCPT_REG_REC_T
|
---|
63 | .uSavedEsp resd 1 ; 0 / 0x00
|
---|
64 | .pXctpPtrs resd 1 ; 4 / 0x04
|
---|
65 | .XcptRec resd 2 ; 8 / 0x08
|
---|
66 | .uEncodedScopeTable resd 1 ; 16 / 0x10
|
---|
67 | .uTryLevel resd 1 ; 20 / 0x14
|
---|
68 | endstruc ; 24 / 0x18
|
---|
69 |
|
---|
70 |
|
---|
71 | ;;
|
---|
72 | ; Scope table record describing __try / __except / __finally blocks (aka
|
---|
73 | ; EH4_SCOPETABLE_RECORD).
|
---|
74 | ;
|
---|
75 | struc EH4_SCOPE_TAB_REC_T
|
---|
76 | .uEnclosingLevel resd 1
|
---|
77 | .pfnFilter resd 1
|
---|
78 | .pfnHandlerOrFinally resd 1
|
---|
79 | endstruc
|
---|
80 |
|
---|
81 | ;; Special EH4_SCOPE_TAB_REC_T::uEnclosingLevel used to terminate the chain.
|
---|
82 | %define EH4_TOPMOST_TRY_LEVEL 0xfffffffe
|
---|
83 |
|
---|
84 | ;;
|
---|
85 | ; Scope table used by _except_handler4 (aka EH4_SCOPETABLE).
|
---|
86 | ;
|
---|
87 | struc EH4_SCOPE_TAB_T
|
---|
88 | .offGSCookie resd 1
|
---|
89 | .offGSCookieXor resd 1
|
---|
90 | .offEHCookie resd 1
|
---|
91 | .offEHCookieXor resd 1
|
---|
92 | .aScopeRecords resb 12
|
---|
93 | endstruc
|
---|
94 |
|
---|
95 |
|
---|
96 | ;*********************************************************************************************************************************
|
---|
97 | ;* External Symbols *
|
---|
98 | ;*********************************************************************************************************************************
|
---|
99 | BEGINCODE
|
---|
100 | extern IMPNAME(RtlUnwind@16)
|
---|
101 | extern _rtVccEh4DoLocalUnwindHandler@16
|
---|
102 |
|
---|
103 |
|
---|
104 | ;*********************************************************************************************************************************
|
---|
105 | ;* Global Variables *
|
---|
106 | ;*********************************************************************************************************************************
|
---|
107 |
|
---|
108 | ;; Delcare rtVccEh4DoLocalUnwindHandler() in except-x86.cpp as a save exception handler.
|
---|
109 | ; This adds the symbol table number of the exception handler to the special .sxdata section.
|
---|
110 | safeseh _rtVccEh4DoLocalUnwindHandler@16
|
---|
111 |
|
---|
112 | %ifdef WITH_NLG_STUFF
|
---|
113 | BEGINDATA
|
---|
114 | GLOBALNAME_RAW __NLG_Destination, data, hidden
|
---|
115 | dd 019930520h
|
---|
116 | dd 0
|
---|
117 | dd 0
|
---|
118 | dd 0
|
---|
119 | %endif
|
---|
120 |
|
---|
121 |
|
---|
122 | BEGINCODE
|
---|
123 |
|
---|
124 | %ifdef WITH_NLG_STUFF
|
---|
125 |
|
---|
126 | ;;
|
---|
127 | ; Some VS debugger interface, I think.
|
---|
128 | ;
|
---|
129 | ; @param EDX Notification code.
|
---|
130 | ; @uses EBP, EAX & ECX are preserved. This differs from other implementation,
|
---|
131 | ; but simplifies the calling code.
|
---|
132 | ;
|
---|
133 | ALIGNCODE(32)
|
---|
134 | GLOBALNAME_RAW __NLG_Notify, function, hidden
|
---|
135 | ;
|
---|
136 | ; Save registers.
|
---|
137 | ;
|
---|
138 | push eax
|
---|
139 | push ecx
|
---|
140 | push ebp
|
---|
141 | push ebx
|
---|
142 |
|
---|
143 |
|
---|
144 | ;
|
---|
145 | ; ECX = notification code.
|
---|
146 | ; EBX = __NLG_Destination
|
---|
147 | ;
|
---|
148 | mov ecx, edx ; Originally held in ECX, so moving it there for now.
|
---|
149 | mov ebx, __NLG_Destination
|
---|
150 |
|
---|
151 | __NLG_Go:
|
---|
152 | ;
|
---|
153 | ; Save info to __NLG_Destination and the stack (same layout).
|
---|
154 | ;
|
---|
155 | mov [ebx + 0ch], ebp
|
---|
156 | push ebp
|
---|
157 | mov [ebx + 08h], ecx
|
---|
158 | push ecx
|
---|
159 | mov [ebx + 04h], eax
|
---|
160 | push eax
|
---|
161 |
|
---|
162 | ;
|
---|
163 | ; This is presumably the symbol the debugger hooks on to as the string
|
---|
164 | ; "__NLG_Dispatch" was found in vsdebugeng.manimpl.dll in VS2019.
|
---|
165 | ;
|
---|
166 | global __NLG_Dispatch
|
---|
167 | __NLG_Dispatch:
|
---|
168 |
|
---|
169 | ; Drop the info structure from the stack.
|
---|
170 | add esp, 4*3
|
---|
171 |
|
---|
172 | ;
|
---|
173 | ; Restore registers and drop the parameter as we return.
|
---|
174 | ;
|
---|
175 | ; Note! This may sabotage attempts by the debugger to modify the state...
|
---|
176 | ; But that can be fixed once we know this is a requirement. Just
|
---|
177 | ; keep things simple for the caller for now.
|
---|
178 | ;
|
---|
179 | pop ebx
|
---|
180 | pop ebp
|
---|
181 | pop ecx
|
---|
182 | pop eax
|
---|
183 | ret
|
---|
184 |
|
---|
185 | ;;
|
---|
186 | ; NLG call + return2.
|
---|
187 | ;
|
---|
188 | ; The "__NLG_Return2" symbol was observed in several vsdebugeng.manimpl.dll
|
---|
189 | ; strings in VS2019.
|
---|
190 | ;
|
---|
191 | ALIGNCODE(4)
|
---|
192 | GLOBALNAME_RAW __NLG_Call, function, hidden
|
---|
193 | call eax
|
---|
194 |
|
---|
195 | global __NLG_Return2
|
---|
196 | __NLG_Return2:
|
---|
197 | ret
|
---|
198 |
|
---|
199 | %endif
|
---|
200 |
|
---|
201 |
|
---|
202 | ;;
|
---|
203 | ; Calls the filter sub-function for a __finally statement.
|
---|
204 | ;
|
---|
205 | ; This sets all GRPs to zero, except for ESP, EBP and EAX.
|
---|
206 | ;
|
---|
207 | ; @param pfnFilter [ebp + 08h]
|
---|
208 | ; @param fAbend [ebp + 0ch]
|
---|
209 | ; @param pbFrame [ebp + 10h]
|
---|
210 | ;
|
---|
211 | ALIGNCODE(64)
|
---|
212 | BEGINPROC rtVccEh4DoFinally
|
---|
213 | push ebp
|
---|
214 | mov ebp, esp
|
---|
215 | push ebx
|
---|
216 | push edi
|
---|
217 | push esi
|
---|
218 |
|
---|
219 | xor edi, edi
|
---|
220 | xor esi, esi
|
---|
221 | %ifndef WITH_NLG_STUFF
|
---|
222 | xor edx, edx
|
---|
223 | %endif
|
---|
224 | xor ebx, ebx
|
---|
225 |
|
---|
226 | mov eax, [ebp + 08h] ; pfnFilter
|
---|
227 | movzx ecx, byte [ebp + 0ch] ; fAbend
|
---|
228 | mov ebp, [ebp + 10h] ; pbFrame
|
---|
229 |
|
---|
230 | %ifdef WITH_NLG_STUFF
|
---|
231 | mov edx, 101h
|
---|
232 | call __NLG_Notify
|
---|
233 | xor edx, edx
|
---|
234 |
|
---|
235 | call __NLG_Call
|
---|
236 | %else
|
---|
237 | call eax
|
---|
238 | %endif
|
---|
239 |
|
---|
240 | pop esi
|
---|
241 | pop edi
|
---|
242 | pop ebx
|
---|
243 | pop ebp
|
---|
244 | ret
|
---|
245 | ENDPROC rtVccEh4DoFinally
|
---|
246 |
|
---|
247 |
|
---|
248 | ;;
|
---|
249 | ; Calls the filter sub-function for an __except statement.
|
---|
250 | ;
|
---|
251 | ; This sets all GRPs to zero, except for ESP, EBP and ECX.
|
---|
252 | ;
|
---|
253 | ; @param pfnFilter [ebp + 08h]
|
---|
254 | ; @param pbFrame [ebp + 0ch]
|
---|
255 | ;
|
---|
256 | ALIGNCODE(32)
|
---|
257 | BEGINPROC rtVccEh4DoFiltering
|
---|
258 | push ebp
|
---|
259 | push ebx
|
---|
260 | push edi
|
---|
261 | push esi
|
---|
262 |
|
---|
263 | mov ecx, [esp + 5 * 4 + 0] ; pfnFilter
|
---|
264 | mov ebp, [esp + 5 * 4 + 4] ; pbFrame
|
---|
265 |
|
---|
266 | xor edi, edi
|
---|
267 | xor esi, esi
|
---|
268 | xor edx, edx
|
---|
269 | xor ebx, ebx
|
---|
270 | xor eax, eax
|
---|
271 |
|
---|
272 | call ecx
|
---|
273 |
|
---|
274 | pop esi
|
---|
275 | pop edi
|
---|
276 | pop ebx
|
---|
277 | pop ebp
|
---|
278 | ret
|
---|
279 | ENDPROC rtVccEh4DoFiltering
|
---|
280 |
|
---|
281 |
|
---|
282 | ;;
|
---|
283 | ; Resumes executing in an __except block (never returns).
|
---|
284 | ;
|
---|
285 | ; @param pfnHandler [ebp + 08h]
|
---|
286 | ; @param pbFrame [ebp + 0ch]
|
---|
287 | ;
|
---|
288 | ALIGNCODE(32)
|
---|
289 | BEGINPROC rtVccEh4JumpToHandler
|
---|
290 | ;
|
---|
291 | ; Since we're never returning there is no need to save anything here. So,
|
---|
292 | ; just start by loading parameters into registers.
|
---|
293 | ;
|
---|
294 | mov esi, [esp + 1 * 4 + 0] ; pfnFilter
|
---|
295 | mov ebp, [esp + 1 * 4 + 4] ; pbFrame
|
---|
296 |
|
---|
297 | %ifdef WITH_NLG_STUFF
|
---|
298 | ;
|
---|
299 | ; Notify VS debugger/whatever.
|
---|
300 | ;
|
---|
301 | mov eax, esi
|
---|
302 | mov edx, 1
|
---|
303 | call __NLG_Notify
|
---|
304 | %endif
|
---|
305 |
|
---|
306 | ;
|
---|
307 | ; Zero all GPRs except for ESP, EBP and ESI.
|
---|
308 | ;
|
---|
309 | xor edi, edi
|
---|
310 | xor edx, edx
|
---|
311 | xor ecx, ecx
|
---|
312 | xor ebx, ebx
|
---|
313 | xor eax, eax
|
---|
314 |
|
---|
315 | jmp esi
|
---|
316 | ENDPROC rtVccEh4JumpToHandler
|
---|
317 |
|
---|
318 |
|
---|
319 | ;;
|
---|
320 | ; This does global unwinding via RtlUnwind.
|
---|
321 | ;
|
---|
322 | ; The interface kind of requires us to do this from assembly.
|
---|
323 | ;
|
---|
324 | ; @param pXcptRec [ebp + 08h]
|
---|
325 | ; @param pXcptRegRec [ebp + 0ch]
|
---|
326 | ;
|
---|
327 | ALIGNCODE(32)
|
---|
328 | BEGINPROC rtVccEh4DoGlobalUnwind
|
---|
329 | push ebp
|
---|
330 | mov ebp, esp
|
---|
331 |
|
---|
332 | ; Save all non-volatile registers.
|
---|
333 | push edi
|
---|
334 | push esi
|
---|
335 | push ebx
|
---|
336 |
|
---|
337 | ;
|
---|
338 | ; Call unwind function.
|
---|
339 | ;
|
---|
340 | push 0 ; ReturnValue
|
---|
341 | push dword [ebp + 08h] ; ExceptionRecord - pXcptRec
|
---|
342 | push .return ; TargetIp
|
---|
343 | push dword [ebp + 0ch] ; TargetFrame - pXcptRegRec
|
---|
344 | call IMP(RtlUnwind@16)
|
---|
345 |
|
---|
346 | ;
|
---|
347 | ; The RtlUnwind code will place us here if it doesn't return the regular way.
|
---|
348 | ;
|
---|
349 | .return:
|
---|
350 | ; Restore non-volatile registers.
|
---|
351 | pop ebx
|
---|
352 | pop esi
|
---|
353 | pop edi
|
---|
354 |
|
---|
355 | leave
|
---|
356 | ret
|
---|
357 | ENDPROC rtVccEh4DoGlobalUnwind
|
---|
358 |
|
---|