2 * COPYRIGHT: See COPYING in the top level directory
4 * FILE: lib/crt/misc/i386/seh.S
5 * PURPOSE: SEH Support for the CRT
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
11 #include <reactos/asm.h>
14 #define DISPOSITION_DISMISS 0
15 #define DISPOSITION_CONTINUE_SEARCH 1
16 #define DISPOSITION_COLLIDED_UNWIND 3
18 EXTERN _RtlUnwind@16:PROC
20 /* GLOBALS *******************************************************************/
22 PUBLIC __global_unwind2
23 PUBLIC __local_unwind2
24 PUBLIC __abnormal_termination
25 PUBLIC __except_handler2
26 PUBLIC __except_handler3
28 /* FUNCTIONS *****************************************************************/
33 /* Check if we were unwinding and continue search if not */
35 test dword ptr [ecx+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
36 mov eax, DISPOSITION_CONTINUE_SEARCH
37 jz unwind_handler_return
39 /* We have a collision, do a local unwind */
51 /* Set new try level */
56 /* Return collided unwind */
57 mov eax, DISPOSITION_COLLIDED_UNWIND
59 unwind_handler_return:
65 /* Create stack and save all registers */
81 /* Restore registers and return */
91 __abnormal_termination:
96 /* Check if the handler is the unwind handler */
98 cmp dword ptr [ecx+4], offset _unwind_handler
101 /* Get the try level */
124 /* Get the exception registration */
127 /* Setup SEH to protect the unwind */
131 push offset _unwind_handler
136 /* Get the exception registration and try level */
141 /* Validate the unwind */
144 cmp dword ptr [esp+40], -1
150 /* Get the new enclosing level and save it */
156 /* Check the filter type */
157 cmp dword ptr [ebx+esi*4+4], 0
160 /* FIXME: NLG Notification */
162 /* Call the handler */
163 call dword ptr [ebx+esi*4+8]
181 /* Setup stack and save volatiles */
190 /* Clear direction flag */
193 /* Get exception registration and record */
197 /* Check if this is an unwind */
198 test dword ptr [eax+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
201 /* Save exception pointers structure */
208 /* Get the try level and scope table */
213 /* Validate try level */
217 /* Check if this is the termination handler */
219 cmp dword ptr [edi+ecx*4+4], 0
222 /* Save registers and call filter, then restore them */
226 call dword ptr [edi+ecx*4+4]
230 /* Restore ebx and check the result */
236 /* So this is an accept, call the termination handlers */
239 call __global_unwind2
245 /* Do local unwind */
251 /* Set new try level */
256 /* Call except handler */
257 call dword ptr [edi+ecx*4+8]
260 /* Reload try level and except again */
268 mov eax, DISPOSITION_DISMISS
272 /* Continue searching */
273 mov eax, DISPOSITION_CONTINUE_SEARCH
276 /* Do local unwind */
285 /* Retore EBP and set return disposition */
287 mov eax, DISPOSITION_CONTINUE_SEARCH
290 /* Restore registers and stack */
302 /* Setup stack and save volatiles */
311 /* Clear direction flag */
314 /* Get exception registration and record */
318 /* Check if this is an unwind */
319 test dword ptr [eax+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
322 /* Save exception pointers structure */
329 /* Get the try level and scope table */
333 /* FIXME: Validate the SEH exception */
336 /* Validate try level */
340 /* Check if this is the termination handler */
342 mov eax, [edi+ecx*4+4]
346 /* Save registers clear them all */
356 /* Call the filter and restore our registers */
361 /* Restore ebx and check the result */
367 /* So this is an accept, call the termination handlers */
370 call __global_unwind2
376 /* Do local unwind */
382 /* FIXME: Do NLG Notification */
384 /* Set new try level */
389 /* Clear registers and call except handler */
390 mov eax, [edi+ecx*4+8]
399 /* Reload try level and except again */
407 mov eax, DISPOSITION_DISMISS
411 /* Continue searching */
412 mov eax, DISPOSITION_CONTINUE_SEARCH
415 /* Do local unwind */
424 /* Retore EBP and set return disposition */
426 mov eax, DISPOSITION_CONTINUE_SEARCH
429 /* Restore registers and stack */