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)
68 #include <internal/wine_msc.h>
70 #define DEFINE_THISCALL_WRAPPER(func,args) \
71 extern void THISCALL(func)(void); \
72 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
76 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
81 #define THISCALL(func) func
82 #define THISCALL_NAME(func) __ASM_NAME(#func)
83 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
87 extern const vtable_ptr MSVCRT_exception_vtable
;
88 extern const vtable_ptr MSVCRT_bad_typeid_vtable
;
89 extern const vtable_ptr MSVCRT_bad_cast_vtable
;
90 extern const vtable_ptr MSVCRT___non_rtti_object_vtable
;
91 extern const vtable_ptr MSVCRT_type_info_vtable
;
93 /* get the vtable pointer for a C++ object */
94 static inline const vtable_ptr
*get_vtable( void *obj
)
96 return *(const vtable_ptr
**)obj
;
99 static inline const rtti_object_locator
*get_obj_locator( void *cppobj
)
101 const vtable_ptr
*vtable
= get_vtable( cppobj
);
102 return (const rtti_object_locator
*)vtable
[-1];
105 static void dump_obj_locator( const rtti_object_locator
*ptr
)
108 const rtti_object_hierarchy
*h
= ptr
->type_hierarchy
;
110 TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n",
111 ptr
, ptr
->signature
, ptr
->base_class_offset
, ptr
->flags
,
112 ptr
->type_descriptor
, dbgstr_type_info(ptr
->type_descriptor
), ptr
->type_hierarchy
);
113 TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n",
114 h
->signature
, h
->attributes
, h
->array_len
, h
->base_classes
);
115 for (i
= 0; i
< h
->array_len
; i
++)
117 TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n",
118 h
->base_classes
->bases
[i
],
119 h
->base_classes
->bases
[i
]->num_base_classes
,
120 h
->base_classes
->bases
[i
]->offsets
.this_offset
,
121 h
->base_classes
->bases
[i
]->offsets
.vbase_descr
,
122 h
->base_classes
->bases
[i
]->offsets
.vbase_offset
,
123 h
->base_classes
->bases
[i
]->attributes
,
124 h
->base_classes
->bases
[i
]->type_descriptor
,
125 dbgstr_type_info(h
->base_classes
->bases
[i
]->type_descriptor
) );
129 /* Internal common ctor for exception */
130 static void WINAPI
EXCEPTION_ctor(exception
*_this
, const char** name
)
132 _this
->vtable
= &MSVCRT_exception_vtable
;
135 unsigned int name_len
= strlen(*name
) + 1;
136 _this
->name
= MSVCRT_malloc(name_len
);
137 memcpy(_this
->name
, *name
, name_len
);
138 _this
->do_free
= TRUE
;
143 _this
->do_free
= FALSE
;
147 /******************************************************************
148 * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
150 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_ctor
,8)
151 exception
* __stdcall
MSVCRT_exception_ctor(exception
* _this
, const char ** name
)
153 TRACE("(%p,%s)\n", _this
, *name
);
154 EXCEPTION_ctor(_this
, name
);
158 /******************************************************************
159 * ??0exception@@QAE@ABQBDH@Z (MSVCRT.@)
161 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_ctor_noalloc
,12)
162 exception
* __stdcall
MSVCRT_exception_ctor_noalloc(exception
* _this
, char ** name
, int noalloc
)
164 TRACE("(%p,%s)\n", _this
, *name
);
165 _this
->vtable
= &MSVCRT_exception_vtable
;
167 _this
->do_free
= FALSE
;
171 /******************************************************************
172 * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
174 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_copy_ctor
,8)
175 exception
* __stdcall
MSVCRT_exception_copy_ctor(exception
* _this
, const exception
* rhs
)
177 TRACE("(%p,%p)\n", _this
, rhs
);
181 _this
->vtable
= &MSVCRT_exception_vtable
;
182 _this
->name
= rhs
->name
;
183 _this
->do_free
= FALSE
;
186 EXCEPTION_ctor(_this
, (const char**)&rhs
->name
);
187 TRACE("name = %s\n", _this
->name
);
191 /******************************************************************
192 * ??0exception@@QAE@XZ (MSVCRT.@)
194 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_default_ctor
,4)
195 exception
* __stdcall
MSVCRT_exception_default_ctor(exception
* _this
)
197 static const char* empty
= NULL
;
199 TRACE("(%p)\n", _this
);
200 EXCEPTION_ctor(_this
, &empty
);
204 /******************************************************************
205 * ??1exception@@UAE@XZ (MSVCRT.@)
207 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_dtor
,4)
208 void __stdcall
MSVCRT_exception_dtor(exception
* _this
)
210 TRACE("(%p)\n", _this
);
211 _this
->vtable
= &MSVCRT_exception_vtable
;
212 if (_this
->do_free
) MSVCRT_free(_this
->name
);
215 /******************************************************************
216 * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
218 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_opequals
,8)
219 exception
* __stdcall
MSVCRT_exception_opequals(exception
* _this
, const exception
* rhs
)
221 TRACE("(%p %p)\n", _this
, rhs
);
224 MSVCRT_exception_dtor(_this
);
225 MSVCRT_exception_copy_ctor(_this
, rhs
);
227 TRACE("name = %s\n", _this
->name
);
231 /******************************************************************
232 * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
234 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_vector_dtor
,8)
235 void * __stdcall
MSVCRT_exception_vector_dtor(exception
* _this
, unsigned int flags
)
237 TRACE("(%p %x)\n", _this
, flags
);
240 /* we have an array, with the number of elements stored before the first object */
241 int i
, *ptr
= (int *)_this
- 1;
243 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_exception_dtor(_this
+ i
);
244 MSVCRT_operator_delete(ptr
);
248 MSVCRT_exception_dtor(_this
);
249 if (flags
& 1) MSVCRT_operator_delete(_this
);
254 /******************************************************************
255 * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
257 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_scalar_dtor
,8)
258 void * __stdcall
MSVCRT_exception_scalar_dtor(exception
* _this
, unsigned int flags
)
260 TRACE("(%p %x)\n", _this
, flags
);
261 MSVCRT_exception_dtor(_this
);
262 if (flags
& 1) MSVCRT_operator_delete(_this
);
266 /******************************************************************
267 * ?what@exception@@UBEPBDXZ (MSVCRT.@)
269 DEFINE_THISCALL_WRAPPER(MSVCRT_what_exception
,4)
270 const char * __stdcall
MSVCRT_what_exception(exception
* _this
)
272 TRACE("(%p) returning %s\n", _this
, _this
->name
);
273 return _this
->name
? _this
->name
: "Unknown exception";
276 /******************************************************************
277 * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
279 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_copy_ctor
,8)
280 bad_typeid
* __stdcall
MSVCRT_bad_typeid_copy_ctor(bad_typeid
* _this
, const bad_typeid
* rhs
)
282 TRACE("(%p %p)\n", _this
, rhs
);
283 MSVCRT_exception_copy_ctor(_this
, rhs
);
284 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
288 /******************************************************************
289 * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
291 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_ctor
,8)
292 bad_typeid
* __stdcall
MSVCRT_bad_typeid_ctor(bad_typeid
* _this
, const char * name
)
294 TRACE("(%p %s)\n", _this
, name
);
295 EXCEPTION_ctor(_this
, &name
);
296 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
300 /******************************************************************
301 * ??_Fbad_typeid@@QAEXXZ (MSVCRT.@)
303 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_default_ctor
,4)
304 bad_typeid
* __stdcall
MSVCRT_bad_typeid_default_ctor(bad_typeid
* _this
)
306 return MSVCRT_bad_typeid_ctor( _this
, "bad typeid" );
309 /******************************************************************
310 * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
312 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_dtor
,4)
313 void __stdcall
MSVCRT_bad_typeid_dtor(bad_typeid
* _this
)
315 TRACE("(%p)\n", _this
);
316 MSVCRT_exception_dtor(_this
);
319 /******************************************************************
320 * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
322 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_opequals
,8)
323 bad_typeid
* __stdcall
MSVCRT_bad_typeid_opequals(bad_typeid
* _this
, const bad_typeid
* rhs
)
325 TRACE("(%p %p)\n", _this
, rhs
);
326 MSVCRT_exception_opequals(_this
, rhs
);
330 /******************************************************************
331 * ??_Ebad_typeid@@UAEPAXI@Z (MSVCRT.@)
333 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_vector_dtor
,8)
334 void * __stdcall
MSVCRT_bad_typeid_vector_dtor(bad_typeid
* _this
, unsigned int flags
)
336 TRACE("(%p %x)\n", _this
, flags
);
339 /* we have an array, with the number of elements stored before the first object */
340 int i
, *ptr
= (int *)_this
- 1;
342 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_typeid_dtor(_this
+ i
);
343 MSVCRT_operator_delete(ptr
);
347 MSVCRT_bad_typeid_dtor(_this
);
348 if (flags
& 1) MSVCRT_operator_delete(_this
);
353 /******************************************************************
354 * ??_Gbad_typeid@@UAEPAXI@Z (MSVCRT.@)
356 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_scalar_dtor
,8)
357 void * __stdcall
MSVCRT_bad_typeid_scalar_dtor(bad_typeid
* _this
, unsigned int flags
)
359 TRACE("(%p %x)\n", _this
, flags
);
360 MSVCRT_bad_typeid_dtor(_this
);
361 if (flags
& 1) MSVCRT_operator_delete(_this
);
365 /******************************************************************
366 * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
368 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_copy_ctor
,8)
369 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object
* _this
,
370 const __non_rtti_object
* rhs
)
372 TRACE("(%p %p)\n", _this
, rhs
);
373 MSVCRT_bad_typeid_copy_ctor(_this
, rhs
);
374 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
378 /******************************************************************
379 * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
381 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_ctor
,8)
382 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_ctor(__non_rtti_object
* _this
,
385 TRACE("(%p %s)\n", _this
, name
);
386 EXCEPTION_ctor(_this
, &name
);
387 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
391 /******************************************************************
392 * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
394 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_dtor
,4)
395 void __stdcall
MSVCRT___non_rtti_object_dtor(__non_rtti_object
* _this
)
397 TRACE("(%p)\n", _this
);
398 MSVCRT_bad_typeid_dtor(_this
);
401 /******************************************************************
402 * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
404 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_opequals
,8)
405 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_opequals(__non_rtti_object
* _this
,
406 const __non_rtti_object
*rhs
)
408 TRACE("(%p %p)\n", _this
, rhs
);
409 MSVCRT_bad_typeid_opequals(_this
, rhs
);
413 /******************************************************************
414 * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
416 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_vector_dtor
,8)
417 void * __stdcall
MSVCRT___non_rtti_object_vector_dtor(__non_rtti_object
* _this
, unsigned int flags
)
419 TRACE("(%p %x)\n", _this
, flags
);
422 /* we have an array, with the number of elements stored before the first object */
423 int i
, *ptr
= (int *)_this
- 1;
425 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT___non_rtti_object_dtor(_this
+ i
);
426 MSVCRT_operator_delete(ptr
);
430 MSVCRT___non_rtti_object_dtor(_this
);
431 if (flags
& 1) MSVCRT_operator_delete(_this
);
436 /******************************************************************
437 * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
439 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_scalar_dtor
,8)
440 void * __stdcall
MSVCRT___non_rtti_object_scalar_dtor(__non_rtti_object
* _this
, unsigned int flags
)
442 TRACE("(%p %x)\n", _this
, flags
);
443 MSVCRT___non_rtti_object_dtor(_this
);
444 if (flags
& 1) MSVCRT_operator_delete(_this
);
448 /******************************************************************
449 * ??0bad_cast@@AAE@PBQBD@Z (MSVCRT.@)
450 * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
452 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_ctor
,8)
453 bad_cast
* __stdcall
MSVCRT_bad_cast_ctor(bad_cast
* _this
, const char ** name
)
455 TRACE("(%p %s)\n", _this
, *name
);
456 EXCEPTION_ctor(_this
, name
);
457 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
461 /******************************************************************
462 * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
464 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_copy_ctor
,8)
465 bad_cast
* __stdcall
MSVCRT_bad_cast_copy_ctor(bad_cast
* _this
, const bad_cast
* rhs
)
467 TRACE("(%p %p)\n", _this
, rhs
);
468 MSVCRT_exception_copy_ctor(_this
, rhs
);
469 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
473 /******************************************************************
474 * ??0bad_cast@@QAE@PBD@Z (MSVCRT.@)
476 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_ctor_charptr
,8)
477 bad_cast
* __stdcall
MSVCRT_bad_cast_ctor_charptr(bad_cast
* _this
, const char * name
)
479 TRACE("(%p %s)\n", _this
, name
);
480 EXCEPTION_ctor(_this
, &name
);
481 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
485 /******************************************************************
486 * ??_Fbad_cast@@QAEXXZ (MSVCRT.@)
488 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_default_ctor
,4)
489 bad_cast
* __stdcall
MSVCRT_bad_cast_default_ctor(bad_cast
* _this
)
491 return MSVCRT_bad_cast_ctor_charptr( _this
, "bad cast" );
494 /******************************************************************
495 * ??1bad_cast@@UAE@XZ (MSVCRT.@)
497 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_dtor
,4)
498 void __stdcall
MSVCRT_bad_cast_dtor(bad_cast
* _this
)
500 TRACE("(%p)\n", _this
);
501 MSVCRT_exception_dtor(_this
);
504 /******************************************************************
505 * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
507 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_opequals
,8)
508 bad_cast
* __stdcall
MSVCRT_bad_cast_opequals(bad_cast
* _this
, const bad_cast
* rhs
)
510 TRACE("(%p %p)\n", _this
, rhs
);
511 MSVCRT_exception_opequals(_this
, rhs
);
515 /******************************************************************
516 * ??_Ebad_cast@@UAEPAXI@Z (MSVCRT.@)
518 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_vector_dtor
,8)
519 void * __stdcall
MSVCRT_bad_cast_vector_dtor(bad_cast
* _this
, unsigned int flags
)
521 TRACE("(%p %x)\n", _this
, flags
);
524 /* we have an array, with the number of elements stored before the first object */
525 int i
, *ptr
= (int *)_this
- 1;
527 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_cast_dtor(_this
+ i
);
528 MSVCRT_operator_delete(ptr
);
532 MSVCRT_bad_cast_dtor(_this
);
533 if (flags
& 1) MSVCRT_operator_delete(_this
);
538 /******************************************************************
539 * ??_Gbad_cast@@UAEPAXI@Z (MSVCRT.@)
541 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_scalar_dtor
,8)
542 void * __stdcall
MSVCRT_bad_cast_scalar_dtor(bad_cast
* _this
, unsigned int flags
)
544 TRACE("(%p %x)\n", _this
, flags
);
545 MSVCRT_bad_cast_dtor(_this
);
546 if (flags
& 1) MSVCRT_operator_delete(_this
);
550 /******************************************************************
551 * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
553 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opequals_equals
,8)
554 int __stdcall
MSVCRT_type_info_opequals_equals(type_info
* _this
, const type_info
* rhs
)
556 int ret
= !strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
557 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
561 /******************************************************************
562 * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
564 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opnot_equals
,8)
565 int __stdcall
MSVCRT_type_info_opnot_equals(type_info
* _this
, const type_info
* rhs
)
567 int ret
= !!strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
568 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
572 /******************************************************************
573 * ?before@type_info@@QBEHABV1@@Z (MSVCRT.@)
575 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_before
,8)
576 int __stdcall
MSVCRT_type_info_before(type_info
* _this
, const type_info
* rhs
)
578 int ret
= strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1) < 0;
579 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
583 /******************************************************************
584 * ??1type_info@@UAE@XZ (MSVCRT.@)
586 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_dtor
,4)
587 void __stdcall
MSVCRT_type_info_dtor(type_info
* _this
)
589 TRACE("(%p)\n", _this
);
590 MSVCRT_free(_this
->name
);
593 /******************************************************************
594 * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
596 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_name
,4)
597 const char * __stdcall
MSVCRT_type_info_name(type_info
* _this
)
601 /* Create and set the demangled name */
602 /* Nota: mangled name in type_info struct always start with a '.', while
603 * it isn't valid for mangled name.
604 * Is this '.' really part of the mangled name, or has it some other meaning ?
606 char* name
= __unDName(0, _this
->mangled
+ 1, 0,
607 MSVCRT_malloc
, MSVCRT_free
, 0x2800);
611 unsigned int len
= strlen(name
);
613 /* It seems _unDName may leave blanks at the end of the demangled name */
614 while (len
&& name
[--len
] == ' ')
621 /* Another thread set this member since we checked above - use it */
627 _munlock(_EXIT_LOCK2
);
630 TRACE("(%p) returning %s\n", _this
, _this
->name
);
634 /******************************************************************
635 * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
637 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_raw_name
,4)
638 const char * __stdcall
MSVCRT_type_info_raw_name(type_info
* _this
)
640 TRACE("(%p) returning %s\n", _this
, _this
->mangled
);
641 return _this
->mangled
;
645 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_vector_dtor
,8)
646 void * __stdcall
MSVCRT_type_info_vector_dtor(type_info
* _this
, unsigned int flags
)
648 TRACE("(%p %x)\n", _this
, flags
);
651 /* we have an array, with the number of elements stored before the first object */
652 int i
, *ptr
= (int *)_this
- 1;
654 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_type_info_dtor(_this
+ i
);
655 MSVCRT_operator_delete(ptr
);
659 MSVCRT_type_info_dtor(_this
);
660 if (flags
& 1) MSVCRT_operator_delete(_this
);
670 #define __ASM_VTABLE(name,funcs) \
673 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
674 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
675 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
676 "\t.quad " THISCALL_NAME(MSVCRT_ ## name ## _vector_dtor) "\n" \
679 #define __ASM_EXCEPTION_VTABLE(name) \
680 __ASM_VTABLE(name, "\t.quad " THISCALL_NAME(MSVCRT_what_exception) )
684 #define __ASM_VTABLE(name,funcs) \
687 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
688 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
689 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
690 "\t.long " THISCALL_NAME(MSVCRT_ ## name ## _vector_dtor) "\n" \
693 #define __ASM_EXCEPTION_VTABLE(name) \
694 __ASM_VTABLE(name, "\t.long " THISCALL_NAME(MSVCRT_what_exception) )
699 void __asm_dummy_vtables(void) {
702 __ASM_VTABLE(type_info
,"")
703 __ASM_EXCEPTION_VTABLE(exception
)
704 __ASM_EXCEPTION_VTABLE(bad_typeid
)
705 __ASM_EXCEPTION_VTABLE(bad_cast
)
706 __ASM_EXCEPTION_VTABLE(__non_rtti_object
)
714 #pragma message ("HAXX!")
715 const vtable_ptr MSVCRT_exception_vtable
;
716 const vtable_ptr MSVCRT_bad_typeid_vtable
;
717 const vtable_ptr MSVCRT_bad_cast_vtable
;
718 const vtable_ptr MSVCRT___non_rtti_object_vtable
;
719 const vtable_ptr MSVCRT_type_info_vtable
;
722 /* Static RTTI for exported objects */
724 static const type_info exception_type_info
=
726 &MSVCRT_type_info_vtable
,
731 static const rtti_base_descriptor exception_rtti_base_descriptor
=
733 &exception_type_info
,
739 static const rtti_base_array exception_rtti_base_array
=
742 &exception_rtti_base_descriptor
,
748 static const rtti_object_hierarchy exception_type_hierarchy
=
753 &exception_rtti_base_array
756 const rtti_object_locator exception_rtti
=
761 &exception_type_info
,
762 &exception_type_hierarchy
765 static const cxx_type_info exception_cxx_type_info
=
768 &exception_type_info
,
771 (cxx_copy_ctor
)THISCALL(MSVCRT_exception_copy_ctor
)
774 static const type_info bad_typeid_type_info
=
776 &MSVCRT_type_info_vtable
,
781 static const rtti_base_descriptor bad_typeid_rtti_base_descriptor
=
783 &bad_typeid_type_info
,
789 static const rtti_base_array bad_typeid_rtti_base_array
=
792 &bad_typeid_rtti_base_descriptor
,
793 &exception_rtti_base_descriptor
,
798 static const rtti_object_hierarchy bad_typeid_type_hierarchy
=
803 &bad_typeid_rtti_base_array
806 const rtti_object_locator bad_typeid_rtti
=
811 &bad_typeid_type_info
,
812 &bad_typeid_type_hierarchy
815 static const cxx_type_info bad_typeid_cxx_type_info
=
818 &bad_typeid_type_info
,
821 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_typeid_copy_ctor
)
824 static const type_info bad_cast_type_info
=
826 &MSVCRT_type_info_vtable
,
831 static const rtti_base_descriptor bad_cast_rtti_base_descriptor
=
839 static const rtti_base_array bad_cast_rtti_base_array
=
842 &bad_cast_rtti_base_descriptor
,
843 &exception_rtti_base_descriptor
,
848 static const rtti_object_hierarchy bad_cast_type_hierarchy
=
853 &bad_cast_rtti_base_array
856 const rtti_object_locator bad_cast_rtti
=
862 &bad_cast_type_hierarchy
865 static const cxx_type_info bad_cast_cxx_type_info
=
871 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_cast_copy_ctor
)
874 static const type_info __non_rtti_object_type_info
=
876 &MSVCRT_type_info_vtable
,
878 ".?AV__non_rtti_object@@"
881 static const rtti_base_descriptor __non_rtti_object_rtti_base_descriptor
=
883 &__non_rtti_object_type_info
,
889 static const rtti_base_array __non_rtti_object_rtti_base_array
=
892 &__non_rtti_object_rtti_base_descriptor
,
893 &bad_typeid_rtti_base_descriptor
,
894 &exception_rtti_base_descriptor
898 static const rtti_object_hierarchy __non_rtti_object_type_hierarchy
=
903 &__non_rtti_object_rtti_base_array
906 const rtti_object_locator __non_rtti_object_rtti
=
911 &__non_rtti_object_type_info
,
912 &__non_rtti_object_type_hierarchy
915 static const cxx_type_info __non_rtti_object_cxx_type_info
=
918 &__non_rtti_object_type_info
,
921 (cxx_copy_ctor
)THISCALL(MSVCRT___non_rtti_object_copy_ctor
)
924 static const type_info type_info_type_info
=
926 &MSVCRT_type_info_vtable
,
931 static const rtti_base_descriptor type_info_rtti_base_descriptor
=
933 &type_info_type_info
,
939 static const rtti_base_array type_info_rtti_base_array
=
942 &type_info_rtti_base_descriptor
,
948 static const rtti_object_hierarchy type_info_type_hierarchy
=
953 &type_info_rtti_base_array
956 const rtti_object_locator type_info_rtti
=
961 &type_info_type_info
,
962 &type_info_type_hierarchy
966 * Exception RTTI for cpp objects
968 static const cxx_type_info_table bad_cast_type_info_table
=
972 &__non_rtti_object_cxx_type_info
,
973 &bad_typeid_cxx_type_info
,
974 &exception_cxx_type_info
978 static const cxx_exception_type bad_cast_exception_type
=
981 (void*)THISCALL(MSVCRT_bad_cast_dtor
),
983 &bad_cast_type_info_table
986 static const cxx_type_info_table bad_typeid_type_info_table
=
990 &bad_cast_cxx_type_info
,
991 &exception_cxx_type_info
,
996 static const cxx_exception_type bad_typeid_exception_type
=
999 (void*)THISCALL(MSVCRT_bad_typeid_dtor
),
1001 &bad_cast_type_info_table
1004 static const cxx_exception_type __non_rtti_object_exception_type
=
1007 (void*)THISCALL(MSVCRT___non_rtti_object_dtor
),
1009 &bad_typeid_type_info_table
1013 /******************************************************************
1014 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
1016 * Install a handler to be called when terminate() is called.
1019 * func [I] Handler function to install
1022 * The previously installed handler function, if any.
1024 terminate_function CDECL
MSVCRT_set_terminate(terminate_function func
)
1026 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1027 terminate_function previous
= data
->terminate_handler
;
1028 TRACE("(%p) returning %p\n",func
,previous
);
1029 data
->terminate_handler
= func
;
1033 /******************************************************************
1034 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
1036 * Install a handler to be called when unexpected() is called.
1039 * func [I] Handler function to install
1042 * The previously installed handler function, if any.
1044 unexpected_function CDECL
MSVCRT_set_unexpected(unexpected_function func
)
1046 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1047 unexpected_function previous
= data
->unexpected_handler
;
1048 TRACE("(%p) returning %p\n",func
,previous
);
1049 data
->unexpected_handler
= func
;
1053 /******************************************************************
1054 * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@)
1056 _se_translator_function CDECL
MSVCRT__set_se_translator(_se_translator_function func
)
1058 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1059 _se_translator_function previous
= data
->se_translator
;
1060 TRACE("(%p) returning %p\n",func
,previous
);
1061 data
->se_translator
= func
;
1065 /******************************************************************
1066 * ?terminate@@YAXXZ (MSVCRT.@)
1068 * Default handler for an unhandled exception.
1074 * This function does not return. Either control resumes from any
1075 * handler installed by calling set_terminate(), or (by default) abort()
1078 void CDECL
MSVCRT_terminate(void)
1080 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1081 if (data
->terminate_handler
) data
->terminate_handler();
1085 /******************************************************************
1086 * ?unexpected@@YAXXZ (MSVCRT.@)
1088 void CDECL
MSVCRT_unexpected(void)
1090 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1091 if (data
->unexpected_handler
) data
->unexpected_handler();
1096 /******************************************************************
1097 * __RTtypeid (MSVCRT.@)
1099 * Retrieve the Run Time Type Information (RTTI) for a C++ object.
1102 * cppobj [I] C++ object to get type information for.
1105 * Success: A type_info object describing cppobj.
1106 * Failure: If the object to be cast has no RTTI, a __non_rtti_object
1107 * exception is thrown. If cppobj is NULL, a bad_typeid exception
1108 * is thrown. In either case, this function does not return.
1111 * This function is usually called by compiler generated code as a result
1112 * of using one of the C++ dynamic cast statements.
1114 const type_info
* CDECL
MSVCRT___RTtypeid(void *cppobj
)
1116 const type_info
*ret
;
1121 MSVCRT_bad_typeid_ctor( &e
, "Attempted a typeid of NULL pointer!" );
1122 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1128 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1129 ret
= obj_locator
->type_descriptor
;
1133 __non_rtti_object e
;
1134 MSVCRT___non_rtti_object_ctor( &e
, "Bad read pointer - no RTTI data!" );
1135 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1142 /******************************************************************
1143 * __RTDynamicCast (MSVCRT.@)
1145 * Dynamically cast a C++ object to one of its base classes.
1148 * cppobj [I] Any C++ object to cast
1149 * unknown [I] Reserved, set to 0
1150 * src [I] type_info object describing cppobj
1151 * dst [I] type_info object describing the base class to cast to
1152 * do_throw [I] TRUE = throw an exception if the cast fails, FALSE = don't
1155 * Success: The address of cppobj, cast to the object described by dst.
1156 * Failure: NULL, If the object to be cast has no RTTI, or dst is not a
1157 * valid cast for cppobj. If do_throw is TRUE, a bad_cast exception
1158 * is thrown and this function does not return.
1161 * This function is usually called by compiler generated code as a result
1162 * of using one of the C++ dynamic cast statements.
1164 void* CDECL
MSVCRT___RTDynamicCast(void *cppobj
, int unknown
,
1165 type_info
*src
, type_info
*dst
,
1170 if (!cppobj
) return NULL
;
1172 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1173 cppobj
, unknown
, src
, dbgstr_type_info(src
), dst
, dbgstr_type_info(dst
), do_throw
);
1175 /* To cast an object at runtime:
1176 * 1.Find out the true type of the object from the typeinfo at vtable[-1]
1177 * 2.Search for the destination type in the class hierarchy
1178 * 3.If destination type is found, return base object address + dest offset
1179 * Otherwise, fail the cast
1181 * FIXME: the unknown parameter doesn't seem to be used for anything
1186 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1187 const rtti_object_hierarchy
*obj_bases
= obj_locator
->type_hierarchy
;
1188 const rtti_base_descriptor
* const* base_desc
= obj_bases
->base_classes
->bases
;
1190 if (TRACE_ON(msvcrt
)) dump_obj_locator(obj_locator
);
1193 for (i
= 0; i
< obj_bases
->array_len
; i
++)
1195 const type_info
*typ
= base_desc
[i
]->type_descriptor
;
1197 if (!strcmp(typ
->mangled
, dst
->mangled
))
1199 /* compute the correct this pointer for that base class */
1200 void *this_ptr
= (char *)cppobj
- obj_locator
->base_class_offset
;
1201 ret
= get_this_pointer( &base_desc
[i
]->offsets
, this_ptr
);
1205 /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned
1206 * to a reference, since references cannot be NULL.
1208 if (!ret
&& do_throw
)
1210 const char *msg
= "Bad dynamic_cast!";
1212 MSVCRT_bad_cast_ctor( &e
, &msg
);
1213 _CxxThrowException( &e
, &bad_cast_exception_type
);
1218 __non_rtti_object e
;
1219 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1220 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1228 /******************************************************************
1229 * __RTCastToVoid (MSVCRT.@)
1231 * Dynamically cast a C++ object to a void*.
1234 * cppobj [I] The C++ object to cast
1237 * Success: The base address of the object as a void*.
1238 * Failure: NULL, if cppobj is NULL or has no RTTI.
1241 * This function is usually called by compiler generated code as a result
1242 * of using one of the C++ dynamic cast statements.
1244 void* CDECL
MSVCRT___RTCastToVoid(void *cppobj
)
1248 if (!cppobj
) return NULL
;
1252 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1253 ret
= (char *)cppobj
- obj_locator
->base_class_offset
;
1257 __non_rtti_object e
;
1258 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1259 _CxxThrowException( &e
, &bad_typeid_exception_type
);