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
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcp
);
29 CREATE_TYPE_INFO_VTABLE
31 #define CLASS_IS_SIMPLE_TYPE 1
32 #define CLASS_HAS_VIRTUAL_BASE_CLASS 4
34 int* __cdecl
__processing_throw(void);
36 #if _MSVCP_VER >= 70 || defined(_MSVCIRT)
37 typedef const char **exception_name
;
38 #define EXCEPTION_STR(name) (*name)
39 #define EXCEPTION_NAME(str) (&str)
41 typedef const char *exception_name
;
42 #define EXCEPTION_STR(name) (name)
43 #define EXCEPTION_NAME(str) (str)
46 void (CDECL
*_Raise_handler
)(const exception
*) = NULL
;
49 extern const vtable_ptr exception_vtable
;
50 /* ??_7bad_alloc@std@@6B@ */
51 extern const vtable_ptr bad_alloc_vtable
;
52 /* ??_7logic_error@std@@6B@ */
53 extern const vtable_ptr logic_error_vtable
;
54 /* ??_7length_error@std@@6B@ */
55 extern const vtable_ptr length_error_vtable
;
56 /* ??_7out_of_range@std@@6B@ */
57 extern const vtable_ptr out_of_range_vtable
;
58 extern const vtable_ptr invalid_argument_vtable
;
59 /* ??_7runtime_error@std@@6B@ */
60 extern const vtable_ptr runtime_error_vtable
;
61 extern const vtable_ptr _System_error_vtable
;
62 extern const vtable_ptr system_error_vtable
;
63 extern const vtable_ptr failure_vtable
;
64 /* ??_7bad_cast@std@@6B@ */
65 extern const vtable_ptr bad_cast_vtable
;
66 /* ??_7range_error@std@@6B@ */
67 extern const vtable_ptr range_error_vtable
;
69 /* ??0exception@@QAE@ABQBD@Z */
70 /* ??0exception@@QEAA@AEBQEBD@Z */
71 DEFINE_THISCALL_WRAPPER(MSVCP_exception_ctor
,8)
72 exception
* __thiscall
MSVCP_exception_ctor(exception
*this, exception_name name
)
74 TRACE("(%p %s)\n", this, EXCEPTION_STR(name
));
76 this->vtable
= &exception_vtable
;
77 if(EXCEPTION_STR(name
)) {
78 unsigned int name_len
= strlen(EXCEPTION_STR(name
)) + 1;
79 this->name
= malloc(name_len
);
80 memcpy(this->name
, EXCEPTION_STR(name
), name_len
);
84 this->do_free
= FALSE
;
89 DEFINE_THISCALL_WRAPPER(exception_copy_ctor
,8)
90 exception
* __thiscall
exception_copy_ctor(exception
*this, const exception
*rhs
)
92 TRACE("(%p,%p)\n", this, rhs
);
95 this->vtable
= &exception_vtable
;
96 this->name
= rhs
->name
;
97 this->do_free
= FALSE
;
99 MSVCP_exception_ctor(this, (exception_name
)EXCEPTION_NAME(rhs
->name
));
100 TRACE("name = %s\n", this->name
);
104 /* ??0exception@@QAE@XZ */
105 /* ??0exception@@QEAA@XZ */
106 DEFINE_THISCALL_WRAPPER(MSVCP_exception_default_ctor
,4)
107 exception
* __thiscall
MSVCP_exception_default_ctor(exception
*this)
109 TRACE("(%p)\n", this);
110 this->vtable
= &exception_vtable
;
112 this->do_free
= FALSE
;
116 DEFINE_THISCALL_WRAPPER(MSVCP_exception_dtor
,4)
117 void __thiscall
MSVCP_exception_dtor(exception
*this)
119 TRACE("(%p)\n", this);
120 this->vtable
= &exception_vtable
;
125 DEFINE_THISCALL_WRAPPER(MSVCP_exception_vector_dtor
, 8)
126 void * __thiscall
MSVCP_exception_vector_dtor(exception
*this, unsigned int flags
)
128 TRACE("%p %x\n", this, flags
);
130 /* we have an array, with the number of elements stored before the first object */
131 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
133 for(i
=*ptr
-1; i
>=0; i
--)
134 MSVCP_exception_dtor(this+i
);
135 operator_delete(ptr
);
137 MSVCP_exception_dtor(this);
139 operator_delete(this);
145 /* ??_Gexception@@UAEPAXI@Z */
146 DEFINE_THISCALL_WRAPPER(MSVCP_exception_scalar_dtor
, 8)
147 void * __thiscall
MSVCP_exception_scalar_dtor(exception
*this, unsigned int flags
)
149 TRACE("(%p %x)\n", this, flags
);
150 MSVCP_exception_dtor(this);
151 if (flags
& 1) operator_delete(this);
155 /* ??4exception@@QAEAAV0@ABV0@@Z */
156 /* ??4exception@@QEAAAEAV0@AEBV0@@Z */
157 DEFINE_THISCALL_WRAPPER(MSVCP_exception_assign
, 8)
158 exception
* __thiscall
MSVCP_exception_assign(exception
*this, const exception
*assign
)
160 MSVCP_exception_dtor(this);
161 return exception_copy_ctor(this, assign
);
164 /* ?_Doraise@bad_alloc@std@@MBEXXZ */
165 /* ?_Doraise@bad_alloc@std@@MEBAXXZ */
166 /* ?_Doraise@logic_error@std@@MBEXXZ */
167 /* ?_Doraise@logic_error@std@@MEBAXXZ */
168 /* ?_Doraise@length_error@std@@MBEXXZ */
169 /* ?_Doraise@length_error@std@@MEBAXXZ */
170 /* ?_Doraise@out_of_range@std@@MBEXXZ */
171 /* ?_Doraise@out_of_range@std@@MEBAXXZ */
172 /* ?_Doraise@runtime_error@std@@MBEXXZ */
173 /* ?_Doraise@runtime_error@std@@MEBAXXZ */
174 /* ?_Doraise@bad_cast@std@@MBEXXZ */
175 /* ?_Doraise@bad_cast@std@@MEBAXXZ */
176 /* ?_Doraise@range_error@std@@MBEXXZ */
177 /* ?_Doraise@range_error@std@@MEBAXXZ */
178 DEFINE_THISCALL_WRAPPER(MSVCP_exception__Doraise
, 4)
179 void __thiscall
MSVCP_exception__Doraise(exception
*this)
181 FIXME("(%p) stub\n", this);
184 DEFINE_THISCALL_WRAPPER(MSVCP_exception_what
,4)
185 const char* __thiscall
MSVCP_exception_what(exception
* this)
187 TRACE("(%p) returning %s\n", this, this->name
);
188 return this->name
? this->name
: "Unknown exception";
192 DEFINE_RTTI_DATA0(exception
, 0, ".?AVexception@std@@")
194 DEFINE_RTTI_DATA0(exception
, 0, ".?AVexception@@")
196 DEFINE_CXX_DATA0(exception
, MSVCP_exception_dtor
)
198 /* bad_alloc class data */
199 typedef exception bad_alloc
;
201 /* ??0bad_alloc@std@@QAE@PBD@Z */
202 /* ??0bad_alloc@std@@QEAA@PEBD@Z */
203 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_ctor
, 8)
204 bad_alloc
* __thiscall
MSVCP_bad_alloc_ctor(bad_alloc
*this, exception_name name
)
206 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
207 MSVCP_exception_ctor(this, name
);
208 this->vtable
= &bad_alloc_vtable
;
212 /* ??0bad_alloc@std@@QAE@XZ */
213 /* ??0bad_alloc@std@@QEAA@XZ */
214 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_default_ctor
, 4)
215 bad_alloc
* __thiscall
MSVCP_bad_alloc_default_ctor(bad_alloc
*this)
217 static const char *name
= "bad allocation";
218 return MSVCP_bad_alloc_ctor(this, EXCEPTION_NAME(name
));
221 /* ??0bad_alloc@std@@QAE@ABV01@@Z */
222 /* ??0bad_alloc@std@@QEAA@AEBV01@@Z */
223 DEFINE_THISCALL_WRAPPER(bad_alloc_copy_ctor
, 8)
224 bad_alloc
* __thiscall
bad_alloc_copy_ctor(bad_alloc
*this, const bad_alloc
*rhs
)
226 TRACE("%p %p\n", this, rhs
);
227 exception_copy_ctor(this, rhs
);
228 this->vtable
= &bad_alloc_vtable
;
232 /* ??1bad_alloc@std@@UAE@XZ */
233 /* ??1bad_alloc@std@@UEAA@XZ */
234 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_dtor
, 4)
235 void __thiscall
MSVCP_bad_alloc_dtor(bad_alloc
*this)
238 MSVCP_exception_dtor(this);
241 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_vector_dtor
, 8)
242 void * __thiscall
MSVCP_bad_alloc_vector_dtor(bad_alloc
*this, unsigned int flags
)
244 TRACE("%p %x\n", this, flags
);
246 /* we have an array, with the number of elements stored before the first object */
247 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
249 for(i
=*ptr
-1; i
>=0; i
--)
250 MSVCP_bad_alloc_dtor(this+i
);
251 operator_delete(ptr
);
253 MSVCP_bad_alloc_dtor(this);
255 operator_delete(this);
261 /* ??4bad_alloc@std@@QAEAAV01@ABV01@@Z */
262 /* ??4bad_alloc@std@@QEAAAEAV01@AEBV01@@Z */
263 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_assign
, 8)
264 bad_alloc
* __thiscall
MSVCP_bad_alloc_assign(bad_alloc
*this, const bad_alloc
*assign
)
266 MSVCP_bad_alloc_dtor(this);
267 return bad_alloc_copy_ctor(this, assign
);
270 DEFINE_RTTI_DATA1(bad_alloc
, 0, &exception_rtti_base_descriptor
, ".?AVbad_alloc@std@@")
271 DEFINE_CXX_DATA1(bad_alloc
, &exception_cxx_type_info
, MSVCP_bad_alloc_dtor
)
273 /* logic_error class data */
276 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
277 basic_string_char str
;
281 /* ??0logic_error@@QAE@ABQBD@Z */
282 /* ??0logic_error@@QEAA@AEBQEBD@Z */
283 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_ctor
, 8)
284 logic_error
* __thiscall
MSVCP_logic_error_ctor( logic_error
*this, exception_name name
)
286 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
287 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
289 MSVCP_exception_ctor(&this->e
, "");
291 MSVCP_exception_default_ctor(&this->e
);
293 MSVCP_basic_string_char_ctor_cstr(&this->str
, EXCEPTION_STR(name
));
295 MSVCP_exception_ctor(&this->e
, name
);
297 this->e
.vtable
= &logic_error_vtable
;
301 /* ??0logic_error@std@@QAE@ABV01@@Z */
302 /* ??0logic_error@std@@QEAA@AEBV01@@Z */
303 DEFINE_THISCALL_WRAPPER(logic_error_copy_ctor
, 8)
304 logic_error
* __thiscall
logic_error_copy_ctor(
305 logic_error
*this, const logic_error
*rhs
)
307 TRACE("%p %p\n", this, rhs
);
308 exception_copy_ctor(&this->e
, &rhs
->e
);
309 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
310 MSVCP_basic_string_char_copy_ctor(&this->str
, &rhs
->str
);
312 this->e
.vtable
= &logic_error_vtable
;
316 /* ??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
317 /* ??0logic_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
319 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_ctor_bstr
, 8)
320 logic_error
* __thiscall
MSVCP_logic_error_ctor_bstr(logic_error
*this, const basic_string_char
*str
)
322 const char *name
= MSVCP_basic_string_char_c_str(str
);
323 TRACE("(%p %p %s)\n", this, str
, name
);
324 return MSVCP_logic_error_ctor(this, EXCEPTION_NAME(name
));
328 /* ??1logic_error@std@@UAE@XZ */
329 /* ??1logic_error@std@@UEAA@XZ */
330 /* ??1length_error@std@@UAE@XZ */
331 /* ??1length_error@std@@UEAA@XZ */
332 /* ??1out_of_range@std@@UAE@XZ */
333 /* ??1out_of_range@std@@UEAA@XZ */
334 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_dtor
, 4)
335 void __thiscall
MSVCP_logic_error_dtor(logic_error
*this)
338 MSVCP_exception_dtor(&this->e
);
339 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
340 MSVCP_basic_string_char_dtor(&this->str
);
344 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_vector_dtor
, 8)
345 void* __thiscall
MSVCP_logic_error_vector_dtor(
346 logic_error
*this, unsigned int flags
)
348 TRACE("%p %x\n", this, flags
);
350 /* we have an array, with the number of elements stored before the first object */
351 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
353 for(i
=*ptr
-1; i
>=0; i
--)
354 MSVCP_logic_error_dtor(this+i
);
355 operator_delete(ptr
);
357 MSVCP_logic_error_dtor(this);
359 operator_delete(this);
365 /* ??_Glogic_error@@UAEPAXI@Z */
366 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_scalar_dtor
, 8)
367 void * __thiscall
MSVCP_logic_error_scalar_dtor(logic_error
*this, unsigned int flags
)
369 TRACE("(%p %x)\n", this, flags
);
370 MSVCP_logic_error_dtor(this);
371 if (flags
& 1) operator_delete(this);
375 /* ??4logic_error@std@@QAEAAV01@ABV01@@Z */
376 /* ??4logic_error@std@@QEAAAEAV01@AEBV01@@Z */
377 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_assign
, 8)
378 logic_error
* __thiscall
MSVCP_logic_error_assign(logic_error
*this, const logic_error
*assign
)
380 MSVCP_logic_error_dtor(this);
381 return logic_error_copy_ctor(this, assign
);
384 /* ?what@logic_error@std@@UBEPBDXZ */
385 /* ?what@logic_error@std@@UEBAPEBDXZ */
386 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_what
, 4)
387 const char* __thiscall
MSVCP_logic_error_what(logic_error
*this)
390 #if _MSVCP_VER > 90 || defined _MSVCIRT
391 return MSVCP_exception_what( &this->e
);
393 return MSVCP_basic_string_char_c_str(&this->str
);
398 DEFINE_RTTI_DATA1(logic_error
, 0, &exception_rtti_base_descriptor
, ".?AVlogic_error@std@@")
400 DEFINE_RTTI_DATA1(logic_error
, 0, &exception_rtti_base_descriptor
, ".?AVlogic_error@@")
402 DEFINE_CXX_TYPE_INFO(logic_error
)
404 /* length_error class data */
405 typedef logic_error length_error
;
407 static length_error
* MSVCP_length_error_ctor( length_error
*this, exception_name name
)
409 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
410 MSVCP_logic_error_ctor(this, name
);
411 this->e
.vtable
= &length_error_vtable
;
415 /* ??0length_error@std@@QAE@ABV01@@Z */
416 /* ??0length_error@std@@QEAA@AEBV01@@Z */
417 DEFINE_THISCALL_WRAPPER(length_error_copy_ctor
, 8)
418 length_error
* __thiscall
length_error_copy_ctor(
419 length_error
*this, const length_error
*rhs
)
421 TRACE("%p %p\n", this, rhs
);
422 logic_error_copy_ctor(this, rhs
);
423 this->e
.vtable
= &length_error_vtable
;
427 /* ??0length_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
428 /* ??0length_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
430 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_ctor_bstr
, 8)
431 length_error
* __thiscall
MSVCP_length_error_ctor_bstr(length_error
*this, const basic_string_char
*str
)
433 const char *name
= MSVCP_basic_string_char_c_str(str
);
434 TRACE("(%p %p %s)\n", this, str
, name
);
435 return MSVCP_length_error_ctor(this, EXCEPTION_NAME(name
));
439 /* ??4length_error@std@@QAEAAV01@ABV01@@Z */
440 /* ??4length_error@std@@QEAAAEAV01@AEBV01@@Z */
441 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_assign
, 8)
442 length_error
* __thiscall
MSVCP_length_error_assign(length_error
*this, const length_error
*assign
)
444 MSVCP_logic_error_dtor(this);
445 return length_error_copy_ctor(this, assign
);
448 DEFINE_RTTI_DATA2(length_error
, 0, &logic_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
, ".?AVlength_error@std@@")
449 DEFINE_CXX_DATA2(length_error
, &logic_error_cxx_type_info
, &exception_cxx_type_info
, MSVCP_logic_error_dtor
)
451 /* out_of_range class data */
452 typedef logic_error out_of_range
;
454 static out_of_range
* MSVCP_out_of_range_ctor( out_of_range
*this, exception_name name
)
456 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
457 MSVCP_logic_error_ctor(this, name
);
458 this->e
.vtable
= &out_of_range_vtable
;
462 /* ??0out_of_range@std@@QAE@ABV01@@Z */
463 /* ??0out_of_range@std@@QEAA@AEBV01@@Z */
464 DEFINE_THISCALL_WRAPPER(out_of_range_copy_ctor
, 8)
465 out_of_range
* __thiscall
out_of_range_copy_ctor(
466 out_of_range
*this, const out_of_range
*rhs
)
468 TRACE("%p %p\n", this, rhs
);
469 logic_error_copy_ctor(this, rhs
);
470 this->e
.vtable
= &out_of_range_vtable
;
474 /* ??0out_of_range@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
475 /* ??0out_of_range@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
477 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_ctor_bstr
, 8)
478 out_of_range
* __thiscall
MSVCP_out_of_range_ctor_bstr(out_of_range
*this, const basic_string_char
*str
)
480 const char *name
= MSVCP_basic_string_char_c_str(str
);
481 TRACE("(%p %p %s)\n", this, str
, name
);
482 return MSVCP_out_of_range_ctor(this, EXCEPTION_NAME(name
));
486 /* ??4out_of_range@std@@QAEAAV01@ABV01@@Z */
487 /* ??4out_of_range@std@@QEAAAEAV01@AEBV01@@Z */
488 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_assign
, 8)
489 out_of_range
* __thiscall
MSVCP_out_of_range_assign(out_of_range
*this, const out_of_range
*assign
)
491 MSVCP_logic_error_dtor(this);
492 return out_of_range_copy_ctor(this, assign
);
495 DEFINE_RTTI_DATA2(out_of_range
, 0, &logic_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
, ".?AVout_of_range@std@@")
496 DEFINE_CXX_DATA2(out_of_range
, &logic_error_cxx_type_info
, &exception_cxx_type_info
, MSVCP_logic_error_dtor
)
498 /* invalid_argument class data */
499 typedef logic_error invalid_argument
;
501 static invalid_argument
* MSVCP_invalid_argument_ctor( invalid_argument
*this, exception_name name
)
503 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
504 MSVCP_logic_error_ctor(this, name
);
505 this->e
.vtable
= &invalid_argument_vtable
;
509 DEFINE_THISCALL_WRAPPER(invalid_argument_copy_ctor
, 8)
510 invalid_argument
* __thiscall
invalid_argument_copy_ctor(
511 invalid_argument
*this, invalid_argument
*rhs
)
513 TRACE("%p %p\n", this, rhs
);
514 logic_error_copy_ctor(this, rhs
);
515 this->e
.vtable
= &invalid_argument_vtable
;
519 DEFINE_RTTI_DATA2(invalid_argument
, 0, &logic_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
, ".?AVinvalid_argument@std@@")
520 DEFINE_CXX_DATA2(invalid_argument
, &logic_error_cxx_type_info
, &exception_cxx_type_info
, MSVCP_logic_error_dtor
)
522 /* runtime_error class data */
525 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
526 basic_string_char str
;
530 static runtime_error
* MSVCP_runtime_error_ctor( runtime_error
*this, exception_name name
)
532 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
533 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
535 MSVCP_exception_ctor(&this->e
, "");
537 MSVCP_exception_default_ctor(&this->e
);
539 MSVCP_basic_string_char_ctor_cstr(&this->str
, EXCEPTION_STR(name
));
541 MSVCP_exception_ctor(&this->e
, name
);
543 this->e
.vtable
= &runtime_error_vtable
;
547 /* ??0runtime_error@std@@QAE@ABV01@@Z */
548 /* ??0runtime_error@std@@QEAA@AEBV01@@Z */
549 DEFINE_THISCALL_WRAPPER(runtime_error_copy_ctor
, 8)
550 runtime_error
* __thiscall
runtime_error_copy_ctor(
551 runtime_error
*this, const runtime_error
*rhs
)
553 TRACE("%p %p\n", this, rhs
);
554 exception_copy_ctor(&this->e
, &rhs
->e
);
555 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
556 MSVCP_basic_string_char_copy_ctor(&this->str
, &rhs
->str
);
558 this->e
.vtable
= &runtime_error_vtable
;
562 /* ??0runtime_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
563 /* ??0runtime_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
565 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_ctor_bstr
, 8)
566 runtime_error
* __thiscall
MSVCP_runtime_error_ctor_bstr(runtime_error
*this, const basic_string_char
*str
)
568 const char *name
= MSVCP_basic_string_char_c_str(str
);
569 TRACE("(%p %p %s)\n", this, str
, name
);
570 return MSVCP_runtime_error_ctor(this, EXCEPTION_NAME(name
));
574 /* ??1runtime_error@std@@UAE@XZ */
575 /* ??1runtime_error@std@@UEAA@XZ */
576 /* ??1range_error@std@@UAE@XZ */
577 /* ??1range_error@std@@UEAA@XZ */
578 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_dtor
, 4)
579 void __thiscall
MSVCP_runtime_error_dtor(runtime_error
*this)
582 MSVCP_exception_dtor(&this->e
);
583 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
584 MSVCP_basic_string_char_dtor(&this->str
);
588 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_vector_dtor
, 8)
589 void* __thiscall
MSVCP_runtime_error_vector_dtor(
590 runtime_error
*this, unsigned int flags
)
592 TRACE("%p %x\n", this, flags
);
594 /* we have an array, with the number of elements stored before the first object */
595 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
597 for(i
=*ptr
-1; i
>=0; i
--)
598 MSVCP_runtime_error_dtor(this+i
);
599 operator_delete(ptr
);
601 MSVCP_runtime_error_dtor(this);
603 operator_delete(this);
609 /* ??4runtime_error@std@@QAEAAV01@ABV01@@Z */
610 /* ??4runtime_error@std@@QEAAAEAV01@AEBV01@@Z */
611 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_assign
, 8)
612 runtime_error
* __thiscall
MSVCP_runtime_error_assign(runtime_error
*this, const runtime_error
*assign
)
614 MSVCP_runtime_error_dtor(this);
615 return runtime_error_copy_ctor(this, assign
);
618 /* ?what@runtime_error@std@@UBEPBDXZ */
619 /* ?what@runtime_error@std@@UEBAPEBDXZ */
620 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_what
, 4)
621 const char* __thiscall
MSVCP_runtime_error_what(runtime_error
*this)
624 #if _MSVCP_VER > 90 || defined _MSVCIRT
625 return MSVCP_exception_what( &this->e
);
627 return MSVCP_basic_string_char_c_str(&this->str
);
631 DEFINE_RTTI_DATA1(runtime_error
, 0, &exception_rtti_base_descriptor
, ".?AVruntime_error@std@@")
632 DEFINE_CXX_DATA1(runtime_error
, &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
634 /* failure class data */
641 typedef system_error _System_error
;
642 typedef system_error failure
;
644 static failure
* MSVCP_failure_ctor( failure
*this, exception_name name
)
646 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
647 MSVCP_runtime_error_ctor(&this->base
, name
);
649 /* FIXME: set err correctly */
652 this->base
.e
.vtable
= &failure_vtable
;
656 DEFINE_THISCALL_WRAPPER(failure_copy_ctor
, 8)
657 failure
* __thiscall
failure_copy_ctor(
658 failure
*this, failure
*rhs
)
660 TRACE("%p %p\n", this, rhs
);
661 runtime_error_copy_ctor(&this->base
, &rhs
->base
);
663 this->err
= rhs
->err
;
665 this->base
.e
.vtable
= &failure_vtable
;
669 DEFINE_THISCALL_WRAPPER(MSVCP_failure_dtor
, 4)
670 void __thiscall
MSVCP_failure_dtor(failure
*this)
673 MSVCP_runtime_error_dtor(&this->base
);
676 DEFINE_THISCALL_WRAPPER(MSVCP_failure_vector_dtor
, 8)
677 void* __thiscall
MSVCP_failure_vector_dtor(
678 failure
*this, unsigned int flags
)
680 TRACE("%p %x\n", this, flags
);
681 return MSVCP_runtime_error_vector_dtor(&this->base
, flags
);
684 DEFINE_THISCALL_WRAPPER(MSVCP_failure_what
, 4)
685 const char* __thiscall
MSVCP_failure_what(failure
*this)
688 return MSVCP_runtime_error_what(&this->base
);
692 DEFINE_THISCALL_WRAPPER(system_error_copy_ctor
, 8)
693 system_error
* __thiscall
system_error_copy_ctor(
694 system_error
*this, system_error
*rhs
)
696 failure_copy_ctor(this, rhs
);
697 this->base
.e
.vtable
= &system_error_vtable
;
703 DEFINE_THISCALL_WRAPPER(_System_error_copy_ctor
, 8)
704 _System_error
* __thiscall
_System_error_copy_ctor(
705 _System_error
*this, _System_error
*rhs
)
707 failure_copy_ctor(this, rhs
);
708 this->base
.e
.vtable
= &_System_error_vtable
;
714 DEFINE_RTTI_DATA2(_System_error
, 0, &runtime_error_rtti_base_descriptor
,
715 &exception_rtti_base_descriptor
, ".?AV_System_error@std@@")
716 DEFINE_RTTI_DATA3(system_error
, 0, &_System_error_rtti_base_descriptor
,
717 &runtime_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
,
718 ".?AVsystem_error@std@@")
719 DEFINE_RTTI_DATA4(failure
, 0, &system_error_rtti_base_descriptor
,
720 &_System_error_rtti_base_descriptor
, &runtime_error_rtti_base_descriptor
,
721 &exception_rtti_base_descriptor
, ".?AVfailure@ios_base@std@@")
722 DEFINE_CXX_TYPE_INFO(_System_error
)
723 DEFINE_CXX_TYPE_INFO(system_error
);
724 DEFINE_CXX_DATA4(failure
, &system_error_cxx_type_info
,
725 &_System_error_cxx_type_info
, &runtime_error_cxx_type_info
,
726 &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
727 #elif _MSVCP_VER > 90
728 DEFINE_RTTI_DATA2(system_error
, 0, &runtime_error_rtti_base_descriptor
,
729 &exception_rtti_base_descriptor
, ".?AVsystem_error@std@@")
730 DEFINE_RTTI_DATA3(failure
, 0, &system_error_rtti_base_descriptor
,
731 &runtime_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
,
732 ".?AVfailure@ios_base@std@@")
733 DEFINE_CXX_TYPE_INFO(system_error
);
734 DEFINE_CXX_DATA3(failure
, &system_error_cxx_type_info
, &runtime_error_cxx_type_info
,
735 &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
737 DEFINE_RTTI_DATA2(failure
, 0, &runtime_error_rtti_base_descriptor
,
738 &exception_rtti_base_descriptor
, ".?AVfailure@ios_base@std@@")
739 DEFINE_CXX_DATA2(failure
, &runtime_error_cxx_type_info
,
740 &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
743 /* bad_cast class data */
744 typedef exception bad_cast
;
746 /* ??0bad_cast@std@@QAE@PBD@Z */
747 /* ??0bad_cast@std@@QEAA@PEBD@Z */
748 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_ctor
, 8)
749 bad_cast
* __thiscall
MSVCP_bad_cast_ctor(bad_cast
*this, const char *name
)
751 TRACE("%p %s\n", this, name
);
752 MSVCP_exception_ctor(this, EXCEPTION_NAME(name
));
753 this->vtable
= &bad_cast_vtable
;
757 /* ??_Fbad_cast@@QAEXXZ */
758 /* ??_Fbad_cast@std@@QEAAXXZ */
759 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_default_ctor
,4)
760 bad_cast
* __thiscall
MSVCP_bad_cast_default_ctor(bad_cast
*this)
762 return MSVCP_bad_cast_ctor(this, "bad cast");
765 /* ??0bad_cast@std@@QAE@ABV01@@Z */
766 /* ??0bad_cast@std@@QEAA@AEBV01@@Z */
767 DEFINE_THISCALL_WRAPPER(bad_cast_copy_ctor
, 8)
768 bad_cast
* __thiscall
bad_cast_copy_ctor(bad_cast
*this, const bad_cast
*rhs
)
770 TRACE("%p %p\n", this, rhs
);
771 exception_copy_ctor(this, rhs
);
772 this->vtable
= &bad_cast_vtable
;
776 /* ??1bad_cast@@UAE@XZ */
777 /* ??1bad_cast@std@@UEAA@XZ */
778 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_dtor
, 4)
779 void __thiscall
MSVCP_bad_cast_dtor(bad_cast
*this)
782 MSVCP_exception_dtor(this);
785 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_vector_dtor
, 8)
786 void * __thiscall
MSVCP_bad_cast_vector_dtor(bad_cast
*this, unsigned int flags
)
788 TRACE("%p %x\n", this, flags
);
790 /* we have an array, with the number of elements stored before the first object */
791 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
793 for(i
=*ptr
-1; i
>=0; i
--)
794 MSVCP_bad_cast_dtor(this+i
);
795 operator_delete(ptr
);
797 MSVCP_bad_cast_dtor(this);
799 operator_delete(this);
805 /* ??4bad_cast@std@@QAEAAV01@ABV01@@Z */
806 /* ??4bad_cast@std@@QEAAAEAV01@AEBV01@@Z */
807 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_opequals
, 8)
808 bad_cast
* __thiscall
MSVCP_bad_cast_opequals(bad_cast
*this, const bad_cast
*rhs
)
810 TRACE("(%p %p)\n", this, rhs
);
813 MSVCP_exception_dtor(this);
814 exception_copy_ctor(this, rhs
);
819 DEFINE_RTTI_DATA1(bad_cast
, 0, &exception_rtti_base_descriptor
, ".?AVbad_cast@std@@")
821 /* range_error class data */
822 typedef runtime_error range_error
;
824 static range_error
* MSVCP_range_error_ctor( range_error
*this, exception_name name
)
826 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
827 MSVCP_runtime_error_ctor(this, name
);
828 this->e
.vtable
= &range_error_vtable
;
832 /* ??0range_error@std@@QAE@ABV01@@Z */
833 /* ??0range_error@std@@QEAA@AEBV01@@Z */
834 DEFINE_THISCALL_WRAPPER(range_error_copy_ctor
, 8)
835 range_error
* __thiscall
range_error_copy_ctor(
836 range_error
*this, const range_error
*rhs
)
838 TRACE("%p %p\n", this, rhs
);
839 runtime_error_copy_ctor(this, rhs
);
840 this->e
.vtable
= &range_error_vtable
;
844 /* ??0range_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
845 /* ??0range_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
847 DEFINE_THISCALL_WRAPPER(MSVCP_range_error_ctor_bstr
, 8)
848 range_error
* __thiscall
MSVCP_range_error_ctor_bstr(range_error
*this, const basic_string_char
*str
)
850 const char *name
= MSVCP_basic_string_char_c_str(str
);
851 TRACE("(%p %p %s)\n", this, str
, name
);
852 return MSVCP_range_error_ctor(this, EXCEPTION_NAME(name
));
856 /* ??4range_error@std@@QAEAAV01@ABV01@@Z */
857 /* ??4range_error@std@@QEAAAEAV01@AEBV01@@Z */
858 DEFINE_THISCALL_WRAPPER(MSVCP_range_error_assign
, 8)
859 range_error
* __thiscall
MSVCP_range_error_assign(range_error
*this, const range_error
*assign
)
861 MSVCP_runtime_error_dtor(this);
862 return range_error_copy_ctor(this, assign
);
865 DEFINE_RTTI_DATA2(range_error
, 0, &runtime_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
, ".?AVrange_error@std@@")
866 DEFINE_CXX_DATA2(range_error
, &runtime_error_cxx_type_info
, &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
868 /* ?_Nomemory@std@@YAXXZ */
869 void __cdecl DECLSPEC_NORETURN
_Nomemory(void)
875 MSVCP_bad_alloc_default_ctor(&e
);
876 _CxxThrowException(&e
, &bad_alloc_cxx_type
);
879 /* ?_Xmem@tr1@std@@YAXXZ */
880 void __cdecl DECLSPEC_NORETURN
_Xmem(void)
886 MSVCP_bad_alloc_default_ctor(&e
);
887 _CxxThrowException(&e
, &bad_alloc_cxx_type
);
890 /* ?_Xinvalid_argument@std@@YAXPBD@Z */
891 /* ?_Xinvalid_argument@std@@YAXPEBD@Z */
892 void __cdecl DECLSPEC_NORETURN
_Xinvalid_argument(const char *str
)
894 exception_name name
= EXCEPTION_NAME(str
);
897 TRACE("(%s)\n", debugstr_a(str
));
899 MSVCP_invalid_argument_ctor(&e
, name
);
900 _CxxThrowException(&e
, &invalid_argument_cxx_type
);
903 /* ?_Xlength_error@std@@YAXPBD@Z */
904 /* ?_Xlength_error@std@@YAXPEBD@Z */
905 void __cdecl DECLSPEC_NORETURN
_Xlength_error(const char *str
)
907 exception_name name
= EXCEPTION_NAME(str
);
910 TRACE("(%s)\n", debugstr_a(str
));
912 MSVCP_length_error_ctor(&e
, name
);
913 _CxxThrowException(&e
, &length_error_cxx_type
);
916 /* ?_Xout_of_range@std@@YAXPBD@Z */
917 /* ?_Xout_of_range@std@@YAXPEBD@Z */
918 void __cdecl DECLSPEC_NORETURN
_Xout_of_range(const char *str
)
920 exception_name name
= EXCEPTION_NAME(str
);
923 TRACE("(%s)\n", debugstr_a(str
));
925 MSVCP_out_of_range_ctor(&e
, name
);
926 _CxxThrowException(&e
, &out_of_range_cxx_type
);
929 /* ?_Xruntime_error@std@@YAXPBD@Z */
930 /* ?_Xruntime_error@std@@YAXPEBD@Z */
931 void __cdecl DECLSPEC_NORETURN
_Xruntime_error(const char *str
)
933 exception_name name
= EXCEPTION_NAME(str
);
936 TRACE("(%s)\n", debugstr_a(str
));
938 MSVCP_runtime_error_ctor(&e
, name
);
939 _CxxThrowException(&e
, &runtime_error_cxx_type
);
942 /* ?uncaught_exception@std@@YA_NXZ */
943 bool __cdecl
MSVCP__uncaught_exception(void)
945 return __uncaught_exception();
948 #if _MSVCP_VER >= 140
949 int __cdecl
__uncaught_exceptions(void)
951 return *__processing_throw();
956 EXCEPTION_RECORD
*rec
;
957 LONG
*ref
; /* not binary compatible with native */
960 /*********************************************************************
961 * ?__ExceptionPtrCreate@@YAXPAX@Z
962 * ?__ExceptionPtrCreate@@YAXPEAX@Z
964 void __cdecl
__ExceptionPtrCreate(exception_ptr
*ep
)
972 #ifdef __ASM_USE_THISCALL_WRAPPER
973 extern void call_dtor(const cxx_exception_type
*type
, void *func
, void *object
);
975 __ASM_GLOBAL_FUNC( call_dtor
,
976 "movl 12(%esp),%ecx\n\t"
980 static inline void call_dtor(const cxx_exception_type
*type
, unsigned int dtor
, void *object
)
982 char *base
= RtlPcToFileHeader((void*)type
, (void**)&base
);
983 void (__cdecl
*func
)(void*) = (void*)(base
+ dtor
);
987 #define call_dtor(type, func, object) ((void (__thiscall*)(void*))(func))(object)
990 /*********************************************************************
991 * ?__ExceptionPtrDestroy@@YAXPAX@Z
992 * ?__ExceptionPtrDestroy@@YAXPEAX@Z
994 void __cdecl
__ExceptionPtrDestroy(exception_ptr
*ep
)
1001 if (!InterlockedDecrement(ep
->ref
))
1003 if (ep
->rec
->ExceptionCode
== CXX_EXCEPTION
)
1005 const cxx_exception_type
*type
= (void*)ep
->rec
->ExceptionInformation
[2];
1006 void *obj
= (void*)ep
->rec
->ExceptionInformation
[1];
1008 if (type
&& type
->destructor
) call_dtor(type
, type
->destructor
, obj
);
1009 HeapFree(GetProcessHeap(), 0, obj
);
1012 HeapFree(GetProcessHeap(), 0, ep
->rec
);
1013 HeapFree(GetProcessHeap(), 0, ep
->ref
);
1018 #if _MSVCP_VER >= 70 || defined(_MSVCIRT)
1019 #define EXCEPTION_VTABLE(name,funcs) __ASM_VTABLE(name,funcs)
1021 #define EXCEPTION_VTABLE(name,funcs) __ASM_VTABLE(name,funcs VTABLE_ADD_FUNC(MSVCP_exception__Doraise))
1024 __ASM_BLOCK_BEGIN(exception_vtables
)
1025 EXCEPTION_VTABLE(exception
,
1026 VTABLE_ADD_FUNC(MSVCP_exception_vector_dtor
)
1027 VTABLE_ADD_FUNC(MSVCP_exception_what
));
1028 EXCEPTION_VTABLE(bad_alloc
,
1029 VTABLE_ADD_FUNC(MSVCP_bad_alloc_vector_dtor
)
1030 VTABLE_ADD_FUNC(MSVCP_exception_what
));
1031 EXCEPTION_VTABLE(logic_error
,
1032 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor
)
1033 VTABLE_ADD_FUNC(MSVCP_logic_error_what
));
1034 EXCEPTION_VTABLE(length_error
,
1035 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor
)
1036 VTABLE_ADD_FUNC(MSVCP_logic_error_what
));
1037 EXCEPTION_VTABLE(out_of_range
,
1038 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor
)
1039 VTABLE_ADD_FUNC(MSVCP_logic_error_what
));
1040 EXCEPTION_VTABLE(invalid_argument
,
1041 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor
)
1042 VTABLE_ADD_FUNC(MSVCP_logic_error_what
));
1043 EXCEPTION_VTABLE(runtime_error
,
1044 VTABLE_ADD_FUNC(MSVCP_runtime_error_vector_dtor
)
1045 VTABLE_ADD_FUNC(MSVCP_runtime_error_what
));
1046 #if _MSVCP_VER > 110
1047 EXCEPTION_VTABLE(_System_error
,
1048 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor
)
1049 VTABLE_ADD_FUNC(MSVCP_failure_what
));
1052 EXCEPTION_VTABLE(system_error
,
1053 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor
)
1054 VTABLE_ADD_FUNC(MSVCP_failure_what
));
1056 EXCEPTION_VTABLE(failure
,
1057 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor
)
1058 VTABLE_ADD_FUNC(MSVCP_failure_what
));
1059 EXCEPTION_VTABLE(bad_cast
,
1060 VTABLE_ADD_FUNC(MSVCP_bad_cast_vector_dtor
)
1061 VTABLE_ADD_FUNC(MSVCP_exception_what
));
1062 EXCEPTION_VTABLE(range_error
,
1063 VTABLE_ADD_FUNC(MSVCP_runtime_error_vector_dtor
)
1064 VTABLE_ADD_FUNC(MSVCP_runtime_error_what
));
1067 /* Internal: throws exception */
1068 void DECLSPEC_NORETURN
throw_exception(const char *str
)
1070 exception_name name
= EXCEPTION_NAME(str
);
1073 MSVCP_exception_ctor(&e
, name
);
1074 _CxxThrowException(&e
, &exception_cxx_type
);
1077 /* Internal: throws range_error exception */
1078 void DECLSPEC_NORETURN
throw_range_error(const char *str
)
1080 exception_name name
= EXCEPTION_NAME(str
);
1083 MSVCP_range_error_ctor(&e
, name
);
1084 _CxxThrowException(&e
, &range_error_cxx_type
);
1087 /* Internal: throws failure exception */
1088 void DECLSPEC_NORETURN
throw_failure(const char *str
)
1090 exception_name name
= EXCEPTION_NAME(str
);
1093 MSVCP_failure_ctor(&e
, name
);
1094 _CxxThrowException(&e
, &failure_cxx_type
);
1097 void init_exception(void *base
)
1100 init_type_info_rtti(base
);
1101 init_exception_rtti(base
);
1102 init_bad_alloc_rtti(base
);
1103 init_logic_error_rtti(base
);
1104 init_length_error_rtti(base
);
1105 init_out_of_range_rtti(base
);
1106 init_invalid_argument_rtti(base
);
1107 init_runtime_error_rtti(base
);
1108 #if _MSVCP_VER > 110
1109 init__System_error_rtti(base
);
1112 init_system_error_rtti(base
);
1114 init_failure_rtti(base
);
1115 init_bad_cast_rtti(base
);
1116 init_range_error_rtti(base
);
1118 init_exception_cxx(base
);
1119 init_bad_alloc_cxx(base
);
1120 init_logic_error_cxx_type_info(base
);
1121 init_length_error_cxx(base
);
1122 init_out_of_range_cxx(base
);
1123 init_invalid_argument_cxx(base
);
1124 init_runtime_error_cxx(base
);
1125 #if _MSVCP_VER > 110
1126 init__System_error_cxx_type_info(base
);
1129 init_system_error_cxx_type_info(base
);
1131 init_failure_cxx(base
);
1132 init_range_error_cxx(base
);