d3d10/effect: Add support for 'imul' instruction.
[wine.git] / dlls / msvcp90 / exception.c
blobee59dbf2112b6d83b33a54b1b968168069c176a7
1 /*
2 * Copyright 2010 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <errno.h>
20 #include <stdarg.h>
22 #include "msvcp90.h"
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winternl.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
30 #define CXX_FRAME_MAGIC_VC6 0x19930520
32 CREATE_TYPE_INFO_VTABLE
34 #define CLASS_IS_SIMPLE_TYPE 1
35 #define CLASS_HAS_VIRTUAL_BASE_CLASS 4
37 int* __cdecl __processing_throw(void);
39 #if _MSVCP_VER >= 70 || defined(_MSVCIRT)
40 typedef const char **exception_name;
41 #define EXCEPTION_STR(name) (*name)
42 #define EXCEPTION_NAME(str) (&str)
43 #else
44 typedef const char *exception_name;
45 #define EXCEPTION_STR(name) (name)
46 #define EXCEPTION_NAME(str) (str)
47 #endif
49 void (CDECL *_Raise_handler)(const exception*) = NULL;
51 /* vtables */
52 extern const vtable_ptr exception_vtable;
53 /* ??_7bad_alloc@std@@6B@ */
54 extern const vtable_ptr bad_alloc_vtable;
55 /* ??_7logic_error@std@@6B@ */
56 extern const vtable_ptr logic_error_vtable;
57 /* ??_7length_error@std@@6B@ */
58 extern const vtable_ptr length_error_vtable;
59 /* ??_7out_of_range@std@@6B@ */
60 extern const vtable_ptr out_of_range_vtable;
61 extern const vtable_ptr invalid_argument_vtable;
62 /* ??_7runtime_error@std@@6B@ */
63 extern const vtable_ptr runtime_error_vtable;
64 extern const vtable_ptr _System_error_vtable;
65 extern const vtable_ptr system_error_vtable;
66 extern const vtable_ptr failure_vtable;
67 /* ??_7bad_cast@std@@6B@ */
68 extern const vtable_ptr bad_cast_vtable;
69 /* ??_7range_error@std@@6B@ */
70 extern const vtable_ptr range_error_vtable;
72 /* ??0exception@@QAE@ABQBD@Z */
73 /* ??0exception@@QEAA@AEBQEBD@Z */
74 DEFINE_THISCALL_WRAPPER(MSVCP_exception_ctor,8)
75 exception* __thiscall MSVCP_exception_ctor(exception *this, exception_name name)
77 TRACE("(%p %s)\n", this, EXCEPTION_STR(name));
79 this->vtable = &exception_vtable;
80 if(EXCEPTION_STR(name)) {
81 unsigned int name_len = strlen(EXCEPTION_STR(name)) + 1;
82 this->name = malloc(name_len);
83 memcpy(this->name, EXCEPTION_STR(name), name_len);
84 this->do_free = TRUE;
85 } else {
86 this->name = NULL;
87 this->do_free = FALSE;
89 return this;
92 DEFINE_THISCALL_WRAPPER(exception_copy_ctor,8)
93 exception* __thiscall exception_copy_ctor(exception *this, const exception *rhs)
95 TRACE("(%p,%p)\n", this, rhs);
97 if(!rhs->do_free) {
98 this->vtable = &exception_vtable;
99 this->name = rhs->name;
100 this->do_free = FALSE;
101 } else
102 MSVCP_exception_ctor(this, (exception_name)EXCEPTION_NAME(rhs->name));
103 TRACE("name = %s\n", this->name);
104 return this;
107 /* ??0exception@@QAE@XZ */
108 /* ??0exception@@QEAA@XZ */
109 DEFINE_THISCALL_WRAPPER(MSVCP_exception_default_ctor,4)
110 exception* __thiscall MSVCP_exception_default_ctor(exception *this)
112 TRACE("(%p)\n", this);
113 this->vtable = &exception_vtable;
114 this->name = NULL;
115 this->do_free = FALSE;
116 return this;
119 DEFINE_THISCALL_WRAPPER(MSVCP_exception_dtor,4)
120 void __thiscall MSVCP_exception_dtor(exception *this)
122 TRACE("(%p)\n", this);
123 this->vtable = &exception_vtable;
124 if(this->do_free)
125 free(this->name);
128 DEFINE_THISCALL_WRAPPER(MSVCP_exception_vector_dtor, 8)
129 void * __thiscall MSVCP_exception_vector_dtor(exception *this, unsigned int flags)
131 TRACE("%p %x\n", this, flags);
132 if(flags & 2) {
133 /* we have an array, with the number of elements stored before the first object */
134 INT_PTR i, *ptr = (INT_PTR *)this-1;
136 for(i=*ptr-1; i>=0; i--)
137 MSVCP_exception_dtor(this+i);
138 operator_delete(ptr);
139 } else {
140 MSVCP_exception_dtor(this);
141 if(flags & 1)
142 operator_delete(this);
145 return this;
148 /* ??_Gexception@@UAEPAXI@Z */
149 DEFINE_THISCALL_WRAPPER(MSVCP_exception_scalar_dtor, 8)
150 void * __thiscall MSVCP_exception_scalar_dtor(exception *this, unsigned int flags)
152 TRACE("(%p %x)\n", this, flags);
153 MSVCP_exception_dtor(this);
154 if (flags & 1) operator_delete(this);
155 return this;
158 /* ??4exception@@QAEAAV0@ABV0@@Z */
159 /* ??4exception@@QEAAAEAV0@AEBV0@@Z */
160 DEFINE_THISCALL_WRAPPER(MSVCP_exception_assign, 8)
161 exception* __thiscall MSVCP_exception_assign(exception *this, const exception *assign)
163 MSVCP_exception_dtor(this);
164 return exception_copy_ctor(this, assign);
167 /* ?_Doraise@bad_alloc@std@@MBEXXZ */
168 /* ?_Doraise@bad_alloc@std@@MEBAXXZ */
169 /* ?_Doraise@logic_error@std@@MBEXXZ */
170 /* ?_Doraise@logic_error@std@@MEBAXXZ */
171 /* ?_Doraise@length_error@std@@MBEXXZ */
172 /* ?_Doraise@length_error@std@@MEBAXXZ */
173 /* ?_Doraise@out_of_range@std@@MBEXXZ */
174 /* ?_Doraise@out_of_range@std@@MEBAXXZ */
175 /* ?_Doraise@runtime_error@std@@MBEXXZ */
176 /* ?_Doraise@runtime_error@std@@MEBAXXZ */
177 /* ?_Doraise@bad_cast@std@@MBEXXZ */
178 /* ?_Doraise@bad_cast@std@@MEBAXXZ */
179 /* ?_Doraise@range_error@std@@MBEXXZ */
180 /* ?_Doraise@range_error@std@@MEBAXXZ */
181 DEFINE_THISCALL_WRAPPER(MSVCP_exception__Doraise, 4)
182 void __thiscall MSVCP_exception__Doraise(exception *this)
184 FIXME("(%p) stub\n", this);
187 DEFINE_THISCALL_WRAPPER(MSVCP_exception_what,4)
188 const char* __thiscall MSVCP_exception_what(exception * this)
190 TRACE("(%p) returning %s\n", this, this->name);
191 return this->name ? this->name : "Unknown exception";
194 #if _MSVCP_VER >= 80
195 DEFINE_RTTI_DATA0(exception, 0, ".?AVexception@std@@")
196 #else
197 DEFINE_RTTI_DATA0(exception, 0, ".?AVexception@@")
198 #endif
199 DEFINE_CXX_DATA0(exception, MSVCP_exception_dtor)
201 /* bad_alloc class data */
202 typedef exception bad_alloc;
204 /* ??0bad_alloc@std@@QAE@PBD@Z */
205 /* ??0bad_alloc@std@@QEAA@PEBD@Z */
206 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_ctor, 8)
207 bad_alloc* __thiscall MSVCP_bad_alloc_ctor(bad_alloc *this, exception_name name)
209 TRACE("%p %s\n", this, EXCEPTION_STR(name));
210 MSVCP_exception_ctor(this, name);
211 this->vtable = &bad_alloc_vtable;
212 return this;
215 /* ??0bad_alloc@std@@QAE@XZ */
216 /* ??0bad_alloc@std@@QEAA@XZ */
217 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_default_ctor, 4)
218 bad_alloc* __thiscall MSVCP_bad_alloc_default_ctor(bad_alloc *this)
220 static const char *name = "bad allocation";
221 return MSVCP_bad_alloc_ctor(this, EXCEPTION_NAME(name));
224 /* ??0bad_alloc@std@@QAE@ABV01@@Z */
225 /* ??0bad_alloc@std@@QEAA@AEBV01@@Z */
226 DEFINE_THISCALL_WRAPPER(bad_alloc_copy_ctor, 8)
227 bad_alloc* __thiscall bad_alloc_copy_ctor(bad_alloc *this, const bad_alloc *rhs)
229 TRACE("%p %p\n", this, rhs);
230 exception_copy_ctor(this, rhs);
231 this->vtable = &bad_alloc_vtable;
232 return this;
235 /* ??1bad_alloc@std@@UAE@XZ */
236 /* ??1bad_alloc@std@@UEAA@XZ */
237 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_dtor, 4)
238 void __thiscall MSVCP_bad_alloc_dtor(bad_alloc *this)
240 TRACE("%p\n", this);
241 MSVCP_exception_dtor(this);
244 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_vector_dtor, 8)
245 void * __thiscall MSVCP_bad_alloc_vector_dtor(bad_alloc *this, unsigned int flags)
247 TRACE("%p %x\n", this, flags);
248 if(flags & 2) {
249 /* we have an array, with the number of elements stored before the first object */
250 INT_PTR i, *ptr = (INT_PTR *)this-1;
252 for(i=*ptr-1; i>=0; i--)
253 MSVCP_bad_alloc_dtor(this+i);
254 operator_delete(ptr);
255 } else {
256 MSVCP_bad_alloc_dtor(this);
257 if(flags & 1)
258 operator_delete(this);
261 return this;
264 /* ??4bad_alloc@std@@QAEAAV01@ABV01@@Z */
265 /* ??4bad_alloc@std@@QEAAAEAV01@AEBV01@@Z */
266 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_assign, 8)
267 bad_alloc* __thiscall MSVCP_bad_alloc_assign(bad_alloc *this, const bad_alloc *assign)
269 MSVCP_bad_alloc_dtor(this);
270 return bad_alloc_copy_ctor(this, assign);
273 DEFINE_RTTI_DATA1(bad_alloc, 0, &exception_rtti_base_descriptor, ".?AVbad_alloc@std@@")
274 DEFINE_CXX_DATA1(bad_alloc, &exception_cxx_type_info, MSVCP_bad_alloc_dtor)
276 /* logic_error class data */
277 typedef struct {
278 exception e;
279 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
280 basic_string_char str;
281 #endif
282 } logic_error;
284 /* ??0logic_error@@QAE@ABQBD@Z */
285 /* ??0logic_error@@QEAA@AEBQEBD@Z */
286 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_ctor, 8)
287 logic_error* __thiscall MSVCP_logic_error_ctor( logic_error *this, exception_name name )
289 TRACE("%p %s\n", this, EXCEPTION_STR(name));
290 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
291 #if _MSVCP_VER == 60
292 MSVCP_exception_ctor(&this->e, "");
293 #else
294 MSVCP_exception_default_ctor(&this->e);
295 #endif
296 MSVCP_basic_string_char_ctor_cstr(&this->str, EXCEPTION_STR(name));
297 #else
298 MSVCP_exception_ctor(&this->e, name);
299 #endif
300 this->e.vtable = &logic_error_vtable;
301 return this;
304 /* ??0logic_error@std@@QAE@ABV01@@Z */
305 /* ??0logic_error@std@@QEAA@AEBV01@@Z */
306 DEFINE_THISCALL_WRAPPER(logic_error_copy_ctor, 8)
307 logic_error* __thiscall logic_error_copy_ctor(
308 logic_error *this, const logic_error *rhs)
310 TRACE("%p %p\n", this, rhs);
311 exception_copy_ctor(&this->e, &rhs->e);
312 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
313 MSVCP_basic_string_char_copy_ctor(&this->str, &rhs->str);
314 #endif
315 this->e.vtable = &logic_error_vtable;
316 return this;
319 /* ??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
320 /* ??0logic_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
321 #ifndef _MSVCIRT
322 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_ctor_bstr, 8)
323 logic_error* __thiscall MSVCP_logic_error_ctor_bstr(logic_error *this, const basic_string_char *str)
325 const char *name = MSVCP_basic_string_char_c_str(str);
326 TRACE("(%p %p %s)\n", this, str, name);
327 return MSVCP_logic_error_ctor(this, EXCEPTION_NAME(name));
329 #endif
331 /* ??1logic_error@std@@UAE@XZ */
332 /* ??1logic_error@std@@UEAA@XZ */
333 /* ??1length_error@std@@UAE@XZ */
334 /* ??1length_error@std@@UEAA@XZ */
335 /* ??1out_of_range@std@@UAE@XZ */
336 /* ??1out_of_range@std@@UEAA@XZ */
337 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_dtor, 4)
338 void __thiscall MSVCP_logic_error_dtor(logic_error *this)
340 TRACE("%p\n", this);
341 MSVCP_exception_dtor(&this->e);
342 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
343 MSVCP_basic_string_char_dtor(&this->str);
344 #endif
347 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_vector_dtor, 8)
348 void* __thiscall MSVCP_logic_error_vector_dtor(
349 logic_error *this, unsigned int flags)
351 TRACE("%p %x\n", this, flags);
352 if(flags & 2) {
353 /* we have an array, with the number of elements stored before the first object */
354 INT_PTR i, *ptr = (INT_PTR *)this-1;
356 for(i=*ptr-1; i>=0; i--)
357 MSVCP_logic_error_dtor(this+i);
358 operator_delete(ptr);
359 } else {
360 MSVCP_logic_error_dtor(this);
361 if(flags & 1)
362 operator_delete(this);
365 return this;
368 /* ??_Glogic_error@@UAEPAXI@Z */
369 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_scalar_dtor, 8)
370 void * __thiscall MSVCP_logic_error_scalar_dtor(logic_error *this, unsigned int flags)
372 TRACE("(%p %x)\n", this, flags);
373 MSVCP_logic_error_dtor(this);
374 if (flags & 1) operator_delete(this);
375 return this;
378 /* ??4logic_error@std@@QAEAAV01@ABV01@@Z */
379 /* ??4logic_error@std@@QEAAAEAV01@AEBV01@@Z */
380 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_assign, 8)
381 logic_error* __thiscall MSVCP_logic_error_assign(logic_error *this, const logic_error *assign)
383 MSVCP_logic_error_dtor(this);
384 return logic_error_copy_ctor(this, assign);
387 /* ?what@logic_error@std@@UBEPBDXZ */
388 /* ?what@logic_error@std@@UEBAPEBDXZ */
389 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_what, 4)
390 const char* __thiscall MSVCP_logic_error_what(logic_error *this)
392 TRACE("%p\n", this);
393 #if _MSVCP_VER > 90 || defined _MSVCIRT
394 return MSVCP_exception_what( &this->e );
395 #else
396 return MSVCP_basic_string_char_c_str(&this->str);
397 #endif
400 #if _MSVCP_VER >= 80
401 DEFINE_RTTI_DATA1(logic_error, 0, &exception_rtti_base_descriptor, ".?AVlogic_error@std@@")
402 #else
403 DEFINE_RTTI_DATA1(logic_error, 0, &exception_rtti_base_descriptor, ".?AVlogic_error@@")
404 #endif
405 DEFINE_CXX_TYPE_INFO(logic_error)
407 /* length_error class data */
408 typedef logic_error length_error;
410 static length_error* MSVCP_length_error_ctor( length_error *this, exception_name name )
412 TRACE("%p %s\n", this, EXCEPTION_STR(name));
413 MSVCP_logic_error_ctor(this, name);
414 this->e.vtable = &length_error_vtable;
415 return this;
418 /* ??0length_error@std@@QAE@ABV01@@Z */
419 /* ??0length_error@std@@QEAA@AEBV01@@Z */
420 DEFINE_THISCALL_WRAPPER(length_error_copy_ctor, 8)
421 length_error* __thiscall length_error_copy_ctor(
422 length_error *this, const length_error *rhs)
424 TRACE("%p %p\n", this, rhs);
425 logic_error_copy_ctor(this, rhs);
426 this->e.vtable = &length_error_vtable;
427 return this;
430 /* ??0length_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
431 /* ??0length_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
432 #ifndef _MSVCIRT
433 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_ctor_bstr, 8)
434 length_error* __thiscall MSVCP_length_error_ctor_bstr(length_error *this, const basic_string_char *str)
436 const char *name = MSVCP_basic_string_char_c_str(str);
437 TRACE("(%p %p %s)\n", this, str, name);
438 return MSVCP_length_error_ctor(this, EXCEPTION_NAME(name));
440 #endif
442 /* ??4length_error@std@@QAEAAV01@ABV01@@Z */
443 /* ??4length_error@std@@QEAAAEAV01@AEBV01@@Z */
444 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_assign, 8)
445 length_error* __thiscall MSVCP_length_error_assign(length_error *this, const length_error *assign)
447 MSVCP_logic_error_dtor(this);
448 return length_error_copy_ctor(this, assign);
451 DEFINE_RTTI_DATA2(length_error, 0, &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVlength_error@std@@")
452 DEFINE_CXX_DATA2(length_error, &logic_error_cxx_type_info, &exception_cxx_type_info, MSVCP_logic_error_dtor)
454 /* out_of_range class data */
455 typedef logic_error out_of_range;
457 static out_of_range* MSVCP_out_of_range_ctor( out_of_range *this, exception_name name )
459 TRACE("%p %s\n", this, EXCEPTION_STR(name));
460 MSVCP_logic_error_ctor(this, name);
461 this->e.vtable = &out_of_range_vtable;
462 return this;
465 /* ??0out_of_range@std@@QAE@ABV01@@Z */
466 /* ??0out_of_range@std@@QEAA@AEBV01@@Z */
467 DEFINE_THISCALL_WRAPPER(out_of_range_copy_ctor, 8)
468 out_of_range* __thiscall out_of_range_copy_ctor(
469 out_of_range *this, const out_of_range *rhs)
471 TRACE("%p %p\n", this, rhs);
472 logic_error_copy_ctor(this, rhs);
473 this->e.vtable = &out_of_range_vtable;
474 return this;
477 /* ??0out_of_range@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
478 /* ??0out_of_range@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
479 #ifndef _MSVCIRT
480 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_ctor_bstr, 8)
481 out_of_range* __thiscall MSVCP_out_of_range_ctor_bstr(out_of_range *this, const basic_string_char *str)
483 const char *name = MSVCP_basic_string_char_c_str(str);
484 TRACE("(%p %p %s)\n", this, str, name);
485 return MSVCP_out_of_range_ctor(this, EXCEPTION_NAME(name));
487 #endif
489 /* ??4out_of_range@std@@QAEAAV01@ABV01@@Z */
490 /* ??4out_of_range@std@@QEAAAEAV01@AEBV01@@Z */
491 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_assign, 8)
492 out_of_range* __thiscall MSVCP_out_of_range_assign(out_of_range *this, const out_of_range *assign)
494 MSVCP_logic_error_dtor(this);
495 return out_of_range_copy_ctor(this, assign);
498 DEFINE_RTTI_DATA2(out_of_range, 0, &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVout_of_range@std@@")
499 DEFINE_CXX_DATA2(out_of_range, &logic_error_cxx_type_info, &exception_cxx_type_info, MSVCP_logic_error_dtor)
501 /* invalid_argument class data */
502 typedef logic_error invalid_argument;
504 static invalid_argument* MSVCP_invalid_argument_ctor( invalid_argument *this, exception_name name )
506 TRACE("%p %s\n", this, EXCEPTION_STR(name));
507 MSVCP_logic_error_ctor(this, name);
508 this->e.vtable = &invalid_argument_vtable;
509 return this;
512 DEFINE_THISCALL_WRAPPER(invalid_argument_copy_ctor, 8)
513 invalid_argument* __thiscall invalid_argument_copy_ctor(
514 invalid_argument *this, invalid_argument *rhs)
516 TRACE("%p %p\n", this, rhs);
517 logic_error_copy_ctor(this, rhs);
518 this->e.vtable = &invalid_argument_vtable;
519 return this;
522 DEFINE_RTTI_DATA2(invalid_argument, 0, &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVinvalid_argument@std@@")
523 DEFINE_CXX_DATA2(invalid_argument, &logic_error_cxx_type_info, &exception_cxx_type_info, MSVCP_logic_error_dtor)
525 /* runtime_error class data */
526 typedef struct {
527 exception e;
528 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
529 basic_string_char str;
530 #endif
531 } runtime_error;
533 static runtime_error* MSVCP_runtime_error_ctor( runtime_error *this, exception_name name )
535 TRACE("%p %s\n", this, EXCEPTION_STR(name));
536 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
537 #if _MSVCP_VER == 60
538 MSVCP_exception_ctor(&this->e, "");
539 #else
540 MSVCP_exception_default_ctor(&this->e);
541 #endif
542 MSVCP_basic_string_char_ctor_cstr(&this->str, EXCEPTION_STR(name));
543 #else
544 MSVCP_exception_ctor(&this->e, name);
545 #endif
546 this->e.vtable = &runtime_error_vtable;
547 return this;
550 /* ??0runtime_error@std@@QAE@ABV01@@Z */
551 /* ??0runtime_error@std@@QEAA@AEBV01@@Z */
552 DEFINE_THISCALL_WRAPPER(runtime_error_copy_ctor, 8)
553 runtime_error* __thiscall runtime_error_copy_ctor(
554 runtime_error *this, const runtime_error *rhs)
556 TRACE("%p %p\n", this, rhs);
557 exception_copy_ctor(&this->e, &rhs->e);
558 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
559 MSVCP_basic_string_char_copy_ctor(&this->str, &rhs->str);
560 #endif
561 this->e.vtable = &runtime_error_vtable;
562 return this;
565 /* ??0runtime_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
566 /* ??0runtime_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
567 #ifndef _MSVCIRT
568 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_ctor_bstr, 8)
569 runtime_error* __thiscall MSVCP_runtime_error_ctor_bstr(runtime_error *this, const basic_string_char *str)
571 const char *name = MSVCP_basic_string_char_c_str(str);
572 TRACE("(%p %p %s)\n", this, str, name);
573 return MSVCP_runtime_error_ctor(this, EXCEPTION_NAME(name));
575 #endif
577 /* ??1runtime_error@std@@UAE@XZ */
578 /* ??1runtime_error@std@@UEAA@XZ */
579 /* ??1range_error@std@@UAE@XZ */
580 /* ??1range_error@std@@UEAA@XZ */
581 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_dtor, 4)
582 void __thiscall MSVCP_runtime_error_dtor(runtime_error *this)
584 TRACE("%p\n", this);
585 MSVCP_exception_dtor(&this->e);
586 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
587 MSVCP_basic_string_char_dtor(&this->str);
588 #endif
591 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_vector_dtor, 8)
592 void* __thiscall MSVCP_runtime_error_vector_dtor(
593 runtime_error *this, unsigned int flags)
595 TRACE("%p %x\n", this, flags);
596 if(flags & 2) {
597 /* we have an array, with the number of elements stored before the first object */
598 INT_PTR i, *ptr = (INT_PTR *)this-1;
600 for(i=*ptr-1; i>=0; i--)
601 MSVCP_runtime_error_dtor(this+i);
602 operator_delete(ptr);
603 } else {
604 MSVCP_runtime_error_dtor(this);
605 if(flags & 1)
606 operator_delete(this);
609 return this;
612 /* ??4runtime_error@std@@QAEAAV01@ABV01@@Z */
613 /* ??4runtime_error@std@@QEAAAEAV01@AEBV01@@Z */
614 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_assign, 8)
615 runtime_error* __thiscall MSVCP_runtime_error_assign(runtime_error *this, const runtime_error *assign)
617 MSVCP_runtime_error_dtor(this);
618 return runtime_error_copy_ctor(this, assign);
621 /* ?what@runtime_error@std@@UBEPBDXZ */
622 /* ?what@runtime_error@std@@UEBAPEBDXZ */
623 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_what, 4)
624 const char* __thiscall MSVCP_runtime_error_what(runtime_error *this)
626 TRACE("%p\n", this);
627 #if _MSVCP_VER > 90 || defined _MSVCIRT
628 return MSVCP_exception_what( &this->e );
629 #else
630 return MSVCP_basic_string_char_c_str(&this->str);
631 #endif
634 DEFINE_RTTI_DATA1(runtime_error, 0, &exception_rtti_base_descriptor, ".?AVruntime_error@std@@")
635 DEFINE_CXX_DATA1(runtime_error, &exception_cxx_type_info, MSVCP_runtime_error_dtor)
637 /* failure class data */
638 typedef struct {
639 runtime_error base;
640 #if _MSVCP_VER > 90
641 error_code code;
642 #endif
643 } system_error;
644 typedef system_error _System_error;
645 typedef system_error failure;
647 static failure* MSVCP_failure_ctor( failure *this, exception_name name )
649 TRACE("%p %s\n", this, EXCEPTION_STR(name));
650 MSVCP_runtime_error_ctor(&this->base, name);
651 #if _MSVCP_VER > 90
652 this->code.code = 1;
653 this->code.category = std_iostream_category();
654 #endif
655 this->base.e.vtable = &failure_vtable;
656 return this;
659 DEFINE_THISCALL_WRAPPER(failure_copy_ctor, 8)
660 failure* __thiscall failure_copy_ctor(
661 failure *this, failure *rhs)
663 TRACE("%p %p\n", this, rhs);
664 runtime_error_copy_ctor(&this->base, &rhs->base);
665 #if _MSVCP_VER > 90
666 this->code = rhs->code;
667 #endif
668 this->base.e.vtable = &failure_vtable;
669 return this;
672 DEFINE_THISCALL_WRAPPER(MSVCP_failure_dtor, 4)
673 void __thiscall MSVCP_failure_dtor(failure *this)
675 TRACE("%p\n", this);
676 MSVCP_runtime_error_dtor(&this->base);
679 DEFINE_THISCALL_WRAPPER(MSVCP_failure_vector_dtor, 8)
680 void* __thiscall MSVCP_failure_vector_dtor(
681 failure *this, unsigned int flags)
683 TRACE("%p %x\n", this, flags);
684 return MSVCP_runtime_error_vector_dtor(&this->base, flags);
687 DEFINE_THISCALL_WRAPPER(MSVCP_failure_what, 4)
688 const char* __thiscall MSVCP_failure_what(failure *this)
690 TRACE("%p\n", this);
691 return MSVCP_runtime_error_what(&this->base);
694 #if _MSVCP_VER > 90
695 DEFINE_THISCALL_WRAPPER(system_error_copy_ctor, 8)
696 system_error* __thiscall system_error_copy_ctor(
697 system_error *this, system_error *rhs)
699 failure_copy_ctor(this, rhs);
700 this->base.e.vtable = &system_error_vtable;
701 return this;
703 #endif
705 #if _MSVCP_VER > 110
706 DEFINE_THISCALL_WRAPPER(_System_error_copy_ctor, 8)
707 _System_error* __thiscall _System_error_copy_ctor(
708 _System_error *this, _System_error *rhs)
710 failure_copy_ctor(this, rhs);
711 this->base.e.vtable = &_System_error_vtable;
712 return this;
714 #endif
716 #if _MSVCP_VER > 110
717 DEFINE_RTTI_DATA2(_System_error, 0, &runtime_error_rtti_base_descriptor,
718 &exception_rtti_base_descriptor, ".?AV_System_error@std@@")
719 DEFINE_RTTI_DATA3(system_error, 0, &_System_error_rtti_base_descriptor,
720 &runtime_error_rtti_base_descriptor, &exception_rtti_base_descriptor,
721 ".?AVsystem_error@std@@")
722 DEFINE_RTTI_DATA4(failure, 0, &system_error_rtti_base_descriptor,
723 &_System_error_rtti_base_descriptor, &runtime_error_rtti_base_descriptor,
724 &exception_rtti_base_descriptor, ".?AVfailure@ios_base@std@@")
725 DEFINE_CXX_TYPE_INFO(_System_error)
726 DEFINE_CXX_DATA3(system_error, &_System_error_cxx_type_info,
727 &runtime_error_cxx_type_info, &exception_cxx_type_info,
728 MSVCP_runtime_error_dtor)
729 DEFINE_CXX_DATA4(failure, &system_error_cxx_type_info,
730 &_System_error_cxx_type_info, &runtime_error_cxx_type_info,
731 &exception_cxx_type_info, MSVCP_runtime_error_dtor)
732 #elif _MSVCP_VER > 90
733 DEFINE_RTTI_DATA2(system_error, 0, &runtime_error_rtti_base_descriptor,
734 &exception_rtti_base_descriptor, ".?AVsystem_error@std@@")
735 DEFINE_RTTI_DATA3(failure, 0, &system_error_rtti_base_descriptor,
736 &runtime_error_rtti_base_descriptor, &exception_rtti_base_descriptor,
737 ".?AVfailure@ios_base@std@@")
738 #if _MSVCP_VER == 100
739 DEFINE_CXX_TYPE_INFO(system_error);
740 #else
741 DEFINE_CXX_DATA2(system_error, &runtime_error_cxx_type_info,
742 &exception_cxx_type_info, MSVCP_runtime_error_dtor)
743 #endif
744 DEFINE_CXX_DATA3(failure, &system_error_cxx_type_info, &runtime_error_cxx_type_info,
745 &exception_cxx_type_info, MSVCP_runtime_error_dtor)
746 #else
747 DEFINE_RTTI_DATA2(failure, 0, &runtime_error_rtti_base_descriptor,
748 &exception_rtti_base_descriptor, ".?AVfailure@ios_base@std@@")
749 DEFINE_CXX_DATA2(failure, &runtime_error_cxx_type_info,
750 &exception_cxx_type_info, MSVCP_runtime_error_dtor)
751 #endif
753 /* bad_cast class data */
754 typedef exception bad_cast;
756 /* ??0bad_cast@std@@QAE@PBD@Z */
757 /* ??0bad_cast@std@@QEAA@PEBD@Z */
758 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_ctor, 8)
759 bad_cast* __thiscall MSVCP_bad_cast_ctor(bad_cast *this, const char *name)
761 TRACE("%p %s\n", this, name);
762 MSVCP_exception_ctor(this, EXCEPTION_NAME(name));
763 this->vtable = &bad_cast_vtable;
764 return this;
767 /* ??_Fbad_cast@@QAEXXZ */
768 /* ??_Fbad_cast@std@@QEAAXXZ */
769 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_default_ctor,4)
770 bad_cast* __thiscall MSVCP_bad_cast_default_ctor(bad_cast *this)
772 return MSVCP_bad_cast_ctor(this, "bad cast");
775 /* ??0bad_cast@std@@QAE@ABV01@@Z */
776 /* ??0bad_cast@std@@QEAA@AEBV01@@Z */
777 DEFINE_THISCALL_WRAPPER(bad_cast_copy_ctor, 8)
778 bad_cast* __thiscall bad_cast_copy_ctor(bad_cast *this, const bad_cast *rhs)
780 TRACE("%p %p\n", this, rhs);
781 exception_copy_ctor(this, rhs);
782 this->vtable = &bad_cast_vtable;
783 return this;
786 /* ??1bad_cast@@UAE@XZ */
787 /* ??1bad_cast@std@@UEAA@XZ */
788 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_dtor, 4)
789 void __thiscall MSVCP_bad_cast_dtor(bad_cast *this)
791 TRACE("%p\n", this);
792 MSVCP_exception_dtor(this);
795 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_vector_dtor, 8)
796 void * __thiscall MSVCP_bad_cast_vector_dtor(bad_cast *this, unsigned int flags)
798 TRACE("%p %x\n", this, flags);
799 if(flags & 2) {
800 /* we have an array, with the number of elements stored before the first object */
801 INT_PTR i, *ptr = (INT_PTR *)this-1;
803 for(i=*ptr-1; i>=0; i--)
804 MSVCP_bad_cast_dtor(this+i);
805 operator_delete(ptr);
806 } else {
807 MSVCP_bad_cast_dtor(this);
808 if(flags & 1)
809 operator_delete(this);
812 return this;
815 /* ??4bad_cast@std@@QAEAAV01@ABV01@@Z */
816 /* ??4bad_cast@std@@QEAAAEAV01@AEBV01@@Z */
817 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_opequals, 8)
818 bad_cast* __thiscall MSVCP_bad_cast_opequals(bad_cast *this, const bad_cast *rhs)
820 TRACE("(%p %p)\n", this, rhs);
822 if(this != rhs) {
823 MSVCP_exception_dtor(this);
824 exception_copy_ctor(this, rhs);
826 return this;
829 DEFINE_RTTI_DATA1(bad_cast, 0, &exception_rtti_base_descriptor, ".?AVbad_cast@std@@")
831 /* range_error class data */
832 typedef runtime_error range_error;
834 static range_error* MSVCP_range_error_ctor( range_error *this, exception_name name )
836 TRACE("%p %s\n", this, EXCEPTION_STR(name));
837 MSVCP_runtime_error_ctor(this, name);
838 this->e.vtable = &range_error_vtable;
839 return this;
842 /* ??0range_error@std@@QAE@ABV01@@Z */
843 /* ??0range_error@std@@QEAA@AEBV01@@Z */
844 DEFINE_THISCALL_WRAPPER(range_error_copy_ctor, 8)
845 range_error* __thiscall range_error_copy_ctor(
846 range_error *this, const range_error *rhs)
848 TRACE("%p %p\n", this, rhs);
849 runtime_error_copy_ctor(this, rhs);
850 this->e.vtable = &range_error_vtable;
851 return this;
854 /* ??0range_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
855 /* ??0range_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
856 #ifndef _MSVCIRT
857 DEFINE_THISCALL_WRAPPER(MSVCP_range_error_ctor_bstr, 8)
858 range_error* __thiscall MSVCP_range_error_ctor_bstr(range_error *this, const basic_string_char *str)
860 const char *name = MSVCP_basic_string_char_c_str(str);
861 TRACE("(%p %p %s)\n", this, str, name);
862 return MSVCP_range_error_ctor(this, EXCEPTION_NAME(name));
864 #endif
866 /* ??4range_error@std@@QAEAAV01@ABV01@@Z */
867 /* ??4range_error@std@@QEAAAEAV01@AEBV01@@Z */
868 DEFINE_THISCALL_WRAPPER(MSVCP_range_error_assign, 8)
869 range_error* __thiscall MSVCP_range_error_assign(range_error *this, const range_error *assign)
871 MSVCP_runtime_error_dtor(this);
872 return range_error_copy_ctor(this, assign);
875 DEFINE_RTTI_DATA2(range_error, 0, &runtime_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVrange_error@std@@")
876 DEFINE_CXX_DATA2(range_error, &runtime_error_cxx_type_info, &exception_cxx_type_info, MSVCP_runtime_error_dtor)
878 /* ?_Nomemory@std@@YAXXZ */
879 void __cdecl DECLSPEC_NORETURN _Nomemory(void)
881 bad_alloc e;
883 TRACE("()\n");
885 MSVCP_bad_alloc_default_ctor(&e);
886 _CxxThrowException(&e, &bad_alloc_cxx_type);
889 /* ?_Xmem@tr1@std@@YAXXZ */
890 void __cdecl DECLSPEC_NORETURN _Xmem(void)
892 bad_alloc e;
894 TRACE("()\n");
896 MSVCP_bad_alloc_default_ctor(&e);
897 _CxxThrowException(&e, &bad_alloc_cxx_type);
900 /* ?_Xinvalid_argument@std@@YAXPBD@Z */
901 /* ?_Xinvalid_argument@std@@YAXPEBD@Z */
902 void __cdecl DECLSPEC_NORETURN _Xinvalid_argument(const char *str)
904 exception_name name = EXCEPTION_NAME(str);
905 invalid_argument e;
907 TRACE("(%s)\n", debugstr_a(str));
909 MSVCP_invalid_argument_ctor(&e, name);
910 _CxxThrowException(&e, &invalid_argument_cxx_type);
913 /* ?_Xlength_error@std@@YAXPBD@Z */
914 /* ?_Xlength_error@std@@YAXPEBD@Z */
915 void __cdecl DECLSPEC_NORETURN _Xlength_error(const char *str)
917 exception_name name = EXCEPTION_NAME(str);
918 length_error e;
920 TRACE("(%s)\n", debugstr_a(str));
922 MSVCP_length_error_ctor(&e, name);
923 _CxxThrowException(&e, &length_error_cxx_type);
926 /* ?_Xout_of_range@std@@YAXPBD@Z */
927 /* ?_Xout_of_range@std@@YAXPEBD@Z */
928 void __cdecl DECLSPEC_NORETURN _Xout_of_range(const char *str)
930 exception_name name = EXCEPTION_NAME(str);
931 out_of_range e;
933 TRACE("(%s)\n", debugstr_a(str));
935 MSVCP_out_of_range_ctor(&e, name);
936 _CxxThrowException(&e, &out_of_range_cxx_type);
939 /* ?_Xruntime_error@std@@YAXPBD@Z */
940 /* ?_Xruntime_error@std@@YAXPEBD@Z */
941 void __cdecl DECLSPEC_NORETURN _Xruntime_error(const char *str)
943 exception_name name = EXCEPTION_NAME(str);
944 runtime_error e;
946 TRACE("(%s)\n", debugstr_a(str));
948 MSVCP_runtime_error_ctor(&e, name);
949 _CxxThrowException(&e, &runtime_error_cxx_type);
952 /* ?uncaught_exception@std@@YA_NXZ */
953 bool __cdecl MSVCP__uncaught_exception(void)
955 return __uncaught_exception();
958 #if _MSVCP_VER >= 110
959 typedef struct
961 logic_error base;
962 error_code code;
963 } future_error;
965 extern const vtable_ptr future_error_vtable;
967 DEFINE_THISCALL_WRAPPER(future_error_copy_ctor, 8)
968 future_error* __thiscall future_error_copy_ctor(future_error *this, const future_error *rhs)
970 logic_error_copy_ctor(&this->base, &rhs->base);
971 this->code = rhs->code;
972 this->base.e.vtable = &future_error_vtable;
973 return this;
976 DEFINE_THISCALL_WRAPPER(MSVCP_future_error_what, 4)
977 const char* __thiscall MSVCP_future_error_what(future_error *this)
979 const char *names[4] = {
980 "broken promise",
981 "future already retrieved",
982 "promise already satisfied",
983 "no state",
985 #if _MSVCP_VER == 110
986 int code = this->code.code;
987 #else
988 int code = this->code.code-1;
989 #endif
990 TRACE("%p\n", this);
991 return code >= 0 && code < ARRAY_SIZE(names) ? names[code] : NULL;
994 DEFINE_RTTI_DATA3(future_error, 0, &future_error_rtti_base_descriptor,
995 &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor,
996 ".?AVfuture_error@std@@")
997 DEFINE_CXX_DATA3(future_error, &logic_error_cxx_type_info, &logic_error_cxx_type_info,
998 &exception_cxx_type_info, MSVCP_logic_error_dtor)
1000 /* ?_Throw_future_error@std@@YAXABVerror_code@1@@Z */
1001 /* ?_Throw_future_error@std@@YAXAEBVerror_code@1@@Z */
1002 void __cdecl DECLSPEC_NORETURN _Throw_future_error( const error_code *error_code )
1004 future_error e;
1005 const char *name = "";
1007 TRACE("(%p)\n", error_code);
1009 MSVCP_logic_error_ctor(&e.base, EXCEPTION_NAME(name));
1010 e.code = *error_code;
1011 e.base.e.vtable = &future_error_vtable;
1012 _CxxThrowException(&e, &future_error_cxx_type);
1015 typedef struct
1017 EXCEPTION_RECORD *rec;
1018 LONG *ref; /* not binary compatible with native */
1019 } exception_ptr;
1021 static void exception_ptr_rethrow(const exception_ptr *ep)
1023 TRACE("(%p)\n", ep);
1025 if (!ep->rec)
1027 static const char *exception_msg = "bad exception";
1028 exception e;
1030 MSVCP_exception_ctor(&e, &exception_msg);
1031 _CxxThrowException(&e, &exception_cxx_type);
1032 return;
1035 RaiseException(ep->rec->ExceptionCode, ep->rec->ExceptionFlags & (~EH_UNWINDING),
1036 ep->rec->NumberParameters, ep->rec->ExceptionInformation);
1039 /* ?_Rethrow_future_exception@std@@YAXVexception_ptr@1@@Z */
1040 void __cdecl _Rethrow_future_exception(const exception_ptr ep)
1042 exception_ptr_rethrow(&ep);
1045 /* ?_Throw_C_error@std@@YAXH@Z */
1046 void __cdecl _Throw_C_error(int code)
1048 system_error se;
1049 const char *msg;
1050 errno_t err;
1052 TRACE("(%d)\n", code);
1054 switch(code)
1056 case 1:
1057 case 2:
1058 err = EAGAIN;
1059 break;
1060 case 3:
1061 err = EBUSY;
1062 break;
1063 case 4:
1064 err = EINVAL;
1065 break;
1066 default:
1067 #if _MSVCP_VER >= 140
1068 abort();
1069 #else
1070 return;
1071 #endif
1074 msg = strerror(err);
1075 MSVCP_runtime_error_ctor(&se.base, &msg);
1076 se.code.code = err;
1077 se.code.category = std_generic_category();
1078 se.base.e.vtable = &system_error_vtable;
1080 _CxxThrowException(&se, &system_error_cxx_type);
1082 #endif
1084 #if _MSVCP_VER >= 140
1085 void** CDECL __current_exception(void);
1087 /* compute the this pointer for a base class of a given type */
1088 static inline void *get_this_pointer( const this_ptr_offsets *off, void *object )
1090 if (!object) return NULL;
1092 if (off->vbase_descr >= 0)
1094 int *offset_ptr;
1096 /* move this ptr to vbase descriptor */
1097 object = (char *)object + off->vbase_descr;
1098 /* and fetch additional offset from vbase descriptor */
1099 offset_ptr = (int *)(*(char **)object + off->vbase_offset);
1100 object = (char *)object + *offset_ptr;
1103 object = (char *)object + off->this_offset;
1104 return object;
1107 #ifdef __i386__
1108 extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase );
1109 __ASM_GLOBAL_FUNC( call_copy_ctor,
1110 "pushl %ebp\n\t"
1111 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1112 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1113 "movl %esp, %ebp\n\t"
1114 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1115 "pushl $1\n\t"
1116 "movl 12(%ebp), %ecx\n\t"
1117 "pushl 16(%ebp)\n\t"
1118 "call *8(%ebp)\n\t"
1119 "leave\n"
1120 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1121 __ASM_CFI(".cfi_same_value %ebp\n\t")
1122 "ret" );
1123 #else
1124 static inline void call_copy_ctor( void *func, void *this, void *src, int has_vbase )
1126 TRACE( "calling copy ctor %p object %p src %p\n", func, this, src );
1127 if (has_vbase)
1128 ((void (__cdecl*)(void*, void*, BOOL))func)(this, src, 1);
1129 else
1130 ((void (__cdecl*)(void*, void*))func)(this, src);
1132 #endif
1134 int __cdecl __uncaught_exceptions(void)
1136 return *__processing_throw();
1139 /*********************************************************************
1140 * ?__ExceptionPtrCreate@@YAXPAX@Z
1141 * ?__ExceptionPtrCreate@@YAXPEAX@Z
1143 void __cdecl __ExceptionPtrCreate(exception_ptr *ep)
1145 TRACE("(%p)\n", ep);
1147 ep->rec = NULL;
1148 ep->ref = NULL;
1151 #ifdef __ASM_USE_THISCALL_WRAPPER
1152 extern void call_dtor(const cxx_exception_type *type, void *func, void *object);
1154 __ASM_GLOBAL_FUNC( call_dtor,
1155 "movl 12(%esp),%ecx\n\t"
1156 "call *8(%esp)\n\t"
1157 "ret" );
1158 #elif __x86_64__
1159 static inline void call_dtor(const cxx_exception_type *type, unsigned int dtor, void *object)
1161 char *base = RtlPcToFileHeader((void*)type, (void**)&base);
1162 void (__cdecl *func)(void*) = (void*)(base + dtor);
1163 func(object);
1165 #else
1166 #define call_dtor(type, func, object) ((void (__thiscall*)(void*))(func))(object)
1167 #endif
1169 /*********************************************************************
1170 * ?__ExceptionPtrDestroy@@YAXPAX@Z
1171 * ?__ExceptionPtrDestroy@@YAXPEAX@Z
1173 void __cdecl __ExceptionPtrDestroy(exception_ptr *ep)
1175 TRACE("(%p)\n", ep);
1177 if (!ep->rec)
1178 return;
1180 if (!InterlockedDecrement(ep->ref))
1182 if (ep->rec->ExceptionCode == CXX_EXCEPTION)
1184 const cxx_exception_type *type = (void*)ep->rec->ExceptionInformation[2];
1185 void *obj = (void*)ep->rec->ExceptionInformation[1];
1187 if (type && type->destructor) call_dtor(type, type->destructor, obj);
1188 HeapFree(GetProcessHeap(), 0, obj);
1191 HeapFree(GetProcessHeap(), 0, ep->rec);
1192 HeapFree(GetProcessHeap(), 0, ep->ref);
1196 /*********************************************************************
1197 * ?__ExceptionPtrCopy@@YAXPAXPBX@Z
1198 * ?__ExceptionPtrCopy@@YAXPEAXPEBX@Z
1200 void __cdecl __ExceptionPtrCopy(exception_ptr *ep, const exception_ptr *copy)
1202 TRACE("(%p %p)\n", ep, copy);
1204 /* don't destroy object stored in ep */
1205 *ep = *copy;
1206 if (ep->ref)
1207 InterlockedIncrement(copy->ref);
1210 /*********************************************************************
1211 * ?__ExceptionPtrAssign@@YAXPAXPBX@Z
1212 * ?__ExceptionPtrAssign@@YAXPEAXPEBX@Z
1214 void __cdecl __ExceptionPtrAssign(exception_ptr *ep, const exception_ptr *assign)
1216 TRACE("(%p %p)\n", ep, assign);
1218 /* don't destroy object stored in ep */
1219 if (ep->ref)
1220 InterlockedDecrement(ep->ref);
1222 *ep = *assign;
1223 if (ep->ref)
1224 InterlockedIncrement(ep->ref);
1227 /*********************************************************************
1228 * ?__ExceptionPtrRethrow@@YAXPBX@Z
1229 * ?__ExceptionPtrRethrow@@YAXPEBX@Z
1231 void __cdecl __ExceptionPtrRethrow(const exception_ptr *ep)
1233 exception_ptr_rethrow(ep);
1236 /*********************************************************************
1237 * ?__ExceptionPtrCurrentException@@YAXPAX@Z
1238 * ?__ExceptionPtrCurrentException@@YAXPEAX@Z
1240 #ifndef __x86_64__
1241 void __cdecl __ExceptionPtrCurrentException(exception_ptr *ep)
1243 void **current_exception = __current_exception();
1244 EXCEPTION_RECORD *rec = current_exception ? *current_exception : NULL;
1246 TRACE("(%p)\n", ep);
1248 if (!rec)
1250 ep->rec = NULL;
1251 ep->ref = NULL;
1252 return;
1255 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1256 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1258 *ep->rec = *rec;
1259 *ep->ref = 1;
1261 if (ep->rec->ExceptionCode == CXX_EXCEPTION)
1263 const cxx_exception_type *et = (void*)ep->rec->ExceptionInformation[2];
1264 const cxx_type_info *ti;
1265 void **data, *obj;
1267 ti = et->type_info_table->info[0];
1268 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1270 obj = (void*)ep->rec->ExceptionInformation[1];
1271 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1273 memcpy(data, obj, ti->size);
1274 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1276 else if (ti->copy_ctor)
1278 call_copy_ctor(ti->copy_ctor, data, get_this_pointer(&ti->offsets, obj),
1279 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1281 else
1282 memcpy(data, get_this_pointer(&ti->offsets, obj), ti->size);
1283 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1285 return;
1287 #else
1288 void __cdecl __ExceptionPtrCurrentException(exception_ptr *ep)
1290 void **current_exception = __current_exception();
1291 EXCEPTION_RECORD *rec = current_exception ? *current_exception : NULL;
1293 TRACE("(%p)\n", ep);
1295 if (!rec)
1297 ep->rec = NULL;
1298 ep->ref = NULL;
1299 return;
1302 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1303 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1305 *ep->rec = *rec;
1306 *ep->ref = 1;
1308 if (ep->rec->ExceptionCode == CXX_EXCEPTION)
1310 const cxx_exception_type *et = (void*)ep->rec->ExceptionInformation[2];
1311 const cxx_type_info *ti;
1312 void **data, *obj;
1313 char *base = RtlPcToFileHeader((void*)et, (void**)&base);
1315 ti = (const cxx_type_info*)(base + ((const cxx_type_info_table*)(base + et->type_info_table))->info[0]);
1316 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1318 obj = (void*)ep->rec->ExceptionInformation[1];
1319 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1321 memcpy(data, obj, ti->size);
1322 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1324 else if (ti->copy_ctor)
1326 call_copy_ctor(base + ti->copy_ctor, data, get_this_pointer(&ti->offsets, obj),
1327 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1329 else
1330 memcpy(data, get_this_pointer(&ti->offsets, obj), ti->size);
1331 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1333 return;
1335 #endif
1337 /*********************************************************************
1338 * ?__ExceptionPtrToBool@@YA_NPBX@Z
1339 * ?__ExceptionPtrToBool@@YA_NPEBX@Z
1341 bool __cdecl __ExceptionPtrToBool(exception_ptr *ep)
1343 return !!ep->rec;
1346 /*********************************************************************
1347 * ?__ExceptionPtrCopyException@@YAXPAXPBX1@Z
1348 * ?__ExceptionPtrCopyException@@YAXPEAXPEBX1@Z
1350 #ifndef __x86_64__
1351 void __cdecl __ExceptionPtrCopyException(exception_ptr *ep,
1352 exception *object, const cxx_exception_type *type)
1354 const cxx_type_info *ti;
1355 void **data;
1357 __ExceptionPtrDestroy(ep);
1359 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1360 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1361 *ep->ref = 1;
1363 memset(ep->rec, 0, sizeof(EXCEPTION_RECORD));
1364 ep->rec->ExceptionCode = CXX_EXCEPTION;
1365 ep->rec->ExceptionFlags = EH_NONCONTINUABLE;
1366 ep->rec->NumberParameters = 3;
1367 ep->rec->ExceptionInformation[0] = CXX_FRAME_MAGIC_VC6;
1368 ep->rec->ExceptionInformation[2] = (ULONG_PTR)type;
1370 ti = type->type_info_table->info[0];
1371 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1372 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1374 memcpy(data, object, ti->size);
1375 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1377 else if (ti->copy_ctor)
1379 call_copy_ctor(ti->copy_ctor, data, get_this_pointer(&ti->offsets, object),
1380 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1382 else
1383 memcpy(data, get_this_pointer(&ti->offsets, object), ti->size);
1384 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1386 #else
1387 void __cdecl __ExceptionPtrCopyException(exception_ptr *ep,
1388 exception *object, const cxx_exception_type *type)
1390 const cxx_type_info *ti;
1391 void **data;
1392 char *base;
1394 RtlPcToFileHeader((void*)type, (void**)&base);
1395 __ExceptionPtrDestroy(ep);
1397 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1398 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1399 *ep->ref = 1;
1401 memset(ep->rec, 0, sizeof(EXCEPTION_RECORD));
1402 ep->rec->ExceptionCode = CXX_EXCEPTION;
1403 ep->rec->ExceptionFlags = EH_NONCONTINUABLE;
1404 ep->rec->NumberParameters = 4;
1405 ep->rec->ExceptionInformation[0] = CXX_FRAME_MAGIC_VC6;
1406 ep->rec->ExceptionInformation[2] = (ULONG_PTR)type;
1407 ep->rec->ExceptionInformation[3] = (ULONG_PTR)base;
1409 ti = (const cxx_type_info*)(base + ((const cxx_type_info_table*)(base + type->type_info_table))->info[0]);
1410 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1411 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1413 memcpy(data, object, ti->size);
1414 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1416 else if (ti->copy_ctor)
1418 call_copy_ctor(base + ti->copy_ctor, data, get_this_pointer(&ti->offsets, object),
1419 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1421 else
1422 memcpy(data, get_this_pointer(&ti->offsets, object), ti->size);
1423 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1425 #endif
1427 /*********************************************************************
1428 * ?__ExceptionPtrCompare@@YA_NPBX0@Z
1429 * ?__ExceptionPtrCompare@@YA_NPEBX0@Z
1431 bool __cdecl __ExceptionPtrCompare(const exception_ptr *ep1, const exception_ptr *ep2)
1433 return ep1->rec == ep2->rec;
1435 #endif
1437 #if _MSVCP_VER >= 70 || defined(_MSVCIRT)
1438 #define EXCEPTION_VTABLE(name,funcs) __ASM_VTABLE(name,funcs)
1439 #else
1440 #define EXCEPTION_VTABLE(name,funcs) __ASM_VTABLE(name,funcs VTABLE_ADD_FUNC(MSVCP_exception__Doraise))
1441 #endif
1443 __ASM_BLOCK_BEGIN(exception_vtables)
1444 EXCEPTION_VTABLE(exception,
1445 VTABLE_ADD_FUNC(MSVCP_exception_vector_dtor)
1446 VTABLE_ADD_FUNC(MSVCP_exception_what));
1447 EXCEPTION_VTABLE(bad_alloc,
1448 VTABLE_ADD_FUNC(MSVCP_bad_alloc_vector_dtor)
1449 VTABLE_ADD_FUNC(MSVCP_exception_what));
1450 EXCEPTION_VTABLE(logic_error,
1451 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
1452 VTABLE_ADD_FUNC(MSVCP_logic_error_what));
1453 EXCEPTION_VTABLE(length_error,
1454 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
1455 VTABLE_ADD_FUNC(MSVCP_logic_error_what));
1456 EXCEPTION_VTABLE(out_of_range,
1457 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
1458 VTABLE_ADD_FUNC(MSVCP_logic_error_what));
1459 EXCEPTION_VTABLE(invalid_argument,
1460 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
1461 VTABLE_ADD_FUNC(MSVCP_logic_error_what));
1462 EXCEPTION_VTABLE(runtime_error,
1463 VTABLE_ADD_FUNC(MSVCP_runtime_error_vector_dtor)
1464 VTABLE_ADD_FUNC(MSVCP_runtime_error_what));
1465 #if _MSVCP_VER >= 110
1466 EXCEPTION_VTABLE(future_error,
1467 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
1468 VTABLE_ADD_FUNC(MSVCP_future_error_what));
1469 #endif
1470 #if _MSVCP_VER > 110
1471 EXCEPTION_VTABLE(_System_error,
1472 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor)
1473 VTABLE_ADD_FUNC(MSVCP_failure_what));
1474 #endif
1475 #if _MSVCP_VER > 90
1476 EXCEPTION_VTABLE(system_error,
1477 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor)
1478 VTABLE_ADD_FUNC(MSVCP_failure_what));
1479 #endif
1480 EXCEPTION_VTABLE(failure,
1481 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor)
1482 VTABLE_ADD_FUNC(MSVCP_failure_what));
1483 EXCEPTION_VTABLE(bad_cast,
1484 VTABLE_ADD_FUNC(MSVCP_bad_cast_vector_dtor)
1485 VTABLE_ADD_FUNC(MSVCP_exception_what));
1486 EXCEPTION_VTABLE(range_error,
1487 VTABLE_ADD_FUNC(MSVCP_runtime_error_vector_dtor)
1488 VTABLE_ADD_FUNC(MSVCP_runtime_error_what));
1489 __ASM_BLOCK_END
1491 /* Internal: throws exception */
1492 void DECLSPEC_NORETURN throw_exception(const char *str)
1494 exception_name name = EXCEPTION_NAME(str);
1495 exception e;
1497 MSVCP_exception_ctor(&e, name);
1498 _CxxThrowException(&e, &exception_cxx_type);
1501 /* Internal: throws range_error exception */
1502 void DECLSPEC_NORETURN throw_range_error(const char *str)
1504 exception_name name = EXCEPTION_NAME(str);
1505 range_error e;
1507 MSVCP_range_error_ctor(&e, name);
1508 _CxxThrowException(&e, &range_error_cxx_type);
1511 /* Internal: throws failure exception */
1512 void DECLSPEC_NORETURN throw_failure(const char *str)
1514 exception_name name = EXCEPTION_NAME(str);
1515 failure e;
1517 MSVCP_failure_ctor(&e, name);
1518 _CxxThrowException(&e, &failure_cxx_type);
1521 void init_exception(void *base)
1523 #ifdef __x86_64__
1524 init_type_info_rtti(base);
1525 init_exception_rtti(base);
1526 init_bad_alloc_rtti(base);
1527 init_logic_error_rtti(base);
1528 init_length_error_rtti(base);
1529 init_out_of_range_rtti(base);
1530 init_invalid_argument_rtti(base);
1531 init_runtime_error_rtti(base);
1532 #if _MSVCP_VER >= 110
1533 init_future_error_rtti(base);
1534 #endif
1535 #if _MSVCP_VER > 110
1536 init__System_error_rtti(base);
1537 #endif
1538 #if _MSVCP_VER > 90
1539 init_system_error_rtti(base);
1540 #endif
1541 init_failure_rtti(base);
1542 init_bad_cast_rtti(base);
1543 init_range_error_rtti(base);
1545 init_exception_cxx(base);
1546 init_bad_alloc_cxx(base);
1547 init_logic_error_cxx_type_info(base);
1548 init_length_error_cxx(base);
1549 init_out_of_range_cxx(base);
1550 init_invalid_argument_cxx(base);
1551 init_runtime_error_cxx(base);
1552 #if _MSVCP_VER >= 110
1553 init_future_error_cxx(base);
1554 #endif
1555 #if _MSVCP_VER > 110
1556 init__System_error_cxx_type_info(base);
1557 #endif
1558 #if _MSVCP_VER == 100
1559 init_system_error_cxx_type_info(base);
1560 #elif _MSVCP_VER > 100
1561 init_system_error_cxx(base);
1562 #endif
1563 init_failure_cxx(base);
1564 init_range_error_cxx(base);
1565 #endif