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
24 #include <wine/exception.h>
25 #include <internal/wine/msvcrt.h>
26 #include <internal/wine/cppexcept.h>
28 typedef exception bad_cast
;
29 typedef exception bad_typeid
;
30 typedef exception __non_rtti_object
;
32 typedef struct _rtti_base_descriptor
34 const type_info
*type_descriptor
;
36 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
37 unsigned int attributes
;
38 } rtti_base_descriptor
;
40 typedef struct _rtti_base_array
42 const rtti_base_descriptor
*bases
[3]; /* First element is the class itself */
45 typedef struct _rtti_object_hierarchy
47 unsigned int signature
;
48 unsigned int attributes
;
49 int array_len
; /* Size of the array pointed to by 'base_classes' */
50 const rtti_base_array
*base_classes
;
51 } rtti_object_hierarchy
;
53 typedef struct _rtti_object_locator
55 unsigned int signature
;
56 int base_class_offset
;
58 const type_info
*type_descriptor
;
59 const rtti_object_hierarchy
*type_hierarchy
;
60 } rtti_object_locator
;
62 #ifdef __i386__ /* thiscall functions are i386-specific */
64 #define THISCALL(func) __thiscall_ ## func
65 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
66 #define DEFINE_THISCALL_WRAPPER(func,args) \
67 extern void THISCALL(func)(void); \
68 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
72 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
75 #define THISCALL(func) func
76 #define THISCALL_NAME(func) __ASM_NAME(#func)
77 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
81 extern const vtable_ptr MSVCRT_exception_vtable
;
82 extern const vtable_ptr MSVCRT_bad_typeid_vtable
;
83 extern const vtable_ptr MSVCRT_bad_cast_vtable
;
84 extern const vtable_ptr MSVCRT___non_rtti_object_vtable
;
85 extern const vtable_ptr MSVCRT_type_info_vtable
;
87 /* get the vtable pointer for a C++ object */
88 static inline const vtable_ptr
*get_vtable( void *obj
)
90 return *(const vtable_ptr
**)obj
;
93 static inline const rtti_object_locator
*get_obj_locator( void *cppobj
)
95 const vtable_ptr
*vtable
= get_vtable( cppobj
);
96 return (const rtti_object_locator
*)vtable
[-1];
99 static void dump_obj_locator( const rtti_object_locator
*ptr
)
102 const rtti_object_hierarchy
*h
= ptr
->type_hierarchy
;
104 TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n",
105 ptr
, ptr
->signature
, ptr
->base_class_offset
, ptr
->flags
,
106 ptr
->type_descriptor
, dbgstr_type_info(ptr
->type_descriptor
), ptr
->type_hierarchy
);
107 TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n",
108 h
->signature
, h
->attributes
, h
->array_len
, h
->base_classes
);
109 for (i
= 0; i
< h
->array_len
; i
++)
111 TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n",
112 h
->base_classes
->bases
[i
],
113 h
->base_classes
->bases
[i
]->num_base_classes
,
114 h
->base_classes
->bases
[i
]->offsets
.this_offset
,
115 h
->base_classes
->bases
[i
]->offsets
.vbase_descr
,
116 h
->base_classes
->bases
[i
]->offsets
.vbase_offset
,
117 h
->base_classes
->bases
[i
]->attributes
,
118 h
->base_classes
->bases
[i
]->type_descriptor
,
119 dbgstr_type_info(h
->base_classes
->bases
[i
]->type_descriptor
) );
123 /* Internal common ctor for exception */
124 static void WINAPI
EXCEPTION_ctor(exception
*_this
, const char** name
)
126 _this
->vtable
= &MSVCRT_exception_vtable
;
129 unsigned int name_len
= strlen(*name
) + 1;
130 _this
->name
= MSVCRT_malloc(name_len
);
131 memcpy(_this
->name
, *name
, name_len
);
132 _this
->do_free
= TRUE
;
137 _this
->do_free
= FALSE
;
141 /******************************************************************
142 * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
144 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_ctor
,8)
145 exception
* __stdcall
MSVCRT_exception_ctor(exception
* _this
, const char ** name
)
147 TRACE("(%p,%s)\n", _this
, *name
);
148 EXCEPTION_ctor(_this
, name
);
152 /******************************************************************
153 * ??0exception@@QAE@ABQBDH@Z (MSVCRT.@)
155 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_ctor_noalloc
,12)
156 exception
* __stdcall
MSVCRT_exception_ctor_noalloc(exception
* _this
, char ** name
, int noalloc
)
158 TRACE("(%p,%s)\n", _this
, *name
);
159 _this
->vtable
= &MSVCRT_exception_vtable
;
161 _this
->do_free
= FALSE
;
165 /******************************************************************
166 * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
168 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_copy_ctor
,8)
169 exception
* __stdcall
MSVCRT_exception_copy_ctor(exception
* _this
, const exception
* rhs
)
171 TRACE("(%p,%p)\n", _this
, rhs
);
175 _this
->vtable
= &MSVCRT_exception_vtable
;
176 _this
->name
= rhs
->name
;
177 _this
->do_free
= FALSE
;
180 EXCEPTION_ctor(_this
, (const char**)&rhs
->name
);
181 TRACE("name = %s\n", _this
->name
);
185 /******************************************************************
186 * ??0exception@@QAE@XZ (MSVCRT.@)
188 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_default_ctor
,4)
189 exception
* __stdcall
MSVCRT_exception_default_ctor(exception
* _this
)
191 static const char* empty
= NULL
;
193 TRACE("(%p)\n", _this
);
194 EXCEPTION_ctor(_this
, &empty
);
198 /******************************************************************
199 * ??1exception@@UAE@XZ (MSVCRT.@)
201 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_dtor
,4)
202 void __stdcall
MSVCRT_exception_dtor(exception
* _this
)
204 TRACE("(%p)\n", _this
);
205 _this
->vtable
= &MSVCRT_exception_vtable
;
206 if (_this
->do_free
) MSVCRT_free(_this
->name
);
209 /******************************************************************
210 * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
212 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_opequals
,8)
213 exception
* __stdcall
MSVCRT_exception_opequals(exception
* _this
, const exception
* rhs
)
215 TRACE("(%p %p)\n", _this
, rhs
);
218 MSVCRT_exception_dtor(_this
);
219 MSVCRT_exception_copy_ctor(_this
, rhs
);
221 TRACE("name = %s\n", _this
->name
);
225 /******************************************************************
226 * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
228 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_vector_dtor
,8)
229 void * __stdcall
MSVCRT_exception_vector_dtor(exception
* _this
, unsigned int flags
)
231 TRACE("(%p %x)\n", _this
, flags
);
234 /* we have an array, with the number of elements stored before the first object */
235 int i
, *ptr
= (int *)_this
- 1;
237 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_exception_dtor(_this
+ i
);
238 MSVCRT_operator_delete(ptr
);
242 MSVCRT_exception_dtor(_this
);
243 if (flags
& 1) MSVCRT_operator_delete(_this
);
248 /******************************************************************
249 * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
251 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_scalar_dtor
,8)
252 void * __stdcall
MSVCRT_exception_scalar_dtor(exception
* _this
, unsigned int flags
)
254 TRACE("(%p %x)\n", _this
, flags
);
255 MSVCRT_exception_dtor(_this
);
256 if (flags
& 1) MSVCRT_operator_delete(_this
);
260 /******************************************************************
261 * ?what@exception@@UBEPBDXZ (MSVCRT.@)
263 DEFINE_THISCALL_WRAPPER(MSVCRT_what_exception
,4)
264 const char * __stdcall
MSVCRT_what_exception(exception
* _this
)
266 TRACE("(%p) returning %s\n", _this
, _this
->name
);
267 return _this
->name
? _this
->name
: "Unknown exception";
270 /******************************************************************
271 * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
273 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_copy_ctor
,8)
274 bad_typeid
* __stdcall
MSVCRT_bad_typeid_copy_ctor(bad_typeid
* _this
, const bad_typeid
* rhs
)
276 TRACE("(%p %p)\n", _this
, rhs
);
277 MSVCRT_exception_copy_ctor(_this
, rhs
);
278 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
282 /******************************************************************
283 * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
285 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_ctor
,8)
286 bad_typeid
* __stdcall
MSVCRT_bad_typeid_ctor(bad_typeid
* _this
, const char * name
)
288 TRACE("(%p %s)\n", _this
, name
);
289 EXCEPTION_ctor(_this
, &name
);
290 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
294 /******************************************************************
295 * ??_Fbad_typeid@@QAEXXZ (MSVCRT.@)
297 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_default_ctor
,4)
298 bad_typeid
* __stdcall
MSVCRT_bad_typeid_default_ctor(bad_typeid
* _this
)
300 return MSVCRT_bad_typeid_ctor( _this
, "bad typeid" );
303 /******************************************************************
304 * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
306 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_dtor
,4)
307 void __stdcall
MSVCRT_bad_typeid_dtor(bad_typeid
* _this
)
309 TRACE("(%p)\n", _this
);
310 MSVCRT_exception_dtor(_this
);
313 /******************************************************************
314 * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
316 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_opequals
,8)
317 bad_typeid
* __stdcall
MSVCRT_bad_typeid_opequals(bad_typeid
* _this
, const bad_typeid
* rhs
)
319 TRACE("(%p %p)\n", _this
, rhs
);
320 MSVCRT_exception_opequals(_this
, rhs
);
324 /******************************************************************
325 * ??_Ebad_typeid@@UAEPAXI@Z (MSVCRT.@)
327 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_vector_dtor
,8)
328 void * __stdcall
MSVCRT_bad_typeid_vector_dtor(bad_typeid
* _this
, unsigned int flags
)
330 TRACE("(%p %x)\n", _this
, flags
);
333 /* we have an array, with the number of elements stored before the first object */
334 int i
, *ptr
= (int *)_this
- 1;
336 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_typeid_dtor(_this
+ i
);
337 MSVCRT_operator_delete(ptr
);
341 MSVCRT_bad_typeid_dtor(_this
);
342 if (flags
& 1) MSVCRT_operator_delete(_this
);
347 /******************************************************************
348 * ??_Gbad_typeid@@UAEPAXI@Z (MSVCRT.@)
350 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_scalar_dtor
,8)
351 void * __stdcall
MSVCRT_bad_typeid_scalar_dtor(bad_typeid
* _this
, unsigned int flags
)
353 TRACE("(%p %x)\n", _this
, flags
);
354 MSVCRT_bad_typeid_dtor(_this
);
355 if (flags
& 1) MSVCRT_operator_delete(_this
);
359 /******************************************************************
360 * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
362 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_copy_ctor
,8)
363 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object
* _this
,
364 const __non_rtti_object
* rhs
)
366 TRACE("(%p %p)\n", _this
, rhs
);
367 MSVCRT_bad_typeid_copy_ctor(_this
, rhs
);
368 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
372 /******************************************************************
373 * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
375 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_ctor
,8)
376 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_ctor(__non_rtti_object
* _this
,
379 TRACE("(%p %s)\n", _this
, name
);
380 EXCEPTION_ctor(_this
, &name
);
381 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
385 /******************************************************************
386 * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
388 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_dtor
,4)
389 void __stdcall
MSVCRT___non_rtti_object_dtor(__non_rtti_object
* _this
)
391 TRACE("(%p)\n", _this
);
392 MSVCRT_bad_typeid_dtor(_this
);
395 /******************************************************************
396 * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
398 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_opequals
,8)
399 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_opequals(__non_rtti_object
* _this
,
400 const __non_rtti_object
*rhs
)
402 TRACE("(%p %p)\n", _this
, rhs
);
403 MSVCRT_bad_typeid_opequals(_this
, rhs
);
407 /******************************************************************
408 * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
410 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_vector_dtor
,8)
411 void * __stdcall
MSVCRT___non_rtti_object_vector_dtor(__non_rtti_object
* _this
, unsigned int flags
)
413 TRACE("(%p %x)\n", _this
, flags
);
416 /* we have an array, with the number of elements stored before the first object */
417 int i
, *ptr
= (int *)_this
- 1;
419 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT___non_rtti_object_dtor(_this
+ i
);
420 MSVCRT_operator_delete(ptr
);
424 MSVCRT___non_rtti_object_dtor(_this
);
425 if (flags
& 1) MSVCRT_operator_delete(_this
);
430 /******************************************************************
431 * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
433 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_scalar_dtor
,8)
434 void * __stdcall
MSVCRT___non_rtti_object_scalar_dtor(__non_rtti_object
* _this
, unsigned int flags
)
436 TRACE("(%p %x)\n", _this
, flags
);
437 MSVCRT___non_rtti_object_dtor(_this
);
438 if (flags
& 1) MSVCRT_operator_delete(_this
);
442 /******************************************************************
443 * ??0bad_cast@@AAE@PBQBD@Z (MSVCRT.@)
444 * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
446 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_ctor
,8)
447 bad_cast
* __stdcall
MSVCRT_bad_cast_ctor(bad_cast
* _this
, const char ** name
)
449 TRACE("(%p %s)\n", _this
, *name
);
450 EXCEPTION_ctor(_this
, name
);
451 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
455 /******************************************************************
456 * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
458 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_copy_ctor
,8)
459 bad_cast
* __stdcall
MSVCRT_bad_cast_copy_ctor(bad_cast
* _this
, const bad_cast
* rhs
)
461 TRACE("(%p %p)\n", _this
, rhs
);
462 MSVCRT_exception_copy_ctor(_this
, rhs
);
463 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
467 /******************************************************************
468 * ??0bad_cast@@QAE@PBD@Z (MSVCRT.@)
470 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_ctor_charptr
,8)
471 bad_cast
* __stdcall
MSVCRT_bad_cast_ctor_charptr(bad_cast
* _this
, const char * name
)
473 TRACE("(%p %s)\n", _this
, name
);
474 EXCEPTION_ctor(_this
, &name
);
475 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
479 /******************************************************************
480 * ??_Fbad_cast@@QAEXXZ (MSVCRT.@)
482 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_default_ctor
,4)
483 bad_cast
* __stdcall
MSVCRT_bad_cast_default_ctor(bad_cast
* _this
)
485 return MSVCRT_bad_cast_ctor_charptr( _this
, "bad cast" );
488 /******************************************************************
489 * ??1bad_cast@@UAE@XZ (MSVCRT.@)
491 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_dtor
,4)
492 void __stdcall
MSVCRT_bad_cast_dtor(bad_cast
* _this
)
494 TRACE("(%p)\n", _this
);
495 MSVCRT_exception_dtor(_this
);
498 /******************************************************************
499 * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
501 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_opequals
,8)
502 bad_cast
* __stdcall
MSVCRT_bad_cast_opequals(bad_cast
* _this
, const bad_cast
* rhs
)
504 TRACE("(%p %p)\n", _this
, rhs
);
505 MSVCRT_exception_opequals(_this
, rhs
);
509 /******************************************************************
510 * ??_Ebad_cast@@UAEPAXI@Z (MSVCRT.@)
512 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_vector_dtor
,8)
513 void * __stdcall
MSVCRT_bad_cast_vector_dtor(bad_cast
* _this
, unsigned int flags
)
515 TRACE("(%p %x)\n", _this
, flags
);
518 /* we have an array, with the number of elements stored before the first object */
519 int i
, *ptr
= (int *)_this
- 1;
521 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_cast_dtor(_this
+ i
);
522 MSVCRT_operator_delete(ptr
);
526 MSVCRT_bad_cast_dtor(_this
);
527 if (flags
& 1) MSVCRT_operator_delete(_this
);
532 /******************************************************************
533 * ??_Gbad_cast@@UAEPAXI@Z (MSVCRT.@)
535 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_scalar_dtor
,8)
536 void * __stdcall
MSVCRT_bad_cast_scalar_dtor(bad_cast
* _this
, unsigned int flags
)
538 TRACE("(%p %x)\n", _this
, flags
);
539 MSVCRT_bad_cast_dtor(_this
);
540 if (flags
& 1) MSVCRT_operator_delete(_this
);
544 /******************************************************************
545 * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
547 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opequals_equals
,8)
548 int __stdcall
MSVCRT_type_info_opequals_equals(type_info
* _this
, const type_info
* rhs
)
550 int ret
= !strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
551 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
555 /******************************************************************
556 * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
558 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opnot_equals
,8)
559 int __stdcall
MSVCRT_type_info_opnot_equals(type_info
* _this
, const type_info
* rhs
)
561 int ret
= !!strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
562 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
566 /******************************************************************
567 * ?before@type_info@@QBEHABV1@@Z (MSVCRT.@)
569 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_before
,8)
570 int __stdcall
MSVCRT_type_info_before(type_info
* _this
, const type_info
* rhs
)
572 int ret
= strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1) < 0;
573 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
577 /******************************************************************
578 * ??1type_info@@UAE@XZ (MSVCRT.@)
580 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_dtor
,4)
581 void __stdcall
MSVCRT_type_info_dtor(type_info
* _this
)
583 TRACE("(%p)\n", _this
);
584 MSVCRT_free(_this
->name
);
587 /******************************************************************
588 * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
590 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_name
,4)
591 const char * __stdcall
MSVCRT_type_info_name(type_info
* _this
)
595 /* Create and set the demangled name */
596 /* Nota: mangled name in type_info struct always start with a '.', while
597 * it isn't valid for mangled name.
598 * Is this '.' really part of the mangled name, or has it some other meaning ?
600 char* name
= __unDName(0, _this
->mangled
+ 1, 0,
601 MSVCRT_malloc
, MSVCRT_free
, 0x2800);
605 unsigned int len
= strlen(name
);
607 /* It seems _unDName may leave blanks at the end of the demangled name */
608 while (len
&& name
[--len
] == ' ')
615 /* Another thread set this member since we checked above - use it */
621 _munlock(_EXIT_LOCK2
);
624 TRACE("(%p) returning %s\n", _this
, _this
->name
);
628 /******************************************************************
629 * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
631 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_raw_name
,4)
632 const char * __stdcall
MSVCRT_type_info_raw_name(type_info
* _this
)
634 TRACE("(%p) returning %s\n", _this
, _this
->mangled
);
635 return _this
->mangled
;
639 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_vector_dtor
,8)
640 void * __stdcall
MSVCRT_type_info_vector_dtor(type_info
* _this
, unsigned int flags
)
642 TRACE("(%p %x)\n", _this
, flags
);
645 /* we have an array, with the number of elements stored before the first object */
646 int i
, *ptr
= (int *)_this
- 1;
648 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_type_info_dtor(_this
+ i
);
649 MSVCRT_operator_delete(ptr
);
653 MSVCRT_type_info_dtor(_this
);
654 if (flags
& 1) MSVCRT_operator_delete(_this
);
663 #define __ASM_VTABLE(name,funcs) \
666 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
667 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
668 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
669 "\t.quad " THISCALL_NAME(MSVCRT_ ## name ## _vector_dtor) "\n" \
672 #define __ASM_EXCEPTION_VTABLE(name) \
673 __ASM_VTABLE(name, "\t.quad " THISCALL_NAME(MSVCRT_what_exception) )
677 #define __ASM_VTABLE(name,funcs) \
680 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
681 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
682 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
683 "\t.long " THISCALL_NAME(MSVCRT_ ## name ## _vector_dtor) "\n" \
686 #define __ASM_EXCEPTION_VTABLE(name) \
687 __ASM_VTABLE(name, "\t.long " THISCALL_NAME(MSVCRT_what_exception) )
692 void __asm_dummy_vtables(void) {
695 __ASM_VTABLE(type_info
,"")
696 __ASM_EXCEPTION_VTABLE(exception
)
697 __ASM_EXCEPTION_VTABLE(bad_typeid
)
698 __ASM_EXCEPTION_VTABLE(bad_cast
)
699 __ASM_EXCEPTION_VTABLE(__non_rtti_object
)
705 /* Static RTTI for exported objects */
707 static const type_info exception_type_info
=
709 &MSVCRT_type_info_vtable
,
714 static const rtti_base_descriptor exception_rtti_base_descriptor
=
716 &exception_type_info
,
722 static const rtti_base_array exception_rtti_base_array
=
725 &exception_rtti_base_descriptor
,
731 static const rtti_object_hierarchy exception_type_hierarchy
=
736 &exception_rtti_base_array
739 const rtti_object_locator exception_rtti
=
744 &exception_type_info
,
745 &exception_type_hierarchy
748 static const cxx_type_info exception_cxx_type_info
=
751 &exception_type_info
,
754 (cxx_copy_ctor
)THISCALL(MSVCRT_exception_copy_ctor
)
757 static const type_info bad_typeid_type_info
=
759 &MSVCRT_type_info_vtable
,
764 static const rtti_base_descriptor bad_typeid_rtti_base_descriptor
=
766 &bad_typeid_type_info
,
772 static const rtti_base_array bad_typeid_rtti_base_array
=
775 &bad_typeid_rtti_base_descriptor
,
776 &exception_rtti_base_descriptor
,
781 static const rtti_object_hierarchy bad_typeid_type_hierarchy
=
786 &bad_typeid_rtti_base_array
789 const rtti_object_locator bad_typeid_rtti
=
794 &bad_typeid_type_info
,
795 &bad_typeid_type_hierarchy
798 static const cxx_type_info bad_typeid_cxx_type_info
=
801 &bad_typeid_type_info
,
804 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_typeid_copy_ctor
)
807 static const type_info bad_cast_type_info
=
809 &MSVCRT_type_info_vtable
,
814 static const rtti_base_descriptor bad_cast_rtti_base_descriptor
=
822 static const rtti_base_array bad_cast_rtti_base_array
=
825 &bad_cast_rtti_base_descriptor
,
826 &exception_rtti_base_descriptor
,
831 static const rtti_object_hierarchy bad_cast_type_hierarchy
=
836 &bad_cast_rtti_base_array
839 const rtti_object_locator bad_cast_rtti
=
845 &bad_cast_type_hierarchy
848 static const cxx_type_info bad_cast_cxx_type_info
=
854 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_cast_copy_ctor
)
857 static const type_info __non_rtti_object_type_info
=
859 &MSVCRT_type_info_vtable
,
861 ".?AV__non_rtti_object@@"
864 static const rtti_base_descriptor __non_rtti_object_rtti_base_descriptor
=
866 &__non_rtti_object_type_info
,
872 static const rtti_base_array __non_rtti_object_rtti_base_array
=
875 &__non_rtti_object_rtti_base_descriptor
,
876 &bad_typeid_rtti_base_descriptor
,
877 &exception_rtti_base_descriptor
881 static const rtti_object_hierarchy __non_rtti_object_type_hierarchy
=
886 &__non_rtti_object_rtti_base_array
889 const rtti_object_locator __non_rtti_object_rtti
=
894 &__non_rtti_object_type_info
,
895 &__non_rtti_object_type_hierarchy
898 static const cxx_type_info __non_rtti_object_cxx_type_info
=
901 &__non_rtti_object_type_info
,
904 (cxx_copy_ctor
)THISCALL(MSVCRT___non_rtti_object_copy_ctor
)
907 static const type_info type_info_type_info
=
909 &MSVCRT_type_info_vtable
,
914 static const rtti_base_descriptor type_info_rtti_base_descriptor
=
916 &type_info_type_info
,
922 static const rtti_base_array type_info_rtti_base_array
=
925 &type_info_rtti_base_descriptor
,
931 static const rtti_object_hierarchy type_info_type_hierarchy
=
936 &type_info_rtti_base_array
939 const rtti_object_locator type_info_rtti
=
944 &type_info_type_info
,
945 &type_info_type_hierarchy
949 * Exception RTTI for cpp objects
951 static const cxx_type_info_table bad_cast_type_info_table
=
955 &__non_rtti_object_cxx_type_info
,
956 &bad_typeid_cxx_type_info
,
957 &exception_cxx_type_info
961 static const cxx_exception_type bad_cast_exception_type
=
964 (void*)THISCALL(MSVCRT_bad_cast_dtor
),
966 &bad_cast_type_info_table
969 static const cxx_type_info_table bad_typeid_type_info_table
=
973 &bad_cast_cxx_type_info
,
974 &exception_cxx_type_info
,
979 static const cxx_exception_type bad_typeid_exception_type
=
982 (void*)THISCALL(MSVCRT_bad_typeid_dtor
),
984 &bad_cast_type_info_table
987 static const cxx_exception_type __non_rtti_object_exception_type
=
990 (void*)THISCALL(MSVCRT___non_rtti_object_dtor
),
992 &bad_typeid_type_info_table
996 /******************************************************************
997 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
999 * Install a handler to be called when terminate() is called.
1002 * func [I] Handler function to install
1005 * The previously installed handler function, if any.
1007 terminate_function CDECL
MSVCRT_set_terminate(terminate_function func
)
1009 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1010 terminate_function previous
= data
->terminate_handler
;
1011 TRACE("(%p) returning %p\n",func
,previous
);
1012 data
->terminate_handler
= func
;
1016 /******************************************************************
1017 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
1019 * Install a handler to be called when unexpected() is called.
1022 * func [I] Handler function to install
1025 * The previously installed handler function, if any.
1027 unexpected_function CDECL
MSVCRT_set_unexpected(unexpected_function func
)
1029 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1030 unexpected_function previous
= data
->unexpected_handler
;
1031 TRACE("(%p) returning %p\n",func
,previous
);
1032 data
->unexpected_handler
= func
;
1036 /******************************************************************
1037 * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@)
1039 _se_translator_function CDECL
MSVCRT__set_se_translator(_se_translator_function func
)
1041 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1042 _se_translator_function previous
= data
->se_translator
;
1043 TRACE("(%p) returning %p\n",func
,previous
);
1044 data
->se_translator
= func
;
1048 /******************************************************************
1049 * ?terminate@@YAXXZ (MSVCRT.@)
1051 * Default handler for an unhandled exception.
1057 * This function does not return. Either control resumes from any
1058 * handler installed by calling set_terminate(), or (by default) abort()
1061 void CDECL
MSVCRT_terminate(void)
1063 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1064 if (data
->terminate_handler
) data
->terminate_handler();
1068 /******************************************************************
1069 * ?unexpected@@YAXXZ (MSVCRT.@)
1071 void CDECL
MSVCRT_unexpected(void)
1073 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1074 if (data
->unexpected_handler
) data
->unexpected_handler();
1079 /******************************************************************
1080 * __RTtypeid (MSVCRT.@)
1082 * Retrieve the Run Time Type Information (RTTI) for a C++ object.
1085 * cppobj [I] C++ object to get type information for.
1088 * Success: A type_info object describing cppobj.
1089 * Failure: If the object to be cast has no RTTI, a __non_rtti_object
1090 * exception is thrown. If cppobj is NULL, a bad_typeid exception
1091 * is thrown. In either case, this function does not return.
1094 * This function is usually called by compiler generated code as a result
1095 * of using one of the C++ dynamic cast statements.
1097 const type_info
* CDECL
MSVCRT___RTtypeid(void *cppobj
)
1099 const type_info
*ret
;
1104 MSVCRT_bad_typeid_ctor( &e
, "Attempted a typeid of NULL pointer!" );
1105 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1111 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1112 ret
= obj_locator
->type_descriptor
;
1116 __non_rtti_object e
;
1117 MSVCRT___non_rtti_object_ctor( &e
, "Bad read pointer - no RTTI data!" );
1118 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1125 /******************************************************************
1126 * __RTDynamicCast (MSVCRT.@)
1128 * Dynamically cast a C++ object to one of its base classes.
1131 * cppobj [I] Any C++ object to cast
1132 * unknown [I] Reserved, set to 0
1133 * src [I] type_info object describing cppobj
1134 * dst [I] type_info object describing the base class to cast to
1135 * do_throw [I] TRUE = throw an exception if the cast fails, FALSE = don't
1138 * Success: The address of cppobj, cast to the object described by dst.
1139 * Failure: NULL, If the object to be cast has no RTTI, or dst is not a
1140 * valid cast for cppobj. If do_throw is TRUE, a bad_cast exception
1141 * is thrown and this function does not return.
1144 * This function is usually called by compiler generated code as a result
1145 * of using one of the C++ dynamic cast statements.
1147 void* CDECL
MSVCRT___RTDynamicCast(void *cppobj
, int unknown
,
1148 type_info
*src
, type_info
*dst
,
1153 if (!cppobj
) return NULL
;
1155 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1156 cppobj
, unknown
, src
, dbgstr_type_info(src
), dst
, dbgstr_type_info(dst
), do_throw
);
1158 /* To cast an object at runtime:
1159 * 1.Find out the true type of the object from the typeinfo at vtable[-1]
1160 * 2.Search for the destination type in the class hierarchy
1161 * 3.If destination type is found, return base object address + dest offset
1162 * Otherwise, fail the cast
1164 * FIXME: the unknown parameter doesn't seem to be used for anything
1169 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1170 const rtti_object_hierarchy
*obj_bases
= obj_locator
->type_hierarchy
;
1171 const rtti_base_descriptor
* const* base_desc
= obj_bases
->base_classes
->bases
;
1173 if (TRACE_ON(msvcrt
)) dump_obj_locator(obj_locator
);
1176 for (i
= 0; i
< obj_bases
->array_len
; i
++)
1178 const type_info
*typ
= base_desc
[i
]->type_descriptor
;
1180 if (!strcmp(typ
->mangled
, dst
->mangled
))
1182 /* compute the correct this pointer for that base class */
1183 void *this_ptr
= (char *)cppobj
- obj_locator
->base_class_offset
;
1184 ret
= get_this_pointer( &base_desc
[i
]->offsets
, this_ptr
);
1188 /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned
1189 * to a reference, since references cannot be NULL.
1191 if (!ret
&& do_throw
)
1193 const char *msg
= "Bad dynamic_cast!";
1195 MSVCRT_bad_cast_ctor( &e
, &msg
);
1196 _CxxThrowException( &e
, &bad_cast_exception_type
);
1201 __non_rtti_object e
;
1202 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1203 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1211 /******************************************************************
1212 * __RTCastToVoid (MSVCRT.@)
1214 * Dynamically cast a C++ object to a void*.
1217 * cppobj [I] The C++ object to cast
1220 * Success: The base address of the object as a void*.
1221 * Failure: NULL, if cppobj is NULL or has no RTTI.
1224 * This function is usually called by compiler generated code as a result
1225 * of using one of the C++ dynamic cast statements.
1227 void* CDECL
MSVCRT___RTCastToVoid(void *cppobj
)
1231 if (!cppobj
) return NULL
;
1235 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1236 ret
= (char *)cppobj
- obj_locator
->base_class_offset
;
1240 __non_rtti_object e
;
1241 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1242 _CxxThrowException( &e
, &bad_typeid_exception_type
);