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
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)
44 typedef const char *exception_name
;
45 #define EXCEPTION_STR(name) (name)
46 #define EXCEPTION_NAME(str) (str)
49 void (CDECL
*_Raise_handler
)(const exception
*) = NULL
;
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
;
71 /* ??_7bad_function_call@std@@6B@ */
72 extern const vtable_ptr bad_function_call_vtable
;
74 /* ??0exception@@QAE@ABQBD@Z */
75 /* ??0exception@@QEAA@AEBQEBD@Z */
76 DEFINE_THISCALL_WRAPPER(MSVCP_exception_ctor
,8)
77 exception
* __thiscall
MSVCP_exception_ctor(exception
*this, exception_name name
)
79 TRACE("(%p %s)\n", this, EXCEPTION_STR(name
));
81 this->vtable
= &exception_vtable
;
82 if(EXCEPTION_STR(name
)) {
83 unsigned int name_len
= strlen(EXCEPTION_STR(name
)) + 1;
84 this->name
= malloc(name_len
);
85 memcpy(this->name
, EXCEPTION_STR(name
), name_len
);
89 this->do_free
= FALSE
;
94 DEFINE_THISCALL_WRAPPER(exception_copy_ctor
,8)
95 exception
* __thiscall
exception_copy_ctor(exception
*this, const exception
*rhs
)
97 TRACE("(%p,%p)\n", this, rhs
);
100 this->vtable
= &exception_vtable
;
101 this->name
= rhs
->name
;
102 this->do_free
= FALSE
;
104 MSVCP_exception_ctor(this, (exception_name
)EXCEPTION_NAME(rhs
->name
));
105 TRACE("name = %s\n", this->name
);
109 /* ??0exception@@QAE@XZ */
110 /* ??0exception@@QEAA@XZ */
111 DEFINE_THISCALL_WRAPPER(MSVCP_exception_default_ctor
,4)
112 exception
* __thiscall
MSVCP_exception_default_ctor(exception
*this)
114 TRACE("(%p)\n", this);
115 this->vtable
= &exception_vtable
;
117 this->do_free
= FALSE
;
121 DEFINE_THISCALL_WRAPPER(MSVCP_exception_dtor
,4)
122 void __thiscall
MSVCP_exception_dtor(exception
*this)
124 TRACE("(%p)\n", this);
125 this->vtable
= &exception_vtable
;
130 DEFINE_THISCALL_WRAPPER(MSVCP_exception_vector_dtor
, 8)
131 void * __thiscall
MSVCP_exception_vector_dtor(exception
*this, unsigned int flags
)
133 TRACE("%p %x\n", this, flags
);
135 /* we have an array, with the number of elements stored before the first object */
136 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
138 for(i
=*ptr
-1; i
>=0; i
--)
139 MSVCP_exception_dtor(this+i
);
140 operator_delete(ptr
);
142 MSVCP_exception_dtor(this);
144 operator_delete(this);
150 /* ??_Gexception@@UAEPAXI@Z */
151 DEFINE_THISCALL_WRAPPER(MSVCP_exception_scalar_dtor
, 8)
152 void * __thiscall
MSVCP_exception_scalar_dtor(exception
*this, unsigned int flags
)
154 TRACE("(%p %x)\n", this, flags
);
155 MSVCP_exception_dtor(this);
156 if (flags
& 1) operator_delete(this);
160 /* ??4exception@@QAEAAV0@ABV0@@Z */
161 /* ??4exception@@QEAAAEAV0@AEBV0@@Z */
162 DEFINE_THISCALL_WRAPPER(MSVCP_exception_assign
, 8)
163 exception
* __thiscall
MSVCP_exception_assign(exception
*this, const exception
*assign
)
165 MSVCP_exception_dtor(this);
166 return exception_copy_ctor(this, assign
);
169 /* ?_Doraise@bad_alloc@std@@MBEXXZ */
170 /* ?_Doraise@bad_alloc@std@@MEBAXXZ */
171 /* ?_Doraise@logic_error@std@@MBEXXZ */
172 /* ?_Doraise@logic_error@std@@MEBAXXZ */
173 /* ?_Doraise@length_error@std@@MBEXXZ */
174 /* ?_Doraise@length_error@std@@MEBAXXZ */
175 /* ?_Doraise@out_of_range@std@@MBEXXZ */
176 /* ?_Doraise@out_of_range@std@@MEBAXXZ */
177 /* ?_Doraise@runtime_error@std@@MBEXXZ */
178 /* ?_Doraise@runtime_error@std@@MEBAXXZ */
179 /* ?_Doraise@bad_cast@std@@MBEXXZ */
180 /* ?_Doraise@bad_cast@std@@MEBAXXZ */
181 /* ?_Doraise@range_error@std@@MBEXXZ */
182 /* ?_Doraise@range_error@std@@MEBAXXZ */
183 DEFINE_THISCALL_WRAPPER(MSVCP_exception__Doraise
, 4)
184 void __thiscall
MSVCP_exception__Doraise(exception
*this)
186 FIXME("(%p) stub\n", this);
189 DEFINE_THISCALL_WRAPPER(MSVCP_exception_what
,4)
190 const char* __thiscall
MSVCP_exception_what(exception
* this)
192 TRACE("(%p) returning %s\n", this, this->name
);
193 return this->name
? this->name
: "Unknown exception";
197 DEFINE_RTTI_DATA0(exception
, 0, ".?AVexception@std@@")
199 DEFINE_RTTI_DATA0(exception
, 0, ".?AVexception@@")
201 DEFINE_CXX_DATA0(exception
, MSVCP_exception_dtor
)
203 /* bad_alloc class data */
204 typedef exception bad_alloc
;
206 /* ??0bad_alloc@std@@QAE@PBD@Z */
207 /* ??0bad_alloc@std@@QEAA@PEBD@Z */
208 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_ctor
, 8)
209 bad_alloc
* __thiscall
MSVCP_bad_alloc_ctor(bad_alloc
*this, exception_name name
)
211 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
212 MSVCP_exception_ctor(this, name
);
213 this->vtable
= &bad_alloc_vtable
;
217 /* ??0bad_alloc@std@@QAE@XZ */
218 /* ??0bad_alloc@std@@QEAA@XZ */
219 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_default_ctor
, 4)
220 bad_alloc
* __thiscall
MSVCP_bad_alloc_default_ctor(bad_alloc
*this)
222 static const char *name
= "bad allocation";
223 return MSVCP_bad_alloc_ctor(this, EXCEPTION_NAME(name
));
226 /* ??0bad_alloc@std@@QAE@ABV01@@Z */
227 /* ??0bad_alloc@std@@QEAA@AEBV01@@Z */
228 DEFINE_THISCALL_WRAPPER(bad_alloc_copy_ctor
, 8)
229 bad_alloc
* __thiscall
bad_alloc_copy_ctor(bad_alloc
*this, const bad_alloc
*rhs
)
231 TRACE("%p %p\n", this, rhs
);
232 exception_copy_ctor(this, rhs
);
233 this->vtable
= &bad_alloc_vtable
;
237 /* ??1bad_alloc@std@@UAE@XZ */
238 /* ??1bad_alloc@std@@UEAA@XZ */
239 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_dtor
, 4)
240 void __thiscall
MSVCP_bad_alloc_dtor(bad_alloc
*this)
243 MSVCP_exception_dtor(this);
246 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_vector_dtor
, 8)
247 void * __thiscall
MSVCP_bad_alloc_vector_dtor(bad_alloc
*this, unsigned int flags
)
249 TRACE("%p %x\n", this, flags
);
251 /* we have an array, with the number of elements stored before the first object */
252 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
254 for(i
=*ptr
-1; i
>=0; i
--)
255 MSVCP_bad_alloc_dtor(this+i
);
256 operator_delete(ptr
);
258 MSVCP_bad_alloc_dtor(this);
260 operator_delete(this);
266 /* ??4bad_alloc@std@@QAEAAV01@ABV01@@Z */
267 /* ??4bad_alloc@std@@QEAAAEAV01@AEBV01@@Z */
268 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_assign
, 8)
269 bad_alloc
* __thiscall
MSVCP_bad_alloc_assign(bad_alloc
*this, const bad_alloc
*assign
)
271 MSVCP_bad_alloc_dtor(this);
272 return bad_alloc_copy_ctor(this, assign
);
275 DEFINE_RTTI_DATA1(bad_alloc
, 0, &exception_rtti_base_descriptor
, ".?AVbad_alloc@std@@")
276 DEFINE_CXX_DATA1(bad_alloc
, &exception_cxx_type_info
, MSVCP_bad_alloc_dtor
)
278 /* logic_error class data */
281 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
282 basic_string_char str
;
286 /* ??0logic_error@@QAE@ABQBD@Z */
287 /* ??0logic_error@@QEAA@AEBQEBD@Z */
288 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_ctor
, 8)
289 logic_error
* __thiscall
MSVCP_logic_error_ctor( logic_error
*this, exception_name name
)
291 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
292 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
294 MSVCP_exception_ctor(&this->e
, "");
296 MSVCP_exception_default_ctor(&this->e
);
298 MSVCP_basic_string_char_ctor_cstr(&this->str
, EXCEPTION_STR(name
));
300 MSVCP_exception_ctor(&this->e
, name
);
302 this->e
.vtable
= &logic_error_vtable
;
306 /* ??0logic_error@std@@QAE@ABV01@@Z */
307 /* ??0logic_error@std@@QEAA@AEBV01@@Z */
308 DEFINE_THISCALL_WRAPPER(logic_error_copy_ctor
, 8)
309 logic_error
* __thiscall
logic_error_copy_ctor(
310 logic_error
*this, const logic_error
*rhs
)
312 TRACE("%p %p\n", this, rhs
);
313 exception_copy_ctor(&this->e
, &rhs
->e
);
314 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
315 MSVCP_basic_string_char_copy_ctor(&this->str
, &rhs
->str
);
317 this->e
.vtable
= &logic_error_vtable
;
321 /* ??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
322 /* ??0logic_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
324 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_ctor_bstr
, 8)
325 logic_error
* __thiscall
MSVCP_logic_error_ctor_bstr(logic_error
*this, const basic_string_char
*str
)
327 const char *name
= MSVCP_basic_string_char_c_str(str
);
328 TRACE("(%p %p %s)\n", this, str
, name
);
329 return MSVCP_logic_error_ctor(this, EXCEPTION_NAME(name
));
333 /* ??1logic_error@std@@UAE@XZ */
334 /* ??1logic_error@std@@UEAA@XZ */
335 /* ??1length_error@std@@UAE@XZ */
336 /* ??1length_error@std@@UEAA@XZ */
337 /* ??1out_of_range@std@@UAE@XZ */
338 /* ??1out_of_range@std@@UEAA@XZ */
339 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_dtor
, 4)
340 void __thiscall
MSVCP_logic_error_dtor(logic_error
*this)
343 MSVCP_exception_dtor(&this->e
);
344 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
345 MSVCP_basic_string_char_dtor(&this->str
);
349 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_vector_dtor
, 8)
350 void* __thiscall
MSVCP_logic_error_vector_dtor(
351 logic_error
*this, unsigned int flags
)
353 TRACE("%p %x\n", this, flags
);
355 /* we have an array, with the number of elements stored before the first object */
356 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
358 for(i
=*ptr
-1; i
>=0; i
--)
359 MSVCP_logic_error_dtor(this+i
);
360 operator_delete(ptr
);
362 MSVCP_logic_error_dtor(this);
364 operator_delete(this);
370 /* ??_Glogic_error@@UAEPAXI@Z */
371 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_scalar_dtor
, 8)
372 void * __thiscall
MSVCP_logic_error_scalar_dtor(logic_error
*this, unsigned int flags
)
374 TRACE("(%p %x)\n", this, flags
);
375 MSVCP_logic_error_dtor(this);
376 if (flags
& 1) operator_delete(this);
380 /* ??4logic_error@std@@QAEAAV01@ABV01@@Z */
381 /* ??4logic_error@std@@QEAAAEAV01@AEBV01@@Z */
382 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_assign
, 8)
383 logic_error
* __thiscall
MSVCP_logic_error_assign(logic_error
*this, const logic_error
*assign
)
385 MSVCP_logic_error_dtor(this);
386 return logic_error_copy_ctor(this, assign
);
389 /* ?what@logic_error@std@@UBEPBDXZ */
390 /* ?what@logic_error@std@@UEBAPEBDXZ */
391 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_what
, 4)
392 const char* __thiscall
MSVCP_logic_error_what(logic_error
*this)
395 #if _MSVCP_VER > 90 || defined _MSVCIRT
396 return MSVCP_exception_what( &this->e
);
398 return MSVCP_basic_string_char_c_str(&this->str
);
403 DEFINE_RTTI_DATA1(logic_error
, 0, &exception_rtti_base_descriptor
, ".?AVlogic_error@std@@")
405 DEFINE_RTTI_DATA1(logic_error
, 0, &exception_rtti_base_descriptor
, ".?AVlogic_error@@")
407 DEFINE_CXX_TYPE_INFO(logic_error
)
409 /* length_error class data */
410 typedef logic_error length_error
;
412 static length_error
* MSVCP_length_error_ctor( length_error
*this, exception_name name
)
414 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
415 MSVCP_logic_error_ctor(this, name
);
416 this->e
.vtable
= &length_error_vtable
;
420 /* ??0length_error@std@@QAE@ABV01@@Z */
421 /* ??0length_error@std@@QEAA@AEBV01@@Z */
422 DEFINE_THISCALL_WRAPPER(length_error_copy_ctor
, 8)
423 length_error
* __thiscall
length_error_copy_ctor(
424 length_error
*this, const length_error
*rhs
)
426 TRACE("%p %p\n", this, rhs
);
427 logic_error_copy_ctor(this, rhs
);
428 this->e
.vtable
= &length_error_vtable
;
432 /* ??0length_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
433 /* ??0length_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
435 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_ctor_bstr
, 8)
436 length_error
* __thiscall
MSVCP_length_error_ctor_bstr(length_error
*this, const basic_string_char
*str
)
438 const char *name
= MSVCP_basic_string_char_c_str(str
);
439 TRACE("(%p %p %s)\n", this, str
, name
);
440 return MSVCP_length_error_ctor(this, EXCEPTION_NAME(name
));
444 /* ??4length_error@std@@QAEAAV01@ABV01@@Z */
445 /* ??4length_error@std@@QEAAAEAV01@AEBV01@@Z */
446 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_assign
, 8)
447 length_error
* __thiscall
MSVCP_length_error_assign(length_error
*this, const length_error
*assign
)
449 MSVCP_logic_error_dtor(this);
450 return length_error_copy_ctor(this, assign
);
453 DEFINE_RTTI_DATA2(length_error
, 0, &logic_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
, ".?AVlength_error@std@@")
454 DEFINE_CXX_DATA2(length_error
, &logic_error_cxx_type_info
, &exception_cxx_type_info
, MSVCP_logic_error_dtor
)
456 /* out_of_range class data */
457 typedef logic_error out_of_range
;
459 static out_of_range
* MSVCP_out_of_range_ctor( out_of_range
*this, exception_name name
)
461 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
462 MSVCP_logic_error_ctor(this, name
);
463 this->e
.vtable
= &out_of_range_vtable
;
467 /* ??0out_of_range@std@@QAE@ABV01@@Z */
468 /* ??0out_of_range@std@@QEAA@AEBV01@@Z */
469 DEFINE_THISCALL_WRAPPER(out_of_range_copy_ctor
, 8)
470 out_of_range
* __thiscall
out_of_range_copy_ctor(
471 out_of_range
*this, const out_of_range
*rhs
)
473 TRACE("%p %p\n", this, rhs
);
474 logic_error_copy_ctor(this, rhs
);
475 this->e
.vtable
= &out_of_range_vtable
;
479 /* ??0out_of_range@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
480 /* ??0out_of_range@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
482 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_ctor_bstr
, 8)
483 out_of_range
* __thiscall
MSVCP_out_of_range_ctor_bstr(out_of_range
*this, const basic_string_char
*str
)
485 const char *name
= MSVCP_basic_string_char_c_str(str
);
486 TRACE("(%p %p %s)\n", this, str
, name
);
487 return MSVCP_out_of_range_ctor(this, EXCEPTION_NAME(name
));
491 /* ??4out_of_range@std@@QAEAAV01@ABV01@@Z */
492 /* ??4out_of_range@std@@QEAAAEAV01@AEBV01@@Z */
493 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_assign
, 8)
494 out_of_range
* __thiscall
MSVCP_out_of_range_assign(out_of_range
*this, const out_of_range
*assign
)
496 MSVCP_logic_error_dtor(this);
497 return out_of_range_copy_ctor(this, assign
);
500 DEFINE_RTTI_DATA2(out_of_range
, 0, &logic_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
, ".?AVout_of_range@std@@")
501 DEFINE_CXX_DATA2(out_of_range
, &logic_error_cxx_type_info
, &exception_cxx_type_info
, MSVCP_logic_error_dtor
)
503 /* invalid_argument class data */
504 typedef logic_error invalid_argument
;
506 static invalid_argument
* MSVCP_invalid_argument_ctor( invalid_argument
*this, exception_name name
)
508 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
509 MSVCP_logic_error_ctor(this, name
);
510 this->e
.vtable
= &invalid_argument_vtable
;
514 DEFINE_THISCALL_WRAPPER(invalid_argument_copy_ctor
, 8)
515 invalid_argument
* __thiscall
invalid_argument_copy_ctor(
516 invalid_argument
*this, invalid_argument
*rhs
)
518 TRACE("%p %p\n", this, rhs
);
519 logic_error_copy_ctor(this, rhs
);
520 this->e
.vtable
= &invalid_argument_vtable
;
524 DEFINE_RTTI_DATA2(invalid_argument
, 0, &logic_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
, ".?AVinvalid_argument@std@@")
525 DEFINE_CXX_DATA2(invalid_argument
, &logic_error_cxx_type_info
, &exception_cxx_type_info
, MSVCP_logic_error_dtor
)
527 /* runtime_error class data */
530 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
531 basic_string_char str
;
535 static runtime_error
* MSVCP_runtime_error_ctor( runtime_error
*this, exception_name name
)
537 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
538 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
540 MSVCP_exception_ctor(&this->e
, "");
542 MSVCP_exception_default_ctor(&this->e
);
544 MSVCP_basic_string_char_ctor_cstr(&this->str
, EXCEPTION_STR(name
));
546 MSVCP_exception_ctor(&this->e
, name
);
548 this->e
.vtable
= &runtime_error_vtable
;
552 /* ??0runtime_error@std@@QAE@ABV01@@Z */
553 /* ??0runtime_error@std@@QEAA@AEBV01@@Z */
554 DEFINE_THISCALL_WRAPPER(runtime_error_copy_ctor
, 8)
555 runtime_error
* __thiscall
runtime_error_copy_ctor(
556 runtime_error
*this, const runtime_error
*rhs
)
558 TRACE("%p %p\n", this, rhs
);
559 exception_copy_ctor(&this->e
, &rhs
->e
);
560 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
561 MSVCP_basic_string_char_copy_ctor(&this->str
, &rhs
->str
);
563 this->e
.vtable
= &runtime_error_vtable
;
567 /* ??0runtime_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
568 /* ??0runtime_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
570 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_ctor_bstr
, 8)
571 runtime_error
* __thiscall
MSVCP_runtime_error_ctor_bstr(runtime_error
*this, const basic_string_char
*str
)
573 const char *name
= MSVCP_basic_string_char_c_str(str
);
574 TRACE("(%p %p %s)\n", this, str
, name
);
575 return MSVCP_runtime_error_ctor(this, EXCEPTION_NAME(name
));
579 /* ??1runtime_error@std@@UAE@XZ */
580 /* ??1runtime_error@std@@UEAA@XZ */
581 /* ??1range_error@std@@UAE@XZ */
582 /* ??1range_error@std@@UEAA@XZ */
583 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_dtor
, 4)
584 void __thiscall
MSVCP_runtime_error_dtor(runtime_error
*this)
587 MSVCP_exception_dtor(&this->e
);
588 #if _MSVCP_VER <= 90 && !defined _MSVCIRT
589 MSVCP_basic_string_char_dtor(&this->str
);
593 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_vector_dtor
, 8)
594 void* __thiscall
MSVCP_runtime_error_vector_dtor(
595 runtime_error
*this, unsigned int flags
)
597 TRACE("%p %x\n", this, flags
);
599 /* we have an array, with the number of elements stored before the first object */
600 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
602 for(i
=*ptr
-1; i
>=0; i
--)
603 MSVCP_runtime_error_dtor(this+i
);
604 operator_delete(ptr
);
606 MSVCP_runtime_error_dtor(this);
608 operator_delete(this);
614 /* ??4runtime_error@std@@QAEAAV01@ABV01@@Z */
615 /* ??4runtime_error@std@@QEAAAEAV01@AEBV01@@Z */
616 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_assign
, 8)
617 runtime_error
* __thiscall
MSVCP_runtime_error_assign(runtime_error
*this, const runtime_error
*assign
)
619 MSVCP_runtime_error_dtor(this);
620 return runtime_error_copy_ctor(this, assign
);
623 /* ?what@runtime_error@std@@UBEPBDXZ */
624 /* ?what@runtime_error@std@@UEBAPEBDXZ */
625 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_what
, 4)
626 const char* __thiscall
MSVCP_runtime_error_what(runtime_error
*this)
629 #if _MSVCP_VER > 90 || defined _MSVCIRT
630 return MSVCP_exception_what( &this->e
);
632 return MSVCP_basic_string_char_c_str(&this->str
);
636 DEFINE_RTTI_DATA1(runtime_error
, 0, &exception_rtti_base_descriptor
, ".?AVruntime_error@std@@")
637 DEFINE_CXX_DATA1(runtime_error
, &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
639 /* failure class data */
646 typedef system_error _System_error
;
647 typedef system_error failure
;
649 static failure
* MSVCP_failure_ctor( failure
*this, exception_name name
)
651 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
652 MSVCP_runtime_error_ctor(&this->base
, name
);
655 this->code
.category
= std_iostream_category();
657 this->base
.e
.vtable
= &failure_vtable
;
661 DEFINE_THISCALL_WRAPPER(failure_copy_ctor
, 8)
662 failure
* __thiscall
failure_copy_ctor(
663 failure
*this, failure
*rhs
)
665 TRACE("%p %p\n", this, rhs
);
666 runtime_error_copy_ctor(&this->base
, &rhs
->base
);
668 this->code
= rhs
->code
;
670 this->base
.e
.vtable
= &failure_vtable
;
674 DEFINE_THISCALL_WRAPPER(MSVCP_failure_dtor
, 4)
675 void __thiscall
MSVCP_failure_dtor(failure
*this)
678 MSVCP_runtime_error_dtor(&this->base
);
681 DEFINE_THISCALL_WRAPPER(MSVCP_failure_vector_dtor
, 8)
682 void* __thiscall
MSVCP_failure_vector_dtor(
683 failure
*this, unsigned int flags
)
685 TRACE("%p %x\n", this, flags
);
686 return MSVCP_runtime_error_vector_dtor(&this->base
, flags
);
689 DEFINE_THISCALL_WRAPPER(MSVCP_failure_what
, 4)
690 const char* __thiscall
MSVCP_failure_what(failure
*this)
693 return MSVCP_runtime_error_what(&this->base
);
697 DEFINE_THISCALL_WRAPPER(system_error_copy_ctor
, 8)
698 system_error
* __thiscall
system_error_copy_ctor(
699 system_error
*this, system_error
*rhs
)
701 failure_copy_ctor(this, rhs
);
702 this->base
.e
.vtable
= &system_error_vtable
;
708 DEFINE_THISCALL_WRAPPER(_System_error_copy_ctor
, 8)
709 _System_error
* __thiscall
_System_error_copy_ctor(
710 _System_error
*this, _System_error
*rhs
)
712 failure_copy_ctor(this, rhs
);
713 this->base
.e
.vtable
= &_System_error_vtable
;
719 DEFINE_RTTI_DATA2(_System_error
, 0, &runtime_error_rtti_base_descriptor
,
720 &exception_rtti_base_descriptor
, ".?AV_System_error@std@@")
721 DEFINE_RTTI_DATA3(system_error
, 0, &_System_error_rtti_base_descriptor
,
722 &runtime_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
,
723 ".?AVsystem_error@std@@")
724 DEFINE_RTTI_DATA4(failure
, 0, &system_error_rtti_base_descriptor
,
725 &_System_error_rtti_base_descriptor
, &runtime_error_rtti_base_descriptor
,
726 &exception_rtti_base_descriptor
, ".?AVfailure@ios_base@std@@")
727 DEFINE_CXX_TYPE_INFO(_System_error
)
728 DEFINE_CXX_DATA3(system_error
, &_System_error_cxx_type_info
,
729 &runtime_error_cxx_type_info
, &exception_cxx_type_info
,
730 MSVCP_runtime_error_dtor
)
731 DEFINE_CXX_DATA4(failure
, &system_error_cxx_type_info
,
732 &_System_error_cxx_type_info
, &runtime_error_cxx_type_info
,
733 &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
734 #elif _MSVCP_VER > 90
735 DEFINE_RTTI_DATA2(system_error
, 0, &runtime_error_rtti_base_descriptor
,
736 &exception_rtti_base_descriptor
, ".?AVsystem_error@std@@")
737 DEFINE_RTTI_DATA3(failure
, 0, &system_error_rtti_base_descriptor
,
738 &runtime_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
,
739 ".?AVfailure@ios_base@std@@")
740 #if _MSVCP_VER == 100
741 DEFINE_CXX_TYPE_INFO(system_error
);
743 DEFINE_CXX_DATA2(system_error
, &runtime_error_cxx_type_info
,
744 &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
746 DEFINE_CXX_DATA3(failure
, &system_error_cxx_type_info
, &runtime_error_cxx_type_info
,
747 &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
749 DEFINE_RTTI_DATA2(failure
, 0, &runtime_error_rtti_base_descriptor
,
750 &exception_rtti_base_descriptor
, ".?AVfailure@ios_base@std@@")
751 DEFINE_CXX_DATA2(failure
, &runtime_error_cxx_type_info
,
752 &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
755 /* bad_cast class data */
756 typedef exception bad_cast
;
758 /* ??0bad_cast@std@@QAE@PBD@Z */
759 /* ??0bad_cast@std@@QEAA@PEBD@Z */
760 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_ctor
, 8)
761 bad_cast
* __thiscall
MSVCP_bad_cast_ctor(bad_cast
*this, const char *name
)
763 TRACE("%p %s\n", this, name
);
764 MSVCP_exception_ctor(this, EXCEPTION_NAME(name
));
765 this->vtable
= &bad_cast_vtable
;
769 /* ??_Fbad_cast@@QAEXXZ */
770 /* ??_Fbad_cast@std@@QEAAXXZ */
771 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_default_ctor
,4)
772 bad_cast
* __thiscall
MSVCP_bad_cast_default_ctor(bad_cast
*this)
774 return MSVCP_bad_cast_ctor(this, "bad cast");
777 /* ??0bad_cast@std@@QAE@ABV01@@Z */
778 /* ??0bad_cast@std@@QEAA@AEBV01@@Z */
779 DEFINE_THISCALL_WRAPPER(bad_cast_copy_ctor
, 8)
780 bad_cast
* __thiscall
bad_cast_copy_ctor(bad_cast
*this, const bad_cast
*rhs
)
782 TRACE("%p %p\n", this, rhs
);
783 exception_copy_ctor(this, rhs
);
784 this->vtable
= &bad_cast_vtable
;
788 /* ??1bad_cast@@UAE@XZ */
789 /* ??1bad_cast@std@@UEAA@XZ */
790 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_dtor
, 4)
791 void __thiscall
MSVCP_bad_cast_dtor(bad_cast
*this)
794 MSVCP_exception_dtor(this);
797 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_vector_dtor
, 8)
798 void * __thiscall
MSVCP_bad_cast_vector_dtor(bad_cast
*this, unsigned int flags
)
800 TRACE("%p %x\n", this, flags
);
802 /* we have an array, with the number of elements stored before the first object */
803 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
805 for(i
=*ptr
-1; i
>=0; i
--)
806 MSVCP_bad_cast_dtor(this+i
);
807 operator_delete(ptr
);
809 MSVCP_bad_cast_dtor(this);
811 operator_delete(this);
817 /* ??4bad_cast@std@@QAEAAV01@ABV01@@Z */
818 /* ??4bad_cast@std@@QEAAAEAV01@AEBV01@@Z */
819 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_opequals
, 8)
820 bad_cast
* __thiscall
MSVCP_bad_cast_opequals(bad_cast
*this, const bad_cast
*rhs
)
822 TRACE("(%p %p)\n", this, rhs
);
825 MSVCP_exception_dtor(this);
826 exception_copy_ctor(this, rhs
);
831 DEFINE_RTTI_DATA1(bad_cast
, 0, &exception_rtti_base_descriptor
, ".?AVbad_cast@std@@")
833 /* range_error class data */
834 typedef runtime_error range_error
;
836 static range_error
* MSVCP_range_error_ctor( range_error
*this, exception_name name
)
838 TRACE("%p %s\n", this, EXCEPTION_STR(name
));
839 MSVCP_runtime_error_ctor(this, name
);
840 this->e
.vtable
= &range_error_vtable
;
844 /* ??0range_error@std@@QAE@ABV01@@Z */
845 /* ??0range_error@std@@QEAA@AEBV01@@Z */
846 DEFINE_THISCALL_WRAPPER(range_error_copy_ctor
, 8)
847 range_error
* __thiscall
range_error_copy_ctor(
848 range_error
*this, const range_error
*rhs
)
850 TRACE("%p %p\n", this, rhs
);
851 runtime_error_copy_ctor(this, rhs
);
852 this->e
.vtable
= &range_error_vtable
;
856 /* ??0range_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
857 /* ??0range_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
859 DEFINE_THISCALL_WRAPPER(MSVCP_range_error_ctor_bstr
, 8)
860 range_error
* __thiscall
MSVCP_range_error_ctor_bstr(range_error
*this, const basic_string_char
*str
)
862 const char *name
= MSVCP_basic_string_char_c_str(str
);
863 TRACE("(%p %p %s)\n", this, str
, name
);
864 return MSVCP_range_error_ctor(this, EXCEPTION_NAME(name
));
868 /* ??4range_error@std@@QAEAAV01@ABV01@@Z */
869 /* ??4range_error@std@@QEAAAEAV01@AEBV01@@Z */
870 DEFINE_THISCALL_WRAPPER(MSVCP_range_error_assign
, 8)
871 range_error
* __thiscall
MSVCP_range_error_assign(range_error
*this, const range_error
*assign
)
873 MSVCP_runtime_error_dtor(this);
874 return range_error_copy_ctor(this, assign
);
877 DEFINE_RTTI_DATA2(range_error
, 0, &runtime_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
, ".?AVrange_error@std@@")
878 DEFINE_CXX_DATA2(range_error
, &runtime_error_cxx_type_info
, &exception_cxx_type_info
, MSVCP_runtime_error_dtor
)
881 /* bad_function_call class data */
882 typedef exception bad_function_call
;
884 static bad_function_call
* MSVCP_bad_function_call_ctor(bad_function_call
*this)
886 static const char *name
= "bad function call";
889 MSVCP_exception_ctor(this, EXCEPTION_NAME(name
));
890 this->vtable
= &bad_function_call_vtable
;
894 DEFINE_THISCALL_WRAPPER(bad_function_call_copy_ctor
, 8)
895 bad_function_call
* __thiscall
bad_function_call_copy_ctor(bad_function_call
*this, const bad_function_call
*rhs
)
897 TRACE("%p %p\n", this, rhs
);
898 exception_copy_ctor(this, rhs
);
899 this->vtable
= &bad_function_call_vtable
;
903 DEFINE_RTTI_DATA1(bad_function_call
, 0, &exception_rtti_base_descriptor
, ".?AVbad_function_call@std@@")
904 DEFINE_CXX_DATA1(bad_function_call
, &exception_cxx_type_info
, MSVCP_exception_dtor
)
907 /* ?_Nomemory@std@@YAXXZ */
908 void __cdecl DECLSPEC_NORETURN
_Nomemory(void)
914 MSVCP_bad_alloc_default_ctor(&e
);
915 _CxxThrowException(&e
, &bad_alloc_cxx_type
);
918 /* ?_Xmem@tr1@std@@YAXXZ */
919 void __cdecl DECLSPEC_NORETURN
_Xmem(void)
925 MSVCP_bad_alloc_default_ctor(&e
);
926 _CxxThrowException(&e
, &bad_alloc_cxx_type
);
929 /* ?_Xinvalid_argument@std@@YAXPBD@Z */
930 /* ?_Xinvalid_argument@std@@YAXPEBD@Z */
931 void __cdecl DECLSPEC_NORETURN
_Xinvalid_argument(const char *str
)
933 exception_name name
= EXCEPTION_NAME(str
);
936 TRACE("(%s)\n", debugstr_a(str
));
938 MSVCP_invalid_argument_ctor(&e
, name
);
939 _CxxThrowException(&e
, &invalid_argument_cxx_type
);
942 /* ?_Xlength_error@std@@YAXPBD@Z */
943 /* ?_Xlength_error@std@@YAXPEBD@Z */
944 void __cdecl DECLSPEC_NORETURN
_Xlength_error(const char *str
)
946 exception_name name
= EXCEPTION_NAME(str
);
949 TRACE("(%s)\n", debugstr_a(str
));
951 MSVCP_length_error_ctor(&e
, name
);
952 _CxxThrowException(&e
, &length_error_cxx_type
);
955 /* ?_Xout_of_range@std@@YAXPBD@Z */
956 /* ?_Xout_of_range@std@@YAXPEBD@Z */
957 void __cdecl DECLSPEC_NORETURN
_Xout_of_range(const char *str
)
959 exception_name name
= EXCEPTION_NAME(str
);
962 TRACE("(%s)\n", debugstr_a(str
));
964 MSVCP_out_of_range_ctor(&e
, name
);
965 _CxxThrowException(&e
, &out_of_range_cxx_type
);
968 /* ?_Xruntime_error@std@@YAXPBD@Z */
969 /* ?_Xruntime_error@std@@YAXPEBD@Z */
970 void __cdecl DECLSPEC_NORETURN
_Xruntime_error(const char *str
)
972 exception_name name
= EXCEPTION_NAME(str
);
975 TRACE("(%s)\n", debugstr_a(str
));
977 MSVCP_runtime_error_ctor(&e
, name
);
978 _CxxThrowException(&e
, &runtime_error_cxx_type
);
982 /* ?_Xbad_function_call@std@@YAXXZ() */
983 void __cdecl
_Xbad_function_call(void)
989 MSVCP_bad_function_call_ctor(&e
);
990 _CxxThrowException(&e
, &bad_function_call_cxx_type
);
994 /* ?uncaught_exception@std@@YA_NXZ */
995 bool __cdecl
MSVCP__uncaught_exception(void)
997 return __uncaught_exception();
1000 #if _MSVCP_VER >= 110
1007 extern const vtable_ptr future_error_vtable
;
1009 DEFINE_THISCALL_WRAPPER(future_error_copy_ctor
, 8)
1010 future_error
* __thiscall
future_error_copy_ctor(future_error
*this, const future_error
*rhs
)
1012 logic_error_copy_ctor(&this->base
, &rhs
->base
);
1013 this->code
= rhs
->code
;
1014 this->base
.e
.vtable
= &future_error_vtable
;
1018 DEFINE_THISCALL_WRAPPER(MSVCP_future_error_what
, 4)
1019 const char* __thiscall
MSVCP_future_error_what(future_error
*this)
1021 const char *names
[4] = {
1023 "future already retrieved",
1024 "promise already satisfied",
1027 #if _MSVCP_VER == 110
1028 int code
= this->code
.code
;
1030 int code
= this->code
.code
-1;
1032 TRACE("%p\n", this);
1033 return code
>= 0 && code
< ARRAY_SIZE(names
) ? names
[code
] : NULL
;
1036 DEFINE_RTTI_DATA3(future_error
, 0, &future_error_rtti_base_descriptor
,
1037 &logic_error_rtti_base_descriptor
, &exception_rtti_base_descriptor
,
1038 ".?AVfuture_error@std@@")
1039 DEFINE_CXX_DATA3(future_error
, &logic_error_cxx_type_info
, &logic_error_cxx_type_info
,
1040 &exception_cxx_type_info
, MSVCP_logic_error_dtor
)
1042 /* ?_Throw_future_error@std@@YAXABVerror_code@1@@Z */
1043 /* ?_Throw_future_error@std@@YAXAEBVerror_code@1@@Z */
1044 void __cdecl DECLSPEC_NORETURN
_Throw_future_error( const error_code
*error_code
)
1047 const char *name
= "";
1049 TRACE("(%p)\n", error_code
);
1051 MSVCP_logic_error_ctor(&e
.base
, EXCEPTION_NAME(name
));
1052 e
.code
= *error_code
;
1053 e
.base
.e
.vtable
= &future_error_vtable
;
1054 _CxxThrowException(&e
, &future_error_cxx_type
);
1059 EXCEPTION_RECORD
*rec
;
1060 LONG
*ref
; /* not binary compatible with native */
1063 static void exception_ptr_rethrow(const exception_ptr
*ep
)
1065 TRACE("(%p)\n", ep
);
1069 static const char *exception_msg
= "bad exception";
1072 MSVCP_exception_ctor(&e
, &exception_msg
);
1073 _CxxThrowException(&e
, &exception_cxx_type
);
1077 RaiseException(ep
->rec
->ExceptionCode
, ep
->rec
->ExceptionFlags
& (~EH_UNWINDING
),
1078 ep
->rec
->NumberParameters
, ep
->rec
->ExceptionInformation
);
1081 /* ?_Rethrow_future_exception@std@@YAXVexception_ptr@1@@Z */
1082 void __cdecl
_Rethrow_future_exception(const exception_ptr ep
)
1084 exception_ptr_rethrow(&ep
);
1087 /* ?_Throw_C_error@std@@YAXH@Z */
1088 void __cdecl
_Throw_C_error(int code
)
1094 TRACE("(%d)\n", code
);
1109 #if _MSVCP_VER >= 140
1116 msg
= strerror(err
);
1117 MSVCP_runtime_error_ctor(&se
.base
, &msg
);
1119 se
.code
.category
= std_generic_category();
1120 se
.base
.e
.vtable
= &system_error_vtable
;
1122 _CxxThrowException(&se
, &system_error_cxx_type
);
1126 #if _MSVCP_VER >= 140
1127 void** CDECL
__current_exception(void);
1129 /* compute the this pointer for a base class of a given type */
1130 static inline void *get_this_pointer( const this_ptr_offsets
*off
, void *object
)
1132 if (!object
) return NULL
;
1134 if (off
->vbase_descr
>= 0)
1138 /* move this ptr to vbase descriptor */
1139 object
= (char *)object
+ off
->vbase_descr
;
1140 /* and fetch additional offset from vbase descriptor */
1141 offset_ptr
= (int *)(*(char **)object
+ off
->vbase_offset
);
1142 object
= (char *)object
+ *offset_ptr
;
1145 object
= (char *)object
+ off
->this_offset
;
1150 extern void call_copy_ctor( void *func
, void *this, void *src
, int has_vbase
);
1151 __ASM_GLOBAL_FUNC( call_copy_ctor
,
1153 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1154 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1155 "movl %esp, %ebp\n\t"
1156 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1158 "movl 12(%ebp), %ecx\n\t"
1159 "pushl 16(%ebp)\n\t"
1162 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1163 __ASM_CFI(".cfi_same_value %ebp\n\t")
1166 static inline void call_copy_ctor( void *func
, void *this, void *src
, int has_vbase
)
1168 TRACE( "calling copy ctor %p object %p src %p\n", func
, this, src
);
1170 ((void (__cdecl
*)(void*, void*, BOOL
))func
)(this, src
, 1);
1172 ((void (__cdecl
*)(void*, void*))func
)(this, src
);
1176 int __cdecl
__uncaught_exceptions(void)
1178 return *__processing_throw();
1181 /*********************************************************************
1182 * ?__ExceptionPtrCreate@@YAXPAX@Z
1183 * ?__ExceptionPtrCreate@@YAXPEAX@Z
1185 void __cdecl
__ExceptionPtrCreate(exception_ptr
*ep
)
1187 TRACE("(%p)\n", ep
);
1193 #ifdef __ASM_USE_THISCALL_WRAPPER
1194 extern void call_dtor(const cxx_exception_type
*type
, void *func
, void *object
);
1196 __ASM_GLOBAL_FUNC( call_dtor
,
1197 "movl 12(%esp),%ecx\n\t"
1201 static inline void call_dtor(const cxx_exception_type
*type
, unsigned int dtor
, void *object
)
1203 char *base
= RtlPcToFileHeader((void*)type
, (void**)&base
);
1204 void (__cdecl
*func
)(void*) = (void*)(base
+ dtor
);
1208 #define call_dtor(type, func, object) ((void (__thiscall*)(void*))(func))(object)
1211 /*********************************************************************
1212 * ?__ExceptionPtrDestroy@@YAXPAX@Z
1213 * ?__ExceptionPtrDestroy@@YAXPEAX@Z
1215 void __cdecl
__ExceptionPtrDestroy(exception_ptr
*ep
)
1217 TRACE("(%p)\n", ep
);
1222 if (!InterlockedDecrement(ep
->ref
))
1224 if (ep
->rec
->ExceptionCode
== CXX_EXCEPTION
)
1226 const cxx_exception_type
*type
= (void*)ep
->rec
->ExceptionInformation
[2];
1227 void *obj
= (void*)ep
->rec
->ExceptionInformation
[1];
1229 if (type
&& type
->destructor
) call_dtor(type
, type
->destructor
, obj
);
1230 HeapFree(GetProcessHeap(), 0, obj
);
1233 HeapFree(GetProcessHeap(), 0, ep
->rec
);
1234 HeapFree(GetProcessHeap(), 0, ep
->ref
);
1238 /*********************************************************************
1239 * ?__ExceptionPtrCopy@@YAXPAXPBX@Z
1240 * ?__ExceptionPtrCopy@@YAXPEAXPEBX@Z
1242 void __cdecl
__ExceptionPtrCopy(exception_ptr
*ep
, const exception_ptr
*copy
)
1244 TRACE("(%p %p)\n", ep
, copy
);
1246 /* don't destroy object stored in ep */
1249 InterlockedIncrement(copy
->ref
);
1252 /*********************************************************************
1253 * ?__ExceptionPtrAssign@@YAXPAXPBX@Z
1254 * ?__ExceptionPtrAssign@@YAXPEAXPEBX@Z
1256 void __cdecl
__ExceptionPtrAssign(exception_ptr
*ep
, const exception_ptr
*assign
)
1258 TRACE("(%p %p)\n", ep
, assign
);
1260 /* don't destroy object stored in ep */
1262 InterlockedDecrement(ep
->ref
);
1266 InterlockedIncrement(ep
->ref
);
1269 /*********************************************************************
1270 * ?__ExceptionPtrRethrow@@YAXPBX@Z
1271 * ?__ExceptionPtrRethrow@@YAXPEBX@Z
1273 void __cdecl
__ExceptionPtrRethrow(const exception_ptr
*ep
)
1275 exception_ptr_rethrow(ep
);
1278 /*********************************************************************
1279 * ?__ExceptionPtrCurrentException@@YAXPAX@Z
1280 * ?__ExceptionPtrCurrentException@@YAXPEAX@Z
1283 void __cdecl
__ExceptionPtrCurrentException(exception_ptr
*ep
)
1285 void **current_exception
= __current_exception();
1286 EXCEPTION_RECORD
*rec
= current_exception
? *current_exception
: NULL
;
1288 TRACE("(%p)\n", ep
);
1297 ep
->rec
= HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD
));
1298 ep
->ref
= HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1303 if (ep
->rec
->ExceptionCode
== CXX_EXCEPTION
)
1305 const cxx_exception_type
*et
= (void*)ep
->rec
->ExceptionInformation
[2];
1306 const cxx_type_info
*ti
;
1309 ti
= et
->type_info_table
->info
[0];
1310 data
= HeapAlloc(GetProcessHeap(), 0, ti
->size
);
1312 obj
= (void*)ep
->rec
->ExceptionInformation
[1];
1313 if (ti
->flags
& CLASS_IS_SIMPLE_TYPE
)
1315 memcpy(data
, obj
, ti
->size
);
1316 if (ti
->size
== sizeof(void *)) *data
= get_this_pointer(&ti
->offsets
, *data
);
1318 else if (ti
->copy_ctor
)
1320 call_copy_ctor(ti
->copy_ctor
, data
, get_this_pointer(&ti
->offsets
, obj
),
1321 ti
->flags
& CLASS_HAS_VIRTUAL_BASE_CLASS
);
1324 memcpy(data
, get_this_pointer(&ti
->offsets
, obj
), ti
->size
);
1325 ep
->rec
->ExceptionInformation
[1] = (ULONG_PTR
)data
;
1330 void __cdecl
__ExceptionPtrCurrentException(exception_ptr
*ep
)
1332 void **current_exception
= __current_exception();
1333 EXCEPTION_RECORD
*rec
= current_exception
? *current_exception
: NULL
;
1335 TRACE("(%p)\n", ep
);
1344 ep
->rec
= HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD
));
1345 ep
->ref
= HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1350 if (ep
->rec
->ExceptionCode
== CXX_EXCEPTION
)
1352 const cxx_exception_type
*et
= (void*)ep
->rec
->ExceptionInformation
[2];
1353 const cxx_type_info
*ti
;
1355 char *base
= RtlPcToFileHeader((void*)et
, (void**)&base
);
1357 ti
= (const cxx_type_info
*)(base
+ ((const cxx_type_info_table
*)(base
+ et
->type_info_table
))->info
[0]);
1358 data
= HeapAlloc(GetProcessHeap(), 0, ti
->size
);
1360 obj
= (void*)ep
->rec
->ExceptionInformation
[1];
1361 if (ti
->flags
& CLASS_IS_SIMPLE_TYPE
)
1363 memcpy(data
, obj
, ti
->size
);
1364 if (ti
->size
== sizeof(void *)) *data
= get_this_pointer(&ti
->offsets
, *data
);
1366 else if (ti
->copy_ctor
)
1368 call_copy_ctor(base
+ ti
->copy_ctor
, data
, get_this_pointer(&ti
->offsets
, obj
),
1369 ti
->flags
& CLASS_HAS_VIRTUAL_BASE_CLASS
);
1372 memcpy(data
, get_this_pointer(&ti
->offsets
, obj
), ti
->size
);
1373 ep
->rec
->ExceptionInformation
[1] = (ULONG_PTR
)data
;
1379 /*********************************************************************
1380 * ?__ExceptionPtrToBool@@YA_NPBX@Z
1381 * ?__ExceptionPtrToBool@@YA_NPEBX@Z
1383 bool __cdecl
__ExceptionPtrToBool(exception_ptr
*ep
)
1388 /*********************************************************************
1389 * ?__ExceptionPtrCopyException@@YAXPAXPBX1@Z
1390 * ?__ExceptionPtrCopyException@@YAXPEAXPEBX1@Z
1393 void __cdecl
__ExceptionPtrCopyException(exception_ptr
*ep
,
1394 exception
*object
, const cxx_exception_type
*type
)
1396 const cxx_type_info
*ti
;
1399 __ExceptionPtrDestroy(ep
);
1401 ep
->rec
= HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD
));
1402 ep
->ref
= HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1405 memset(ep
->rec
, 0, sizeof(EXCEPTION_RECORD
));
1406 ep
->rec
->ExceptionCode
= CXX_EXCEPTION
;
1407 ep
->rec
->ExceptionFlags
= EH_NONCONTINUABLE
;
1408 ep
->rec
->NumberParameters
= 3;
1409 ep
->rec
->ExceptionInformation
[0] = CXX_FRAME_MAGIC_VC6
;
1410 ep
->rec
->ExceptionInformation
[2] = (ULONG_PTR
)type
;
1412 ti
= type
->type_info_table
->info
[0];
1413 data
= HeapAlloc(GetProcessHeap(), 0, ti
->size
);
1414 if (ti
->flags
& CLASS_IS_SIMPLE_TYPE
)
1416 memcpy(data
, object
, ti
->size
);
1417 if (ti
->size
== sizeof(void *)) *data
= get_this_pointer(&ti
->offsets
, *data
);
1419 else if (ti
->copy_ctor
)
1421 call_copy_ctor(ti
->copy_ctor
, data
, get_this_pointer(&ti
->offsets
, object
),
1422 ti
->flags
& CLASS_HAS_VIRTUAL_BASE_CLASS
);
1425 memcpy(data
, get_this_pointer(&ti
->offsets
, object
), ti
->size
);
1426 ep
->rec
->ExceptionInformation
[1] = (ULONG_PTR
)data
;
1429 void __cdecl
__ExceptionPtrCopyException(exception_ptr
*ep
,
1430 exception
*object
, const cxx_exception_type
*type
)
1432 const cxx_type_info
*ti
;
1436 RtlPcToFileHeader((void*)type
, (void**)&base
);
1437 __ExceptionPtrDestroy(ep
);
1439 ep
->rec
= HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD
));
1440 ep
->ref
= HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1443 memset(ep
->rec
, 0, sizeof(EXCEPTION_RECORD
));
1444 ep
->rec
->ExceptionCode
= CXX_EXCEPTION
;
1445 ep
->rec
->ExceptionFlags
= EH_NONCONTINUABLE
;
1446 ep
->rec
->NumberParameters
= 4;
1447 ep
->rec
->ExceptionInformation
[0] = CXX_FRAME_MAGIC_VC6
;
1448 ep
->rec
->ExceptionInformation
[2] = (ULONG_PTR
)type
;
1449 ep
->rec
->ExceptionInformation
[3] = (ULONG_PTR
)base
;
1451 ti
= (const cxx_type_info
*)(base
+ ((const cxx_type_info_table
*)(base
+ type
->type_info_table
))->info
[0]);
1452 data
= HeapAlloc(GetProcessHeap(), 0, ti
->size
);
1453 if (ti
->flags
& CLASS_IS_SIMPLE_TYPE
)
1455 memcpy(data
, object
, ti
->size
);
1456 if (ti
->size
== sizeof(void *)) *data
= get_this_pointer(&ti
->offsets
, *data
);
1458 else if (ti
->copy_ctor
)
1460 call_copy_ctor(base
+ ti
->copy_ctor
, data
, get_this_pointer(&ti
->offsets
, object
),
1461 ti
->flags
& CLASS_HAS_VIRTUAL_BASE_CLASS
);
1464 memcpy(data
, get_this_pointer(&ti
->offsets
, object
), ti
->size
);
1465 ep
->rec
->ExceptionInformation
[1] = (ULONG_PTR
)data
;
1469 /*********************************************************************
1470 * ?__ExceptionPtrCompare@@YA_NPBX0@Z
1471 * ?__ExceptionPtrCompare@@YA_NPEBX0@Z
1473 bool __cdecl
__ExceptionPtrCompare(const exception_ptr
*ep1
, const exception_ptr
*ep2
)
1475 return ep1
->rec
== ep2
->rec
;
1479 #if _MSVCP_VER >= 70 || defined(_MSVCIRT)
1480 #define EXCEPTION_VTABLE(name,funcs) __ASM_VTABLE(name,funcs)
1482 #define EXCEPTION_VTABLE(name,funcs) __ASM_VTABLE(name,funcs VTABLE_ADD_FUNC(MSVCP_exception__Doraise))
1485 __ASM_BLOCK_BEGIN(exception_vtables
)
1486 EXCEPTION_VTABLE(exception
,
1487 VTABLE_ADD_FUNC(MSVCP_exception_vector_dtor
)
1488 VTABLE_ADD_FUNC(MSVCP_exception_what
));
1489 EXCEPTION_VTABLE(bad_alloc
,
1490 VTABLE_ADD_FUNC(MSVCP_bad_alloc_vector_dtor
)
1491 VTABLE_ADD_FUNC(MSVCP_exception_what
));
1492 EXCEPTION_VTABLE(logic_error
,
1493 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor
)
1494 VTABLE_ADD_FUNC(MSVCP_logic_error_what
));
1495 EXCEPTION_VTABLE(length_error
,
1496 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor
)
1497 VTABLE_ADD_FUNC(MSVCP_logic_error_what
));
1498 EXCEPTION_VTABLE(out_of_range
,
1499 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor
)
1500 VTABLE_ADD_FUNC(MSVCP_logic_error_what
));
1501 EXCEPTION_VTABLE(invalid_argument
,
1502 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor
)
1503 VTABLE_ADD_FUNC(MSVCP_logic_error_what
));
1504 EXCEPTION_VTABLE(runtime_error
,
1505 VTABLE_ADD_FUNC(MSVCP_runtime_error_vector_dtor
)
1506 VTABLE_ADD_FUNC(MSVCP_runtime_error_what
));
1507 #if _MSVCP_VER >= 110
1508 EXCEPTION_VTABLE(future_error
,
1509 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor
)
1510 VTABLE_ADD_FUNC(MSVCP_future_error_what
));
1512 #if _MSVCP_VER > 110
1513 EXCEPTION_VTABLE(_System_error
,
1514 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor
)
1515 VTABLE_ADD_FUNC(MSVCP_failure_what
));
1518 EXCEPTION_VTABLE(system_error
,
1519 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor
)
1520 VTABLE_ADD_FUNC(MSVCP_failure_what
));
1521 EXCEPTION_VTABLE(bad_function_call
,
1522 VTABLE_ADD_FUNC(MSVCP_exception_vector_dtor
)
1523 VTABLE_ADD_FUNC(MSVCP_exception_what
));
1525 EXCEPTION_VTABLE(failure
,
1526 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor
)
1527 VTABLE_ADD_FUNC(MSVCP_failure_what
));
1528 EXCEPTION_VTABLE(bad_cast
,
1529 VTABLE_ADD_FUNC(MSVCP_bad_cast_vector_dtor
)
1530 VTABLE_ADD_FUNC(MSVCP_exception_what
));
1531 EXCEPTION_VTABLE(range_error
,
1532 VTABLE_ADD_FUNC(MSVCP_runtime_error_vector_dtor
)
1533 VTABLE_ADD_FUNC(MSVCP_runtime_error_what
));
1537 /* Internal: throws exception */
1538 void DECLSPEC_NORETURN
throw_exception(const char *str
)
1540 exception_name name
= EXCEPTION_NAME(str
);
1543 MSVCP_exception_ctor(&e
, name
);
1544 _CxxThrowException(&e
, &exception_cxx_type
);
1547 /* Internal: throws range_error exception */
1548 void DECLSPEC_NORETURN
throw_range_error(const char *str
)
1550 exception_name name
= EXCEPTION_NAME(str
);
1553 MSVCP_range_error_ctor(&e
, name
);
1554 _CxxThrowException(&e
, &range_error_cxx_type
);
1557 /* Internal: throws failure exception */
1558 void DECLSPEC_NORETURN
throw_failure(const char *str
)
1560 exception_name name
= EXCEPTION_NAME(str
);
1563 MSVCP_failure_ctor(&e
, name
);
1564 _CxxThrowException(&e
, &failure_cxx_type
);
1567 void init_exception(void *base
)
1570 init_type_info_rtti(base
);
1571 init_exception_rtti(base
);
1572 init_bad_alloc_rtti(base
);
1573 init_logic_error_rtti(base
);
1574 init_length_error_rtti(base
);
1575 init_out_of_range_rtti(base
);
1576 init_invalid_argument_rtti(base
);
1577 init_runtime_error_rtti(base
);
1578 #if _MSVCP_VER >= 110
1579 init_future_error_rtti(base
);
1581 #if _MSVCP_VER > 110
1582 init__System_error_rtti(base
);
1585 init_system_error_rtti(base
);
1586 init_bad_function_call_rtti(base
);
1588 init_failure_rtti(base
);
1589 init_bad_cast_rtti(base
);
1590 init_range_error_rtti(base
);
1592 init_exception_cxx(base
);
1593 init_bad_alloc_cxx(base
);
1594 init_logic_error_cxx_type_info(base
);
1595 init_length_error_cxx(base
);
1596 init_out_of_range_cxx(base
);
1597 init_invalid_argument_cxx(base
);
1598 init_runtime_error_cxx(base
);
1599 #if _MSVCP_VER >= 110
1600 init_future_error_cxx(base
);
1602 #if _MSVCP_VER > 110
1603 init__System_error_cxx_type_info(base
);
1605 #if _MSVCP_VER == 100
1606 init_system_error_cxx_type_info(base
);
1607 #elif _MSVCP_VER > 100
1608 init_system_error_cxx(base
);
1611 init_bad_function_call_cxx(base
);
1613 init_failure_cxx(base
);
1614 init_range_error_cxx(base
);