2 * msvcrt.dll C++ objects
4 * Copyright 2000 Jon Griffiths
5 * Copyright 2003, 2004 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/config.h"
23 #include "wine/port.h"
31 #include "wine/exception.h"
34 #include "wine/debug.h"
39 #include <internal/wine/msvcrt.h>
40 #include <internal/wine/cppexcept.h>
41 #include <internal/mtdll.h>
43 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
45 typedef exception bad_cast
;
46 typedef exception bad_typeid
;
47 typedef exception __non_rtti_object
;
49 typedef struct _rtti_base_descriptor
51 const type_info
*type_descriptor
;
53 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
54 unsigned int attributes
;
55 } rtti_base_descriptor
;
57 typedef struct _rtti_base_array
59 const rtti_base_descriptor
*bases
[3]; /* First element is the class itself */
62 typedef struct _rtti_object_hierarchy
64 unsigned int signature
;
65 unsigned int attributes
;
66 int array_len
; /* Size of the array pointed to by 'base_classes' */
67 const rtti_base_array
*base_classes
;
68 } rtti_object_hierarchy
;
70 typedef struct _rtti_object_locator
72 unsigned int signature
;
73 int base_class_offset
;
75 const type_info
*type_descriptor
;
76 const rtti_object_hierarchy
*type_hierarchy
;
77 } rtti_object_locator
;
80 #ifdef __i386__ /* thiscall functions are i386-specific */
82 #define THISCALL(func) __thiscall_ ## func
83 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
84 #define DEFINE_THISCALL_WRAPPER(func) \
85 extern void THISCALL(func)(); \
86 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
90 "jmp " __ASM_NAME(#func) )
93 #define THISCALL(func) func
94 #define THISCALL_NAME(func) __ASM_NAME(#func)
95 #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
99 extern const vtable_ptr MSVCRT_exception_vtable
;
100 extern const vtable_ptr MSVCRT_bad_typeid_vtable
;
101 extern const vtable_ptr MSVCRT_bad_cast_vtable
;
102 extern const vtable_ptr MSVCRT___non_rtti_object_vtable
;
103 extern const vtable_ptr MSVCRT_type_info_vtable
;
105 /* get the vtable pointer for a C++ object */
106 static inline const vtable_ptr
*get_vtable( void *obj
)
108 return *(const vtable_ptr
**)obj
;
111 static inline const rtti_object_locator
*get_obj_locator( void *cppobj
)
113 const vtable_ptr
*vtable
= get_vtable( cppobj
);
114 return (const rtti_object_locator
*)vtable
[-1];
117 static void dump_obj_locator( const rtti_object_locator
*ptr
)
120 const rtti_object_hierarchy
*h
= ptr
->type_hierarchy
;
122 TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n",
123 ptr
, ptr
->signature
, ptr
->base_class_offset
, ptr
->flags
,
124 ptr
->type_descriptor
, dbgstr_type_info(ptr
->type_descriptor
), ptr
->type_hierarchy
);
125 TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n",
126 h
->signature
, h
->attributes
, h
->array_len
, h
->base_classes
);
127 for (i
= 0; i
< h
->array_len
; i
++)
129 TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n",
130 h
->base_classes
->bases
[i
],
131 h
->base_classes
->bases
[i
]->num_base_classes
,
132 h
->base_classes
->bases
[i
]->offsets
.this_offset
,
133 h
->base_classes
->bases
[i
]->offsets
.vbase_descr
,
134 h
->base_classes
->bases
[i
]->offsets
.vbase_offset
,
135 h
->base_classes
->bases
[i
]->attributes
,
136 h
->base_classes
->bases
[i
]->type_descriptor
,
137 dbgstr_type_info(h
->base_classes
->bases
[i
]->type_descriptor
) );
141 /* Internal common ctor for exception */
142 static void WINAPI
EXCEPTION_ctor(exception
*_this
, const char** name
)
144 _this
->vtable
= &MSVCRT_exception_vtable
;
147 size_t name_len
= strlen(*name
) + 1;
148 _this
->name
= MSVCRT_malloc(name_len
);
149 memcpy(_this
->name
, *name
, name_len
);
150 _this
->do_free
= TRUE
;
155 _this
->do_free
= FALSE
;
159 /******************************************************************
160 * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
162 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_ctor
)
163 exception
* __stdcall
MSVCRT_exception_ctor(exception
* _this
, const char ** name
)
165 TRACE("(%p,%s)\n", _this
, *name
);
166 EXCEPTION_ctor(_this
, name
);
170 /******************************************************************
171 * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
173 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_copy_ctor
)
174 exception
* __stdcall
MSVCRT_exception_copy_ctor(exception
* _this
, const exception
* rhs
)
176 TRACE("(%p,%p)\n", _this
, rhs
);
180 _this
->vtable
= &MSVCRT_exception_vtable
;
181 _this
->name
= rhs
->name
;
182 _this
->do_free
= FALSE
;
185 EXCEPTION_ctor(_this
, (const char**)&rhs
->name
);
186 TRACE("name = %s\n", _this
->name
);
190 /******************************************************************
191 * ??0exception@@QAE@XZ (MSVCRT.@)
193 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_default_ctor
)
194 exception
* __stdcall
MSVCRT_exception_default_ctor(exception
* _this
)
196 static const char* empty
= NULL
;
198 TRACE("(%p)\n", _this
);
199 EXCEPTION_ctor(_this
, &empty
);
203 /******************************************************************
204 * ??1exception@@UAE@XZ (MSVCRT.@)
206 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_dtor
)
207 void __stdcall
MSVCRT_exception_dtor(exception
* _this
)
209 TRACE("(%p)\n", _this
);
210 _this
->vtable
= &MSVCRT_exception_vtable
;
211 if (_this
->do_free
) MSVCRT_free(_this
->name
);
214 /******************************************************************
215 * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
217 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_opequals
)
218 exception
* __stdcall
MSVCRT_exception_opequals(exception
* _this
, const exception
* rhs
)
220 TRACE("(%p %p)\n", _this
, rhs
);
223 MSVCRT_exception_dtor(_this
);
224 MSVCRT_exception_copy_ctor(_this
, rhs
);
226 TRACE("name = %s\n", _this
->name
);
230 /******************************************************************
231 * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
233 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_vector_dtor
)
234 void * __stdcall
MSVCRT_exception_vector_dtor(exception
* _this
, unsigned int flags
)
236 TRACE("(%p %x)\n", _this
, flags
);
239 /* we have an array, with the number of elements stored before the first object */
240 int i
, *ptr
= (int *)_this
- 1;
242 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_exception_dtor(_this
+ i
);
243 MSVCRT_operator_delete(ptr
);
247 MSVCRT_exception_dtor(_this
);
248 if (flags
& 1) MSVCRT_operator_delete(_this
);
253 /******************************************************************
254 * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
256 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_scalar_dtor
)
257 void * __stdcall
MSVCRT_exception_scalar_dtor(exception
* _this
, unsigned int flags
)
259 TRACE("(%p %x)\n", _this
, flags
);
260 MSVCRT_exception_dtor(_this
);
261 if (flags
& 1) MSVCRT_operator_delete(_this
);
265 /******************************************************************
266 * ?what@exception@@UBEPBDXZ (MSVCRT.@)
268 DEFINE_THISCALL_WRAPPER(MSVCRT_what_exception
)
269 const char * __stdcall
MSVCRT_what_exception(exception
* _this
)
271 TRACE("(%p) returning %s\n", _this
, _this
->name
);
272 return _this
->name
? _this
->name
: "Unknown exception";
275 /******************************************************************
276 * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
278 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_copy_ctor
)
279 bad_typeid
* __stdcall
MSVCRT_bad_typeid_copy_ctor(bad_typeid
* _this
, const bad_typeid
* rhs
)
281 TRACE("(%p %p)\n", _this
, rhs
);
282 MSVCRT_exception_copy_ctor(_this
, rhs
);
283 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
287 /******************************************************************
288 * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
290 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_ctor
)
291 bad_typeid
* __stdcall
MSVCRT_bad_typeid_ctor(bad_typeid
* _this
, const char * name
)
293 TRACE("(%p %s)\n", _this
, name
);
294 EXCEPTION_ctor(_this
, &name
);
295 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
299 /******************************************************************
300 * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
302 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_dtor
)
303 void __stdcall
MSVCRT_bad_typeid_dtor(bad_typeid
* _this
)
305 TRACE("(%p)\n", _this
);
306 MSVCRT_exception_dtor(_this
);
309 /******************************************************************
310 * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
312 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_opequals
)
313 bad_typeid
* __stdcall
MSVCRT_bad_typeid_opequals(bad_typeid
* _this
, const bad_typeid
* rhs
)
315 TRACE("(%p %p)\n", _this
, rhs
);
316 MSVCRT_exception_opequals(_this
, rhs
);
320 /******************************************************************
321 * ??_Ebad_typeid@@UAEPAXI@Z (MSVCRT.@)
323 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_vector_dtor
)
324 void * __stdcall
MSVCRT_bad_typeid_vector_dtor(bad_typeid
* _this
, unsigned int flags
)
326 TRACE("(%p %x)\n", _this
, flags
);
329 /* we have an array, with the number of elements stored before the first object */
330 int i
, *ptr
= (int *)_this
- 1;
332 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_typeid_dtor(_this
+ i
);
333 MSVCRT_operator_delete(ptr
);
337 MSVCRT_bad_typeid_dtor(_this
);
338 if (flags
& 1) MSVCRT_operator_delete(_this
);
343 /******************************************************************
344 * ??_Gbad_typeid@@UAEPAXI@Z (MSVCRT.@)
346 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_scalar_dtor
)
347 void * __stdcall
MSVCRT_bad_typeid_scalar_dtor(bad_typeid
* _this
, unsigned int flags
)
349 TRACE("(%p %x)\n", _this
, flags
);
350 MSVCRT_bad_typeid_dtor(_this
);
351 if (flags
& 1) MSVCRT_operator_delete(_this
);
355 /******************************************************************
356 * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
358 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_copy_ctor
)
359 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object
* _this
,
360 const __non_rtti_object
* rhs
)
362 TRACE("(%p %p)\n", _this
, rhs
);
363 MSVCRT_bad_typeid_copy_ctor(_this
, rhs
);
364 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
368 /******************************************************************
369 * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
371 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_ctor
)
372 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_ctor(__non_rtti_object
* _this
,
375 TRACE("(%p %s)\n", _this
, name
);
376 EXCEPTION_ctor(_this
, &name
);
377 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
381 /******************************************************************
382 * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
384 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_dtor
)
385 void __stdcall
MSVCRT___non_rtti_object_dtor(__non_rtti_object
* _this
)
387 TRACE("(%p)\n", _this
);
388 MSVCRT_bad_typeid_dtor(_this
);
391 /******************************************************************
392 * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
394 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_opequals
)
395 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_opequals(__non_rtti_object
* _this
,
396 const __non_rtti_object
*rhs
)
398 TRACE("(%p %p)\n", _this
, rhs
);
399 MSVCRT_bad_typeid_opequals(_this
, rhs
);
403 /******************************************************************
404 * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
406 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_vector_dtor
)
407 void * __stdcall
MSVCRT___non_rtti_object_vector_dtor(__non_rtti_object
* _this
, unsigned int flags
)
409 TRACE("(%p %x)\n", _this
, flags
);
412 /* we have an array, with the number of elements stored before the first object */
413 int i
, *ptr
= (int *)_this
- 1;
415 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT___non_rtti_object_dtor(_this
+ i
);
416 MSVCRT_operator_delete(ptr
);
420 MSVCRT___non_rtti_object_dtor(_this
);
421 if (flags
& 1) MSVCRT_operator_delete(_this
);
426 /******************************************************************
427 * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
429 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_scalar_dtor
)
430 void * __stdcall
MSVCRT___non_rtti_object_scalar_dtor(__non_rtti_object
* _this
, unsigned int flags
)
432 TRACE("(%p %x)\n", _this
, flags
);
433 MSVCRT___non_rtti_object_dtor(_this
);
434 if (flags
& 1) MSVCRT_operator_delete(_this
);
438 /******************************************************************
439 * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
441 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_ctor
)
442 bad_cast
* __stdcall
MSVCRT_bad_cast_ctor(bad_cast
* _this
, const char ** name
)
444 TRACE("(%p %s)\n", _this
, *name
);
445 EXCEPTION_ctor(_this
, name
);
446 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
450 /******************************************************************
451 * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
453 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_copy_ctor
)
454 bad_cast
* __stdcall
MSVCRT_bad_cast_copy_ctor(bad_cast
* _this
, const bad_cast
* rhs
)
456 TRACE("(%p %p)\n", _this
, rhs
);
457 MSVCRT_exception_copy_ctor(_this
, rhs
);
458 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
462 /******************************************************************
463 * ??1bad_cast@@UAE@XZ (MSVCRT.@)
465 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_dtor
)
466 void __stdcall
MSVCRT_bad_cast_dtor(bad_cast
* _this
)
468 TRACE("(%p)\n", _this
);
469 MSVCRT_exception_dtor(_this
);
472 /******************************************************************
473 * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
475 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_opequals
)
476 bad_cast
* __stdcall
MSVCRT_bad_cast_opequals(bad_cast
* _this
, const bad_cast
* rhs
)
478 TRACE("(%p %p)\n", _this
, rhs
);
479 MSVCRT_exception_opequals(_this
, rhs
);
483 /******************************************************************
484 * ??_Ebad_cast@@UAEPAXI@Z (MSVCRT.@)
486 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_vector_dtor
)
487 void * __stdcall
MSVCRT_bad_cast_vector_dtor(bad_cast
* _this
, unsigned int flags
)
489 TRACE("(%p %x)\n", _this
, flags
);
492 /* we have an array, with the number of elements stored before the first object */
493 int i
, *ptr
= (int *)_this
- 1;
495 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_cast_dtor(_this
+ i
);
496 MSVCRT_operator_delete(ptr
);
500 MSVCRT_bad_cast_dtor(_this
);
501 if (flags
& 1) MSVCRT_operator_delete(_this
);
506 /******************************************************************
507 * ??_Gbad_cast@@UAEPAXI@Z (MSVCRT.@)
509 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_scalar_dtor
)
510 void * __stdcall
MSVCRT_bad_cast_scalar_dtor(bad_cast
* _this
, unsigned int flags
)
512 TRACE("(%p %x)\n", _this
, flags
);
513 MSVCRT_bad_cast_dtor(_this
);
514 if (flags
& 1) MSVCRT_operator_delete(_this
);
518 /******************************************************************
519 * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
521 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opequals_equals
)
522 int __stdcall
MSVCRT_type_info_opequals_equals(type_info
* _this
, const type_info
* rhs
)
524 int ret
= !strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
525 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
529 /******************************************************************
530 * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
532 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opnot_equals
)
533 int __stdcall
MSVCRT_type_info_opnot_equals(type_info
* _this
, const type_info
* rhs
)
535 int ret
= !!strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
536 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
540 /******************************************************************
541 * ?before@type_info@@QBEHABV1@@Z (MSVCRT.@)
543 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_before
)
544 int __stdcall
MSVCRT_type_info_before(type_info
* _this
, const type_info
* rhs
)
546 int ret
= strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1) < 0;
547 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
551 /******************************************************************
552 * ??1type_info@@UAE@XZ (MSVCRT.@)
554 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_dtor
)
555 void __stdcall
MSVCRT_type_info_dtor(type_info
* _this
)
557 TRACE("(%p)\n", _this
);
558 MSVCRT_free(_this
->name
);
561 /******************************************************************
562 * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
564 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_name
)
565 const char * __stdcall
MSVCRT_type_info_name(type_info
* _this
)
569 /* Create and set the demangled name */
570 /* Nota: mangled name in type_info struct always start with a '.', while
571 * it isn't valid for mangled name.
572 * Is this '.' really part of the mangled name, or has it some other meaning ?
574 char* name
= __unDName(0, _this
->mangled
+ 1, 0,
575 MSVCRT_malloc
, MSVCRT_free
, 0x2800);
579 unsigned int len
= strlen(name
);
581 /* It seems _unDName may leave blanks at the end of the demangled name */
582 while (len
&& name
[--len
] == ' ')
589 /* Another thread set this member since we checked above - use it */
595 _munlock(_EXIT_LOCK2
);
598 TRACE("(%p) returning %s\n", _this
, _this
->name
);
602 /******************************************************************
603 * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
605 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_raw_name
)
606 const char * __stdcall
MSVCRT_type_info_raw_name(type_info
* _this
)
608 TRACE("(%p) returning %s\n", _this
, _this
->mangled
);
609 return _this
->mangled
;
613 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_vector_dtor
)
614 void * __stdcall
MSVCRT_type_info_vector_dtor(type_info
* _this
, unsigned int flags
)
616 TRACE("(%p %x)\n", _this
, flags
);
619 /* we have an array, with the number of elements stored before the first object */
620 int i
, *ptr
= (int *)_this
- 1;
622 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_type_info_dtor(_this
+ i
);
623 MSVCRT_operator_delete(ptr
);
627 MSVCRT_type_info_dtor(_this
);
628 if (flags
& 1) MSVCRT_operator_delete(_this
);
636 #define __ASM_VTABLE(name,funcs) \
639 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
640 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
641 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
642 "\t.quad " THISCALL_NAME(MSVCRT_ ## name ## _vector_dtor) "\n" \
645 #define __ASM_EXCEPTION_VTABLE(name) \
646 __ASM_VTABLE(name, "\t.quad " THISCALL_NAME(MSVCRT_what_exception) )
650 #define __ASM_VTABLE(name,funcs) \
653 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
654 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
655 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
656 "\t.long " THISCALL_NAME(MSVCRT_ ## name ## _vector_dtor) "\n" \
659 #define __ASM_EXCEPTION_VTABLE(name) \
660 __ASM_VTABLE(name, "\t.long " THISCALL_NAME(MSVCRT_what_exception) )
665 void __asm_dummy_vtables(void) {
668 __ASM_VTABLE(type_info
,"")
669 __ASM_EXCEPTION_VTABLE(exception
)
670 __ASM_EXCEPTION_VTABLE(bad_typeid
)
671 __ASM_EXCEPTION_VTABLE(bad_cast
)
672 __ASM_EXCEPTION_VTABLE(__non_rtti_object
)
678 /* Static RTTI for exported objects */
680 static const type_info exception_type_info
=
682 &MSVCRT_type_info_vtable
,
687 static const rtti_base_descriptor exception_rtti_base_descriptor
=
689 &exception_type_info
,
695 static const rtti_base_array exception_rtti_base_array
=
698 &exception_rtti_base_descriptor
,
704 static const rtti_object_hierarchy exception_type_hierarchy
=
709 &exception_rtti_base_array
712 const rtti_object_locator exception_rtti
=
717 &exception_type_info
,
718 &exception_type_hierarchy
721 static const cxx_type_info exception_cxx_type_info
=
724 &exception_type_info
,
727 (cxx_copy_ctor
)THISCALL(MSVCRT_exception_copy_ctor
)
730 static const type_info bad_typeid_type_info
=
732 &MSVCRT_type_info_vtable
,
737 static const rtti_base_descriptor bad_typeid_rtti_base_descriptor
=
739 &bad_typeid_type_info
,
745 static const rtti_base_array bad_typeid_rtti_base_array
=
748 &bad_typeid_rtti_base_descriptor
,
749 &exception_rtti_base_descriptor
,
754 static const rtti_object_hierarchy bad_typeid_type_hierarchy
=
759 &bad_typeid_rtti_base_array
762 const rtti_object_locator bad_typeid_rtti
=
767 &bad_typeid_type_info
,
768 &bad_typeid_type_hierarchy
771 static const cxx_type_info bad_typeid_cxx_type_info
=
774 &bad_typeid_type_info
,
777 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_typeid_copy_ctor
)
780 static const type_info bad_cast_type_info
=
782 &MSVCRT_type_info_vtable
,
787 static const rtti_base_descriptor bad_cast_rtti_base_descriptor
=
795 static const rtti_base_array bad_cast_rtti_base_array
=
798 &bad_cast_rtti_base_descriptor
,
799 &exception_rtti_base_descriptor
,
804 static const rtti_object_hierarchy bad_cast_type_hierarchy
=
809 &bad_cast_rtti_base_array
812 const rtti_object_locator bad_cast_rtti
=
818 &bad_cast_type_hierarchy
821 static const cxx_type_info bad_cast_cxx_type_info
=
827 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_cast_copy_ctor
)
830 static const type_info __non_rtti_object_type_info
=
832 &MSVCRT_type_info_vtable
,
834 ".?AV__non_rtti_object@@"
837 static const rtti_base_descriptor __non_rtti_object_rtti_base_descriptor
=
839 &__non_rtti_object_type_info
,
845 static const rtti_base_array __non_rtti_object_rtti_base_array
=
848 &__non_rtti_object_rtti_base_descriptor
,
849 &bad_typeid_rtti_base_descriptor
,
850 &exception_rtti_base_descriptor
854 static const rtti_object_hierarchy __non_rtti_object_type_hierarchy
=
859 &__non_rtti_object_rtti_base_array
862 const rtti_object_locator __non_rtti_object_rtti
=
867 &__non_rtti_object_type_info
,
868 &__non_rtti_object_type_hierarchy
871 static const cxx_type_info __non_rtti_object_cxx_type_info
=
874 &__non_rtti_object_type_info
,
877 (cxx_copy_ctor
)THISCALL(MSVCRT___non_rtti_object_copy_ctor
)
880 static const type_info type_info_type_info
=
882 &MSVCRT_type_info_vtable
,
887 static const rtti_base_descriptor type_info_rtti_base_descriptor
=
889 &type_info_type_info
,
895 static const rtti_base_array type_info_rtti_base_array
=
898 &type_info_rtti_base_descriptor
,
904 static const rtti_object_hierarchy type_info_type_hierarchy
=
909 &type_info_rtti_base_array
912 const rtti_object_locator type_info_rtti
=
917 &type_info_type_info
,
918 &type_info_type_hierarchy
922 * Exception RTTI for cpp objects
924 static const cxx_type_info_table bad_cast_type_info_table
=
928 &__non_rtti_object_cxx_type_info
,
929 &bad_typeid_cxx_type_info
,
930 &exception_cxx_type_info
934 static const cxx_exception_type bad_cast_exception_type
=
937 (void*)THISCALL(MSVCRT_bad_cast_dtor
),
939 &bad_cast_type_info_table
942 static const cxx_type_info_table bad_typeid_type_info_table
=
946 &bad_cast_cxx_type_info
,
947 &exception_cxx_type_info
,
952 static const cxx_exception_type bad_typeid_exception_type
=
955 (void*)THISCALL(MSVCRT_bad_typeid_dtor
),
957 &bad_cast_type_info_table
960 static const cxx_exception_type __non_rtti_object_exception_type
=
963 (void*)THISCALL(MSVCRT___non_rtti_object_dtor
),
965 &bad_typeid_type_info_table
969 /******************************************************************
970 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
972 * Install a handler to be called when terminate() is called.
975 * func [I] Handler function to install
978 * The previously installed handler function, if any.
980 terminate_function CDECL
MSVCRT_set_terminate(terminate_function func
)
982 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
983 terminate_function previous
= data
->terminate_handler
;
984 TRACE("(%p) returning %p\n",func
,previous
);
985 data
->terminate_handler
= func
;
989 /******************************************************************
990 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
992 * Install a handler to be called when unexpected() is called.
995 * func [I] Handler function to install
998 * The previously installed handler function, if any.
1000 unexpected_function CDECL
MSVCRT_set_unexpected(unexpected_function func
)
1002 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1003 unexpected_function previous
= data
->unexpected_handler
;
1004 TRACE("(%p) returning %p\n",func
,previous
);
1005 data
->unexpected_handler
= func
;
1009 /******************************************************************
1010 * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@)
1012 _se_translator_function CDECL
MSVCRT__set_se_translator(_se_translator_function func
)
1014 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1015 _se_translator_function previous
= data
->se_translator
;
1016 TRACE("(%p) returning %p\n",func
,previous
);
1017 data
->se_translator
= func
;
1021 /******************************************************************
1022 * ?terminate@@YAXXZ (MSVCRT.@)
1024 * Default handler for an unhandled exception.
1030 * This function does not return. Either control resumes from any
1031 * handler installed by calling set_terminate(), or (by default) abort()
1034 void CDECL
MSVCRT_terminate(void)
1036 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1037 if (data
->terminate_handler
) data
->terminate_handler();
1041 /******************************************************************
1042 * ?unexpected@@YAXXZ (MSVCRT.@)
1044 void CDECL
MSVCRT_unexpected(void)
1046 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1047 if (data
->unexpected_handler
) data
->unexpected_handler();
1052 /******************************************************************
1053 * __RTtypeid (MSVCRT.@)
1055 * Retrieve the Run Time Type Information (RTTI) for a C++ object.
1058 * cppobj [I] C++ object to get type information for.
1061 * Success: A type_info object describing cppobj.
1062 * Failure: If the object to be cast has no RTTI, a __non_rtti_object
1063 * exception is thrown. If cppobj is NULL, a bad_typeid exception
1064 * is thrown. In either case, this function does not return.
1067 * This function is usually called by compiler generated code as a result
1068 * of using one of the C++ dynamic cast statements.
1070 const type_info
* CDECL
MSVCRT___RTtypeid(void *cppobj
)
1072 const type_info
*ret
;
1077 MSVCRT_bad_typeid_ctor( &e
, "Attempted a typeid of NULL pointer!" );
1078 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1084 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1085 ret
= obj_locator
->type_descriptor
;
1089 __non_rtti_object e
;
1090 MSVCRT___non_rtti_object_ctor( &e
, "Bad read pointer - no RTTI data!" );
1091 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1098 /******************************************************************
1099 * __RTDynamicCast (MSVCRT.@)
1101 * Dynamically cast a C++ object to one of its base classes.
1104 * cppobj [I] Any C++ object to cast
1105 * unknown [I] Reserved, set to 0
1106 * src [I] type_info object describing cppobj
1107 * dst [I] type_info object describing the base class to cast to
1108 * do_throw [I] TRUE = throw an exception if the cast fails, FALSE = don't
1111 * Success: The address of cppobj, cast to the object described by dst.
1112 * Failure: NULL, If the object to be cast has no RTTI, or dst is not a
1113 * valid cast for cppobj. If do_throw is TRUE, a bad_cast exception
1114 * is thrown and this function does not return.
1117 * This function is usually called by compiler generated code as a result
1118 * of using one of the C++ dynamic cast statements.
1120 void* CDECL
MSVCRT___RTDynamicCast(void *cppobj
, int unknown
,
1121 type_info
*src
, type_info
*dst
,
1126 if (!cppobj
) return NULL
;
1128 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1129 cppobj
, unknown
, src
, dbgstr_type_info(src
), dst
, dbgstr_type_info(dst
), do_throw
);
1131 /* To cast an object at runtime:
1132 * 1.Find out the true type of the object from the typeinfo at vtable[-1]
1133 * 2.Search for the destination type in the class hierarchy
1134 * 3.If destination type is found, return base object address + dest offset
1135 * Otherwise, fail the cast
1137 * FIXME: the unknown parameter doesn't seem to be used for anything
1142 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1143 const rtti_object_hierarchy
*obj_bases
= obj_locator
->type_hierarchy
;
1144 const rtti_base_descriptor
* const* base_desc
= obj_bases
->base_classes
->bases
;
1146 if (TRACE_ON(msvcrt
)) dump_obj_locator(obj_locator
);
1149 for (i
= 0; i
< obj_bases
->array_len
; i
++)
1151 const type_info
*typ
= base_desc
[i
]->type_descriptor
;
1153 if (!strcmp(typ
->mangled
, dst
->mangled
))
1155 /* compute the correct this pointer for that base class */
1156 void *this_ptr
= (char *)cppobj
- obj_locator
->base_class_offset
;
1157 ret
= get_this_pointer( &base_desc
[i
]->offsets
, this_ptr
);
1161 /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned
1162 * to a reference, since references cannot be NULL.
1164 if (!ret
&& do_throw
)
1166 const char *msg
= "Bad dynamic_cast!";
1168 MSVCRT_bad_cast_ctor( &e
, &msg
);
1169 _CxxThrowException( &e
, &bad_cast_exception_type
);
1174 __non_rtti_object e
;
1175 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1176 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1184 /******************************************************************
1185 * __RTCastToVoid (MSVCRT.@)
1187 * Dynamically cast a C++ object to a void*.
1190 * cppobj [I] The C++ object to cast
1193 * Success: The base address of the object as a void*.
1194 * Failure: NULL, if cppobj is NULL or has no RTTI.
1197 * This function is usually called by compiler generated code as a result
1198 * of using one of the C++ dynamic cast statements.
1200 void* CDECL
MSVCRT___RTCastToVoid(void *cppobj
)
1204 if (!cppobj
) return NULL
;
1208 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1209 ret
= (char *)cppobj
- obj_locator
->base_class_offset
;
1213 __non_rtti_object e
;
1214 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1215 _CxxThrowException( &e
, &bad_typeid_exception_type
);