Commit | Line | Data |
---|---|---|
37a4c9b8 AJ |
1 | /* |
2 | * msvcrt C++ exception handling | |
3 | * | |
4 | * Copyright 2002 Alexandre Julliard | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2.1 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
360a3f91 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
37a4c9b8 AJ |
19 | * |
20 | * NOTES | |
21 | * A good reference is the article "How a C++ compiler implements | |
22 | * exception handling" by Vishal Kochhar, available on | |
23 | * www.thecodeproject.com. | |
24 | */ | |
25 | ||
26 | #include "config.h" | |
27 | #include "wine/port.h" | |
28 | ||
e37c6e18 AJ |
29 | #include <stdarg.h> |
30 | ||
31 | #include "windef.h" | |
32 | #include "winbase.h" | |
9c1de6de | 33 | #include "winternl.h" |
37a4c9b8 AJ |
34 | #include "msvcrt.h" |
35 | #include "wine/exception.h" | |
737d4be8 | 36 | #include "excpt.h" |
37a4c9b8 AJ |
37 | #include "wine/debug.h" |
38 | ||
c62c1c01 | 39 | #include "cppexcept.h" |
37a4c9b8 | 40 | |
37a4c9b8 AJ |
41 | #ifdef __i386__ /* CxxFrameHandler is not supported on non-i386 */ |
42 | ||
6d9f0c20 AT |
43 | WINE_DEFAULT_DEBUG_CHANNEL(seh); |
44 | ||
24beabfd AJ |
45 | DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame, |
46 | PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch, | |
8592c4b8 AJ |
47 | const cxx_function_descr *descr, |
48 | EXCEPTION_REGISTRATION_RECORD* nested_frame, int nested_trylevel ); | |
5ad69f19 | 49 | |
37a4c9b8 | 50 | /* call a function with a given ebp */ |
7b103480 | 51 | static inline void *call_ebp_func( void *func, void *ebp ) |
37a4c9b8 AJ |
52 | { |
53 | void *ret; | |
c0165091 AJ |
54 | int dummy; |
55 | __asm__ __volatile__ ("pushl %%ebx\n\t" | |
56 | "pushl %%ebp\n\t" | |
57 | "movl %4,%%ebp\n\t" | |
58 | "call *%%eax\n\t" | |
59 | "popl %%ebp\n\t" | |
60 | "popl %%ebx" | |
61 | : "=a" (ret), "=S" (dummy), "=D" (dummy) | |
62 | : "0" (func), "1" (ebp) : "ecx", "edx", "memory" ); | |
37a4c9b8 AJ |
63 | return ret; |
64 | } | |
65 | ||
66 | /* call a copy constructor */ | |
7b103480 | 67 | static inline void call_copy_ctor( void *func, void *this, void *src, int has_vbase ) |
37a4c9b8 AJ |
68 | { |
69 | TRACE( "calling copy ctor %p object %p src %p\n", func, this, src ); | |
70 | if (has_vbase) | |
71 | /* in that case copy ctor takes an extra bool indicating whether to copy the base class */ | |
72 | __asm__ __volatile__("pushl $1; pushl %2; call *%0" | |
505dfdef | 73 | : : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" ); |
37a4c9b8 AJ |
74 | else |
75 | __asm__ __volatile__("pushl %2; call *%0" | |
505dfdef | 76 | : : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" ); |
37a4c9b8 AJ |
77 | } |
78 | ||
79 | /* call the destructor of the exception object */ | |
7b103480 | 80 | static inline void call_dtor( void *func, void *object ) |
37a4c9b8 | 81 | { |
6bd508f8 | 82 | __asm__ __volatile__("call *%0" : : "r" (func), "c" (object) : "eax", "edx", "memory" ); |
37a4c9b8 AJ |
83 | } |
84 | ||
abb170fa | 85 | /* continue execution to the specified address after exception is caught */ |
7b103480 | 86 | static inline void DECLSPEC_NORETURN continue_after_catch( cxx_exception_frame* frame, void *addr ) |
abb170fa AJ |
87 | { |
88 | __asm__ __volatile__("movl -4(%0),%%esp; leal 12(%0),%%ebp; jmp *%1" | |
89 | : : "r" (frame), "a" (addr) ); | |
90 | for (;;) ; /* unreached */ | |
91 | } | |
92 | ||
b8d5d962 | 93 | static inline void dump_type( const cxx_type_info *type ) |
37a4c9b8 | 94 | { |
9f859692 | 95 | TRACE( "flags %x type %p %s offsets %d,%d,%d size %d copy ctor %p\n", |
b8d5d962 AJ |
96 | type->flags, type->type_info, dbgstr_type_info(type->type_info), |
97 | type->offsets.this_offset, type->offsets.vbase_descr, type->offsets.vbase_offset, | |
98 | type->size, type->copy_ctor ); | |
37a4c9b8 AJ |
99 | } |
100 | ||
c62c1c01 | 101 | static void dump_exception_type( const cxx_exception_type *type ) |
37a4c9b8 | 102 | { |
c62c1c01 | 103 | UINT i; |
37a4c9b8 | 104 | |
9f859692 | 105 | TRACE( "flags %x destr %p handler %p type info %p\n", |
37a4c9b8 AJ |
106 | type->flags, type->destructor, type->custom_handler, type->type_info_table ); |
107 | for (i = 0; i < type->type_info_table->count; i++) | |
108 | { | |
9f859692 | 109 | TRACE( " %d: ", i ); |
37a4c9b8 AJ |
110 | dump_type( type->type_info_table->info[i] ); |
111 | } | |
112 | } | |
113 | ||
8592c4b8 | 114 | static void dump_function_descr( const cxx_function_descr *descr ) |
37a4c9b8 | 115 | { |
c62c1c01 JG |
116 | UINT i; |
117 | int j; | |
37a4c9b8 | 118 | |
9f859692 AJ |
119 | TRACE( "magic %x\n", descr->magic ); |
120 | TRACE( "unwind table: %p %d\n", descr->unwind_table, descr->unwind_count ); | |
37a4c9b8 AJ |
121 | for (i = 0; i < descr->unwind_count; i++) |
122 | { | |
9f859692 | 123 | TRACE( " %d: prev %d func %p\n", i, |
37a4c9b8 AJ |
124 | descr->unwind_table[i].prev, descr->unwind_table[i].handler ); |
125 | } | |
9f859692 | 126 | TRACE( "try table: %p %d\n", descr->tryblock, descr->tryblock_count ); |
37a4c9b8 AJ |
127 | for (i = 0; i < descr->tryblock_count; i++) |
128 | { | |
9f859692 | 129 | TRACE( " %d: start %d end %d catchlevel %d catch %p %d\n", i, |
37a4c9b8 AJ |
130 | descr->tryblock[i].start_level, descr->tryblock[i].end_level, |
131 | descr->tryblock[i].catch_level, descr->tryblock[i].catchblock, | |
132 | descr->tryblock[i].catchblock_count ); | |
133 | for (j = 0; j < descr->tryblock[i].catchblock_count; j++) | |
134 | { | |
8592c4b8 | 135 | const catchblock_info *ptr = &descr->tryblock[i].catchblock[j]; |
9f859692 | 136 | TRACE( " %d: flags %x offset %d handler %p type %p %s\n", |
b8d5d962 AJ |
137 | j, ptr->flags, ptr->offset, ptr->handler, |
138 | ptr->type_info, dbgstr_type_info( ptr->type_info ) ); | |
37a4c9b8 AJ |
139 | } |
140 | } | |
141 | } | |
142 | ||
37a4c9b8 | 143 | /* check if the exception type is caught by a given catch block, and return the type that matched */ |
8592c4b8 AJ |
144 | static const cxx_type_info *find_caught_type( cxx_exception_type *exc_type, |
145 | const catchblock_info *catchblock ) | |
37a4c9b8 AJ |
146 | { |
147 | UINT i; | |
148 | ||
149 | for (i = 0; i < exc_type->type_info_table->count; i++) | |
150 | { | |
c62c1c01 | 151 | const cxx_type_info *type = exc_type->type_info_table->info[i]; |
37a4c9b8 AJ |
152 | |
153 | if (!catchblock->type_info) return type; /* catch(...) matches any type */ | |
154 | if (catchblock->type_info != type->type_info) | |
155 | { | |
c62c1c01 | 156 | if (strcmp( catchblock->type_info->mangled, type->type_info->mangled )) continue; |
37a4c9b8 AJ |
157 | } |
158 | /* type is the same, now check the flags */ | |
159 | if ((exc_type->flags & TYPE_FLAG_CONST) && | |
160 | !(catchblock->flags & TYPE_FLAG_CONST)) continue; | |
161 | if ((exc_type->flags & TYPE_FLAG_VOLATILE) && | |
162 | !(catchblock->flags & TYPE_FLAG_VOLATILE)) continue; | |
163 | return type; /* it matched */ | |
164 | } | |
165 | return NULL; | |
166 | } | |
167 | ||
168 | ||
169 | /* copy the exception object where the catch block wants it */ | |
170 | static void copy_exception( void *object, cxx_exception_frame *frame, | |
8592c4b8 | 171 | const catchblock_info *catchblock, const cxx_type_info *type ) |
37a4c9b8 AJ |
172 | { |
173 | void **dest_ptr; | |
174 | ||
c62c1c01 | 175 | if (!catchblock->type_info || !catchblock->type_info->mangled[0]) return; |
37a4c9b8 AJ |
176 | if (!catchblock->offset) return; |
177 | dest_ptr = (void **)((char *)&frame->ebp + catchblock->offset); | |
178 | ||
179 | if (catchblock->flags & TYPE_FLAG_REFERENCE) | |
180 | { | |
b8d5d962 | 181 | *dest_ptr = get_this_pointer( &type->offsets, object ); |
37a4c9b8 AJ |
182 | } |
183 | else if (type->flags & CLASS_IS_SIMPLE_TYPE) | |
184 | { | |
185 | memmove( dest_ptr, object, type->size ); | |
186 | /* if it is a pointer, adjust it */ | |
b8d5d962 | 187 | if (type->size == sizeof(void *)) *dest_ptr = get_this_pointer( &type->offsets, *dest_ptr ); |
37a4c9b8 AJ |
188 | } |
189 | else /* copy the object */ | |
190 | { | |
191 | if (type->copy_ctor) | |
b8d5d962 | 192 | call_copy_ctor( type->copy_ctor, dest_ptr, get_this_pointer(&type->offsets,object), |
37a4c9b8 AJ |
193 | (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) ); |
194 | else | |
b8d5d962 | 195 | memmove( dest_ptr, get_this_pointer(&type->offsets,object), type->size ); |
37a4c9b8 AJ |
196 | } |
197 | } | |
198 | ||
199 | /* unwind the local function up to a given trylevel */ | |
8592c4b8 | 200 | static void cxx_local_unwind( cxx_exception_frame* frame, const cxx_function_descr *descr, int last_level) |
37a4c9b8 | 201 | { |
5af33ee0 | 202 | void (*handler)(void); |
37a4c9b8 AJ |
203 | int trylevel = frame->trylevel; |
204 | ||
205 | while (trylevel != last_level) | |
206 | { | |
207 | if (trylevel < 0 || trylevel >= descr->unwind_count) | |
208 | { | |
209 | ERR( "invalid trylevel %d\n", trylevel ); | |
210 | MSVCRT_terminate(); | |
211 | } | |
212 | handler = descr->unwind_table[trylevel].handler; | |
213 | if (handler) | |
214 | { | |
215 | TRACE( "calling unwind handler %p trylevel %d last %d ebp %p\n", | |
216 | handler, trylevel, last_level, &frame->ebp ); | |
217 | call_ebp_func( handler, &frame->ebp ); | |
218 | } | |
219 | trylevel = descr->unwind_table[trylevel].prev; | |
220 | } | |
221 | frame->trylevel = last_level; | |
222 | } | |
223 | ||
5ad69f19 AJ |
224 | /* exception frame for nested exceptions in catch block */ |
225 | struct catch_func_nested_frame | |
226 | { | |
ee106783 AJ |
227 | EXCEPTION_REGISTRATION_RECORD frame; /* standard exception frame */ |
228 | EXCEPTION_RECORD *prev_rec; /* previous record to restore in thread data */ | |
229 | cxx_exception_frame *cxx_frame; /* frame of parent exception */ | |
8592c4b8 | 230 | const cxx_function_descr *descr; /* descriptor of parent exception */ |
ee106783 | 231 | int trylevel; /* current try level */ |
be07b6db | 232 | EXCEPTION_RECORD *rec; /* rec associated with frame */ |
5ad69f19 AJ |
233 | }; |
234 | ||
235 | /* handler for exceptions happening while calling a catch function */ | |
ee106783 AJ |
236 | static DWORD catch_function_nested_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame, |
237 | CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher ) | |
5ad69f19 AJ |
238 | { |
239 | struct catch_func_nested_frame *nested_frame = (struct catch_func_nested_frame *)frame; | |
240 | ||
241 | if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)) | |
242 | { | |
243 | msvcrt_get_thread_data()->exc_record = nested_frame->prev_rec; | |
244 | return ExceptionContinueSearch; | |
245 | } | |
62dc7f52 PB |
246 | |
247 | TRACE( "got nested exception in catch function\n" ); | |
248 | ||
249 | if(rec->ExceptionCode == CXX_EXCEPTION) | |
5ad69f19 | 250 | { |
be07b6db | 251 | PEXCEPTION_RECORD prev_rec = nested_frame->rec; |
62dc7f52 PB |
252 | if(rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0) |
253 | { | |
254 | /* exception was rethrown */ | |
255 | rec->ExceptionInformation[1] = prev_rec->ExceptionInformation[1]; | |
256 | rec->ExceptionInformation[2] = prev_rec->ExceptionInformation[2]; | |
257 | TRACE("detect rethrow: re-propagate: obj: %lx, type: %lx\n", | |
258 | rec->ExceptionInformation[1], rec->ExceptionInformation[2]); | |
259 | } | |
260 | else { | |
261 | /* new exception in exception handler, destroy old */ | |
262 | void *object = (void*)prev_rec->ExceptionInformation[1]; | |
263 | cxx_exception_type *info = (cxx_exception_type*) prev_rec->ExceptionInformation[2]; | |
264 | TRACE("detect threw new exception in catch block - destroy old(obj: %p type: %p)\n", | |
265 | object, info); | |
266 | if(info && info->destructor) | |
267 | call_dtor( info->destructor, object ); | |
268 | } | |
5ad69f19 | 269 | } |
62dc7f52 PB |
270 | |
271 | return cxx_frame_handler( rec, nested_frame->cxx_frame, context, | |
272 | NULL, nested_frame->descr, &nested_frame->frame, | |
273 | nested_frame->trylevel ); | |
5ad69f19 AJ |
274 | } |
275 | ||
37a4c9b8 AJ |
276 | /* find and call the appropriate catch block for an exception */ |
277 | /* returns the address to continue execution to after the catch block was called */ | |
7b103480 | 278 | static inline void call_catch_block( PEXCEPTION_RECORD rec, cxx_exception_frame *frame, |
8592c4b8 | 279 | const cxx_function_descr *descr, int nested_trylevel, |
abb170fa | 280 | cxx_exception_type *info ) |
37a4c9b8 | 281 | { |
c62c1c01 JG |
282 | UINT i; |
283 | int j; | |
916c4b6b | 284 | void *addr, *object = (void *)rec->ExceptionInformation[1]; |
5ad69f19 AJ |
285 | struct catch_func_nested_frame nested_frame; |
286 | int trylevel = frame->trylevel; | |
03774624 | 287 | thread_data_t *thread_data = msvcrt_get_thread_data(); |
82818284 | 288 | DWORD save_esp = ((DWORD*)frame)[-1]; |
37a4c9b8 AJ |
289 | |
290 | for (i = 0; i < descr->tryblock_count; i++) | |
291 | { | |
8592c4b8 | 292 | const tryblock_info *tryblock = &descr->tryblock[i]; |
37a4c9b8 AJ |
293 | |
294 | if (trylevel < tryblock->start_level) continue; | |
295 | if (trylevel > tryblock->end_level) continue; | |
296 | ||
297 | /* got a try block */ | |
298 | for (j = 0; j < tryblock->catchblock_count; j++) | |
299 | { | |
8592c4b8 | 300 | const catchblock_info *catchblock = &tryblock->catchblock[j]; |
78ea87c5 PB |
301 | if(info) |
302 | { | |
303 | const cxx_type_info *type = find_caught_type( info, catchblock ); | |
304 | if (!type) continue; | |
305 | ||
306 | TRACE( "matched type %p in tryblock %d catchblock %d\n", type, i, j ); | |
307 | ||
308 | /* copy the exception to its destination on the stack */ | |
309 | copy_exception( object, frame, catchblock, type ); | |
310 | } | |
311 | else | |
312 | { | |
313 | /* no CXX_EXCEPTION only proceed with a catch(...) block*/ | |
314 | if(catchblock->type_info) | |
315 | continue; | |
316 | TRACE("found catch(...) block\n"); | |
317 | } | |
37a4c9b8 AJ |
318 | |
319 | /* unwind the stack */ | |
5ad69f19 | 320 | RtlUnwind( frame, 0, rec, 0 ); |
37a4c9b8 AJ |
321 | cxx_local_unwind( frame, descr, tryblock->start_level ); |
322 | frame->trylevel = tryblock->end_level + 1; | |
323 | ||
324 | /* call the catch block */ | |
78ea87c5 PB |
325 | TRACE( "calling catch block %p addr %p ebp %p\n", |
326 | catchblock, catchblock->handler, &frame->ebp ); | |
5ad69f19 AJ |
327 | |
328 | /* setup an exception block for nested exceptions */ | |
329 | ||
330 | nested_frame.frame.Handler = catch_function_nested_handler; | |
331 | nested_frame.prev_rec = thread_data->exc_record; | |
332 | nested_frame.cxx_frame = frame; | |
333 | nested_frame.descr = descr; | |
334 | nested_frame.trylevel = nested_trylevel + 1; | |
be07b6db | 335 | nested_frame.rec = rec; |
5ad69f19 AJ |
336 | |
337 | __wine_push_frame( &nested_frame.frame ); | |
338 | thread_data->exc_record = rec; | |
37a4c9b8 | 339 | addr = call_ebp_func( catchblock->handler, &frame->ebp ); |
5ad69f19 AJ |
340 | thread_data->exc_record = nested_frame.prev_rec; |
341 | __wine_pop_frame( &nested_frame.frame ); | |
342 | ||
82818284 | 343 | ((DWORD*)frame)[-1] = save_esp; |
78ea87c5 | 344 | if (info && info->destructor) call_dtor( info->destructor, object ); |
37a4c9b8 | 345 | TRACE( "done, continuing at %p\n", addr ); |
916c4b6b | 346 | |
abb170fa | 347 | continue_after_catch( frame, addr ); |
37a4c9b8 AJ |
348 | } |
349 | } | |
37a4c9b8 AJ |
350 | } |
351 | ||
352 | ||
353 | /********************************************************************* | |
354 | * cxx_frame_handler | |
355 | * | |
356 | * Implementation of __CxxFrameHandler. | |
357 | */ | |
24beabfd AJ |
358 | DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame, |
359 | PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch, | |
8592c4b8 AJ |
360 | const cxx_function_descr *descr, |
361 | EXCEPTION_REGISTRATION_RECORD* nested_frame, | |
24beabfd | 362 | int nested_trylevel ) |
37a4c9b8 AJ |
363 | { |
364 | cxx_exception_type *exc_type; | |
37a4c9b8 AJ |
365 | |
366 | if (descr->magic != CXX_FRAME_MAGIC) | |
367 | { | |
368 | ERR( "invalid frame magic %x\n", descr->magic ); | |
369 | return ExceptionContinueSearch; | |
370 | } | |
371 | if (rec->ExceptionFlags & (EH_UNWINDING|EH_EXIT_UNWIND)) | |
372 | { | |
5ad69f19 | 373 | if (descr->unwind_count && !nested_trylevel) cxx_local_unwind( frame, descr, -1 ); |
37a4c9b8 AJ |
374 | return ExceptionContinueSearch; |
375 | } | |
376 | if (!descr->tryblock_count) return ExceptionContinueSearch; | |
377 | ||
78ea87c5 | 378 | if(rec->ExceptionCode == CXX_EXCEPTION) |
5ad69f19 | 379 | { |
5ad69f19 | 380 | exc_type = (cxx_exception_type *)rec->ExceptionInformation[2]; |
37a4c9b8 | 381 | |
78ea87c5 PB |
382 | if (rec->ExceptionInformation[0] > CXX_FRAME_MAGIC && |
383 | exc_type->custom_handler) | |
384 | { | |
abb170fa | 385 | return exc_type->custom_handler( rec, frame, context, dispatch, |
78ea87c5 PB |
386 | descr, nested_trylevel, nested_frame, 0 ); |
387 | } | |
62dc7f52 | 388 | |
78ea87c5 PB |
389 | if (TRACE_ON(seh)) |
390 | { | |
391 | TRACE("handling C++ exception rec %p frame %p trylevel %d descr %p nested_frame %p\n", | |
392 | rec, frame, frame->trylevel, descr, nested_frame ); | |
393 | dump_exception_type( exc_type ); | |
8592c4b8 | 394 | dump_function_descr( descr ); |
78ea87c5 PB |
395 | } |
396 | } | |
397 | else | |
37a4c9b8 | 398 | { |
78ea87c5 | 399 | exc_type = NULL; |
6520ee04 | 400 | TRACE("handling C exception code %x rec %p frame %p trylevel %d descr %p nested_frame %p\n", |
78ea87c5 | 401 | rec->ExceptionCode, rec, frame, frame->trylevel, descr, nested_frame ); |
37a4c9b8 AJ |
402 | } |
403 | ||
abb170fa AJ |
404 | call_catch_block( rec, frame, descr, frame->trylevel, exc_type ); |
405 | return ExceptionContinueSearch; | |
37a4c9b8 AJ |
406 | } |
407 | ||
408 | ||
409 | /********************************************************************* | |
410 | * __CxxFrameHandler (MSVCRT.@) | |
411 | */ | |
24beabfd AJ |
412 | extern DWORD CDECL __CxxFrameHandler( PEXCEPTION_RECORD rec, EXCEPTION_REGISTRATION_RECORD* frame, |
413 | PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch ); | |
abb170fa AJ |
414 | __ASM_GLOBAL_FUNC( __CxxFrameHandler, |
415 | "pushl $0\n\t" /* nested_trylevel */ | |
0cb406ef | 416 | __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") |
abb170fa | 417 | "pushl $0\n\t" /* nested_frame */ |
0cb406ef | 418 | __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") |
abb170fa | 419 | "pushl %eax\n\t" /* descr */ |
0cb406ef | 420 | __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") |
abb170fa | 421 | "pushl 28(%esp)\n\t" /* dispatch */ |
0cb406ef | 422 | __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") |
abb170fa | 423 | "pushl 28(%esp)\n\t" /* context */ |
0cb406ef | 424 | __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") |
abb170fa | 425 | "pushl 28(%esp)\n\t" /* frame */ |
0cb406ef | 426 | __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") |
abb170fa | 427 | "pushl 28(%esp)\n\t" /* rec */ |
0cb406ef | 428 | __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") |
abb170fa AJ |
429 | "call " __ASM_NAME("cxx_frame_handler") "\n\t" |
430 | "add $28,%esp\n\t" | |
0cb406ef | 431 | __ASM_CFI(".cfi_adjust_cfa_offset -28\n\t") |
2319999a | 432 | "ret" ) |
37a4c9b8 | 433 | |
0689e9ea AJ |
434 | |
435 | /********************************************************************* | |
436 | * __CxxLongjmpUnwind (MSVCRT.@) | |
437 | * | |
438 | * Callback meant to be used as UnwindFunc for setjmp/longjmp. | |
439 | */ | |
440 | void __stdcall __CxxLongjmpUnwind( const struct MSVCRT___JUMP_BUFFER *buf ) | |
441 | { | |
442 | cxx_exception_frame *frame = (cxx_exception_frame *)buf->Registration; | |
443 | const cxx_function_descr *descr = (const cxx_function_descr *)buf->UnwindData[0]; | |
444 | ||
445 | TRACE( "unwinding frame %p descr %p trylevel %ld\n", frame, descr, buf->TryLevel ); | |
446 | cxx_local_unwind( frame, descr, buf->TryLevel ); | |
447 | } | |
448 | ||
37a4c9b8 AJ |
449 | #endif /* __i386__ */ |
450 | ||
a6d7b6fc AJ |
451 | |
452 | /********************************************************************* | |
453 | * __CppXcptFilter (MSVCRT.@) | |
454 | */ | |
455 | int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr) | |
456 | { | |
457 | /* only filter c++ exceptions */ | |
458 | if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH; | |
459 | return _XcptFilter( ex, ptr ); | |
460 | } | |
461 | ||
37a4c9b8 AJ |
462 | /********************************************************************* |
463 | * _CxxThrowException (MSVCRT.@) | |
464 | */ | |
24beabfd | 465 | void CDECL _CxxThrowException( exception *object, const cxx_exception_type *type ) |
37a4c9b8 | 466 | { |
261e3764 | 467 | ULONG_PTR args[3]; |
37a4c9b8 AJ |
468 | |
469 | args[0] = CXX_FRAME_MAGIC; | |
261e3764 AJ |
470 | args[1] = (ULONG_PTR)object; |
471 | args[2] = (ULONG_PTR)type; | |
37a4c9b8 AJ |
472 | RaiseException( CXX_EXCEPTION, EH_NONCONTINUABLE, 3, args ); |
473 | } | |
c62c1c01 JG |
474 | |
475 | /********************************************************************* | |
476 | * __CxxDetectRethrow (MSVCRT.@) | |
477 | */ | |
24beabfd | 478 | BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs) |
c62c1c01 JG |
479 | { |
480 | PEXCEPTION_RECORD rec; | |
481 | ||
482 | if (!ptrs) | |
483 | return FALSE; | |
484 | ||
485 | rec = ptrs->ExceptionRecord; | |
486 | ||
487 | if (rec->ExceptionCode == CXX_EXCEPTION && | |
488 | rec->NumberParameters == 3 && | |
489 | rec->ExceptionInformation[0] == CXX_FRAME_MAGIC && | |
490 | rec->ExceptionInformation[2]) | |
491 | { | |
492 | ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record; | |
493 | return TRUE; | |
494 | } | |
495 | return (msvcrt_get_thread_data()->exc_record == rec); | |
496 | } | |
497 | ||
498 | /********************************************************************* | |
499 | * __CxxQueryExceptionSize (MSVCRT.@) | |
500 | */ | |
24beabfd | 501 | unsigned int CDECL __CxxQueryExceptionSize(void) |
c62c1c01 JG |
502 | { |
503 | return sizeof(cxx_exception_type); | |
504 | } |