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 <internal/wine/msvcrt.h>
25 #include <internal/wine/cppexcept.h>
27 typedef exception bad_cast
;
28 typedef exception bad_typeid
;
29 typedef exception __non_rtti_object
;
31 typedef struct _rtti_base_descriptor
33 const type_info
*type_descriptor
;
35 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
36 unsigned int attributes
;
37 } rtti_base_descriptor
;
39 typedef struct _rtti_base_array
41 const rtti_base_descriptor
*bases
[3]; /* First element is the class itself */
44 typedef struct _rtti_object_hierarchy
46 unsigned int signature
;
47 unsigned int attributes
;
48 int array_len
; /* Size of the array pointed to by 'base_classes' */
49 const rtti_base_array
*base_classes
;
50 } rtti_object_hierarchy
;
52 typedef struct _rtti_object_locator
54 unsigned int signature
;
55 int base_class_offset
;
57 const type_info
*type_descriptor
;
58 const rtti_object_hierarchy
*type_hierarchy
;
59 } rtti_object_locator
;
61 #ifdef __i386__ /* thiscall functions are i386-specific */
63 #define THISCALL(func) __thiscall_ ## func
64 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
65 #define DEFINE_THISCALL_WRAPPER(func) \
66 extern void THISCALL(func)(); \
67 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
71 "jmp " __ASM_NAME(#func) )
74 #define THISCALL(func) func
75 #define THISCALL_NAME(func) __ASM_NAME(#func)
76 #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
80 extern const vtable_ptr MSVCRT_exception_vtable
;
81 extern const vtable_ptr MSVCRT_bad_typeid_vtable
;
82 extern const vtable_ptr MSVCRT_bad_cast_vtable
;
83 extern const vtable_ptr MSVCRT___non_rtti_object_vtable
;
84 extern const vtable_ptr MSVCRT_type_info_vtable
;
86 /* get the vtable pointer for a C++ object */
87 static inline const vtable_ptr
*get_vtable( void *obj
)
89 return *(const vtable_ptr
**)obj
;
92 static inline const rtti_object_locator
*get_obj_locator( void *cppobj
)
94 const vtable_ptr
*vtable
= get_vtable( cppobj
);
95 return (const rtti_object_locator
*)vtable
[-1];
98 static void dump_obj_locator( const rtti_object_locator
*ptr
)
101 const rtti_object_hierarchy
*h
= ptr
->type_hierarchy
;
103 TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n",
104 ptr
, ptr
->signature
, ptr
->base_class_offset
, ptr
->flags
,
105 ptr
->type_descriptor
, dbgstr_type_info(ptr
->type_descriptor
), ptr
->type_hierarchy
);
106 TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n",
107 h
->signature
, h
->attributes
, h
->array_len
, h
->base_classes
);
108 for (i
= 0; i
< h
->array_len
; i
++)
110 TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n",
111 h
->base_classes
->bases
[i
],
112 h
->base_classes
->bases
[i
]->num_base_classes
,
113 h
->base_classes
->bases
[i
]->offsets
.this_offset
,
114 h
->base_classes
->bases
[i
]->offsets
.vbase_descr
,
115 h
->base_classes
->bases
[i
]->offsets
.vbase_offset
,
116 h
->base_classes
->bases
[i
]->attributes
,
117 h
->base_classes
->bases
[i
]->type_descriptor
,
118 dbgstr_type_info(h
->base_classes
->bases
[i
]->type_descriptor
) );
122 /* Internal common ctor for exception */
123 static void WINAPI
EXCEPTION_ctor(exception
*_this
, const char** name
)
125 _this
->vtable
= &MSVCRT_exception_vtable
;
128 size_t name_len
= strlen(*name
) + 1;
129 _this
->name
= MSVCRT_malloc(name_len
);
130 memcpy(_this
->name
, *name
, name_len
);
131 _this
->do_free
= TRUE
;
136 _this
->do_free
= FALSE
;
140 /******************************************************************
141 * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
143 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_ctor
)
144 exception
* __stdcall
MSVCRT_exception_ctor(exception
* _this
, const char ** name
)
146 TRACE("(%p,%s)\n", _this
, *name
);
147 EXCEPTION_ctor(_this
, name
);
151 /******************************************************************
152 * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
154 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_copy_ctor
)
155 exception
* __stdcall
MSVCRT_exception_copy_ctor(exception
* _this
, const exception
* rhs
)
157 TRACE("(%p,%p)\n", _this
, rhs
);
161 _this
->vtable
= &MSVCRT_exception_vtable
;
162 _this
->name
= rhs
->name
;
163 _this
->do_free
= FALSE
;
166 EXCEPTION_ctor(_this
, (const char**)&rhs
->name
);
167 TRACE("name = %s\n", _this
->name
);
171 /******************************************************************
172 * ??0exception@@QAE@XZ (MSVCRT.@)
174 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_default_ctor
)
175 exception
* __stdcall
MSVCRT_exception_default_ctor(exception
* _this
)
177 static const char* empty
= NULL
;
179 TRACE("(%p)\n", _this
);
180 EXCEPTION_ctor(_this
, &empty
);
184 /******************************************************************
185 * ??1exception@@UAE@XZ (MSVCRT.@)
187 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_dtor
)
188 void __stdcall
MSVCRT_exception_dtor(exception
* _this
)
190 TRACE("(%p)\n", _this
);
191 _this
->vtable
= &MSVCRT_exception_vtable
;
192 if (_this
->do_free
) MSVCRT_free(_this
->name
);
195 /******************************************************************
196 * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
198 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_opequals
)
199 exception
* __stdcall
MSVCRT_exception_opequals(exception
* _this
, const exception
* rhs
)
201 TRACE("(%p %p)\n", _this
, rhs
);
204 MSVCRT_exception_dtor(_this
);
205 MSVCRT_exception_copy_ctor(_this
, rhs
);
207 TRACE("name = %s\n", _this
->name
);
211 /******************************************************************
212 * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
214 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_vector_dtor
)
215 void * __stdcall
MSVCRT_exception_vector_dtor(exception
* _this
, unsigned int flags
)
217 TRACE("(%p %x)\n", _this
, flags
);
220 /* we have an array, with the number of elements stored before the first object */
221 int i
, *ptr
= (int *)_this
- 1;
223 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_exception_dtor(_this
+ i
);
224 MSVCRT_operator_delete(ptr
);
228 MSVCRT_exception_dtor(_this
);
229 if (flags
& 1) MSVCRT_operator_delete(_this
);
234 /******************************************************************
235 * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
237 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_scalar_dtor
)
238 void * __stdcall
MSVCRT_exception_scalar_dtor(exception
* _this
, unsigned int flags
)
240 TRACE("(%p %x)\n", _this
, flags
);
241 MSVCRT_exception_dtor(_this
);
242 if (flags
& 1) MSVCRT_operator_delete(_this
);
246 /******************************************************************
247 * ?what@exception@@UBEPBDXZ (MSVCRT.@)
249 DEFINE_THISCALL_WRAPPER(MSVCRT_what_exception
)
250 const char * __stdcall
MSVCRT_what_exception(exception
* _this
)
252 TRACE("(%p) returning %s\n", _this
, _this
->name
);
253 return _this
->name
? _this
->name
: "Unknown exception";
256 /******************************************************************
257 * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
259 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_copy_ctor
)
260 bad_typeid
* __stdcall
MSVCRT_bad_typeid_copy_ctor(bad_typeid
* _this
, const bad_typeid
* rhs
)
262 TRACE("(%p %p)\n", _this
, rhs
);
263 MSVCRT_exception_copy_ctor(_this
, rhs
);
264 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
268 /******************************************************************
269 * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
271 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_ctor
)
272 bad_typeid
* __stdcall
MSVCRT_bad_typeid_ctor(bad_typeid
* _this
, const char * name
)
274 TRACE("(%p %s)\n", _this
, name
);
275 EXCEPTION_ctor(_this
, &name
);
276 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
280 /******************************************************************
281 * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
283 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_dtor
)
284 void __stdcall
MSVCRT_bad_typeid_dtor(bad_typeid
* _this
)
286 TRACE("(%p)\n", _this
);
287 MSVCRT_exception_dtor(_this
);
290 /******************************************************************
291 * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
293 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_opequals
)
294 bad_typeid
* __stdcall
MSVCRT_bad_typeid_opequals(bad_typeid
* _this
, const bad_typeid
* rhs
)
296 TRACE("(%p %p)\n", _this
, rhs
);
297 MSVCRT_exception_opequals(_this
, rhs
);
301 /******************************************************************
302 * ??_Ebad_typeid@@UAEPAXI@Z (MSVCRT.@)
304 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_vector_dtor
)
305 void * __stdcall
MSVCRT_bad_typeid_vector_dtor(bad_typeid
* _this
, unsigned int flags
)
307 TRACE("(%p %x)\n", _this
, flags
);
310 /* we have an array, with the number of elements stored before the first object */
311 int i
, *ptr
= (int *)_this
- 1;
313 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_typeid_dtor(_this
+ i
);
314 MSVCRT_operator_delete(ptr
);
318 MSVCRT_bad_typeid_dtor(_this
);
319 if (flags
& 1) MSVCRT_operator_delete(_this
);
324 /******************************************************************
325 * ??_Gbad_typeid@@UAEPAXI@Z (MSVCRT.@)
327 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_scalar_dtor
)
328 void * __stdcall
MSVCRT_bad_typeid_scalar_dtor(bad_typeid
* _this
, unsigned int flags
)
330 TRACE("(%p %x)\n", _this
, flags
);
331 MSVCRT_bad_typeid_dtor(_this
);
332 if (flags
& 1) MSVCRT_operator_delete(_this
);
336 /******************************************************************
337 * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
339 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_copy_ctor
)
340 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object
* _this
,
341 const __non_rtti_object
* rhs
)
343 TRACE("(%p %p)\n", _this
, rhs
);
344 MSVCRT_bad_typeid_copy_ctor(_this
, rhs
);
345 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
349 /******************************************************************
350 * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
352 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_ctor
)
353 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_ctor(__non_rtti_object
* _this
,
356 TRACE("(%p %s)\n", _this
, name
);
357 EXCEPTION_ctor(_this
, &name
);
358 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
362 /******************************************************************
363 * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
365 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_dtor
)
366 void __stdcall
MSVCRT___non_rtti_object_dtor(__non_rtti_object
* _this
)
368 TRACE("(%p)\n", _this
);
369 MSVCRT_bad_typeid_dtor(_this
);
372 /******************************************************************
373 * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
375 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_opequals
)
376 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_opequals(__non_rtti_object
* _this
,
377 const __non_rtti_object
*rhs
)
379 TRACE("(%p %p)\n", _this
, rhs
);
380 MSVCRT_bad_typeid_opequals(_this
, rhs
);
384 /******************************************************************
385 * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
387 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_vector_dtor
)
388 void * __stdcall
MSVCRT___non_rtti_object_vector_dtor(__non_rtti_object
* _this
, unsigned int flags
)
390 TRACE("(%p %x)\n", _this
, flags
);
393 /* we have an array, with the number of elements stored before the first object */
394 int i
, *ptr
= (int *)_this
- 1;
396 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT___non_rtti_object_dtor(_this
+ i
);
397 MSVCRT_operator_delete(ptr
);
401 MSVCRT___non_rtti_object_dtor(_this
);
402 if (flags
& 1) MSVCRT_operator_delete(_this
);
407 /******************************************************************
408 * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
410 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_scalar_dtor
)
411 void * __stdcall
MSVCRT___non_rtti_object_scalar_dtor(__non_rtti_object
* _this
, unsigned int flags
)
413 TRACE("(%p %x)\n", _this
, flags
);
414 MSVCRT___non_rtti_object_dtor(_this
);
415 if (flags
& 1) MSVCRT_operator_delete(_this
);
419 /******************************************************************
420 * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
422 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_ctor
)
423 bad_cast
* __stdcall
MSVCRT_bad_cast_ctor(bad_cast
* _this
, const char ** name
)
425 TRACE("(%p %s)\n", _this
, *name
);
426 EXCEPTION_ctor(_this
, name
);
427 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
431 /******************************************************************
432 * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
434 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_copy_ctor
)
435 bad_cast
* __stdcall
MSVCRT_bad_cast_copy_ctor(bad_cast
* _this
, const bad_cast
* rhs
)
437 TRACE("(%p %p)\n", _this
, rhs
);
438 MSVCRT_exception_copy_ctor(_this
, rhs
);
439 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
443 /******************************************************************
444 * ??1bad_cast@@UAE@XZ (MSVCRT.@)
446 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_dtor
)
447 void __stdcall
MSVCRT_bad_cast_dtor(bad_cast
* _this
)
449 TRACE("(%p)\n", _this
);
450 MSVCRT_exception_dtor(_this
);
453 /******************************************************************
454 * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
456 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_opequals
)
457 bad_cast
* __stdcall
MSVCRT_bad_cast_opequals(bad_cast
* _this
, const bad_cast
* rhs
)
459 TRACE("(%p %p)\n", _this
, rhs
);
460 MSVCRT_exception_opequals(_this
, rhs
);
464 /******************************************************************
465 * ??_Ebad_cast@@UAEPAXI@Z (MSVCRT.@)
467 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_vector_dtor
)
468 void * __stdcall
MSVCRT_bad_cast_vector_dtor(bad_cast
* _this
, unsigned int flags
)
470 TRACE("(%p %x)\n", _this
, flags
);
473 /* we have an array, with the number of elements stored before the first object */
474 int i
, *ptr
= (int *)_this
- 1;
476 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_cast_dtor(_this
+ i
);
477 MSVCRT_operator_delete(ptr
);
481 MSVCRT_bad_cast_dtor(_this
);
482 if (flags
& 1) MSVCRT_operator_delete(_this
);
487 /******************************************************************
488 * ??_Gbad_cast@@UAEPAXI@Z (MSVCRT.@)
490 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_scalar_dtor
)
491 void * __stdcall
MSVCRT_bad_cast_scalar_dtor(bad_cast
* _this
, unsigned int flags
)
493 TRACE("(%p %x)\n", _this
, flags
);
494 MSVCRT_bad_cast_dtor(_this
);
495 if (flags
& 1) MSVCRT_operator_delete(_this
);
499 /******************************************************************
500 * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
502 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opequals_equals
)
503 int __stdcall
MSVCRT_type_info_opequals_equals(type_info
* _this
, const type_info
* rhs
)
505 int ret
= !strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
506 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
510 /******************************************************************
511 * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
513 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opnot_equals
)
514 int __stdcall
MSVCRT_type_info_opnot_equals(type_info
* _this
, const type_info
* rhs
)
516 int ret
= !!strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
517 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
521 /******************************************************************
522 * ?before@type_info@@QBEHABV1@@Z (MSVCRT.@)
524 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_before
)
525 int __stdcall
MSVCRT_type_info_before(type_info
* _this
, const type_info
* rhs
)
527 int ret
= strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1) < 0;
528 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
532 /******************************************************************
533 * ??1type_info@@UAE@XZ (MSVCRT.@)
535 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_dtor
)
536 void __stdcall
MSVCRT_type_info_dtor(type_info
* _this
)
538 TRACE("(%p)\n", _this
);
539 MSVCRT_free(_this
->name
);
542 /******************************************************************
543 * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
545 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_name
)
546 const char * __stdcall
MSVCRT_type_info_name(type_info
* _this
)
550 /* Create and set the demangled name */
551 /* Nota: mangled name in type_info struct always start with a '.', while
552 * it isn't valid for mangled name.
553 * Is this '.' really part of the mangled name, or has it some other meaning ?
555 char* name
= __unDName(0, _this
->mangled
+ 1, 0,
556 MSVCRT_malloc
, MSVCRT_free
, 0x2800);
560 unsigned int len
= strlen(name
);
562 /* It seems _unDName may leave blanks at the end of the demangled name */
563 while (len
&& name
[--len
] == ' ')
570 /* Another thread set this member since we checked above - use it */
576 _munlock(_EXIT_LOCK2
);
579 TRACE("(%p) returning %s\n", _this
, _this
->name
);
583 /******************************************************************
584 * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
586 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_raw_name
)
587 const char * __stdcall
MSVCRT_type_info_raw_name(type_info
* _this
)
589 TRACE("(%p) returning %s\n", _this
, _this
->mangled
);
590 return _this
->mangled
;
594 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_vector_dtor
)
595 void * __stdcall
MSVCRT_type_info_vector_dtor(type_info
* _this
, unsigned int flags
)
597 TRACE("(%p %x)\n", _this
, flags
);
600 /* we have an array, with the number of elements stored before the first object */
601 int i
, *ptr
= (int *)_this
- 1;
603 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_type_info_dtor(_this
+ i
);
604 MSVCRT_operator_delete(ptr
);
608 MSVCRT_type_info_dtor(_this
);
609 if (flags
& 1) MSVCRT_operator_delete(_this
);
616 #define __ASM_VTABLE(name,funcs) \
619 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
620 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
621 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
622 "\t.long " THISCALL_NAME(MSVCRT_ ## name ## _vector_dtor) "\n" \
625 #define __ASM_EXCEPTION_VTABLE(name) \
626 __ASM_VTABLE(name, "\t.long " THISCALL_NAME(MSVCRT_what_exception) )
629 void __asm_dummy_vtables(void) {
632 __ASM_VTABLE(type_info
,"")
633 __ASM_EXCEPTION_VTABLE(exception
)
634 __ASM_EXCEPTION_VTABLE(bad_typeid
)
635 __ASM_EXCEPTION_VTABLE(bad_cast
)
636 __ASM_EXCEPTION_VTABLE(__non_rtti_object
)
642 /* Static RTTI for exported objects */
644 static const type_info exception_type_info
=
646 &MSVCRT_type_info_vtable
,
651 static const rtti_base_descriptor exception_rtti_base_descriptor
=
653 &exception_type_info
,
659 static const rtti_base_array exception_rtti_base_array
=
662 &exception_rtti_base_descriptor
,
668 static const rtti_object_hierarchy exception_type_hierarchy
=
673 &exception_rtti_base_array
676 const rtti_object_locator exception_rtti
=
681 &exception_type_info
,
682 &exception_type_hierarchy
685 static const cxx_type_info exception_cxx_type_info
=
688 &exception_type_info
,
691 (cxx_copy_ctor
)THISCALL(MSVCRT_exception_copy_ctor
)
694 static const type_info bad_typeid_type_info
=
696 &MSVCRT_type_info_vtable
,
701 static const rtti_base_descriptor bad_typeid_rtti_base_descriptor
=
703 &bad_typeid_type_info
,
709 static const rtti_base_array bad_typeid_rtti_base_array
=
712 &bad_typeid_rtti_base_descriptor
,
713 &exception_rtti_base_descriptor
,
718 static const rtti_object_hierarchy bad_typeid_type_hierarchy
=
723 &bad_typeid_rtti_base_array
726 const rtti_object_locator bad_typeid_rtti
=
731 &bad_typeid_type_info
,
732 &bad_typeid_type_hierarchy
735 static const cxx_type_info bad_typeid_cxx_type_info
=
738 &bad_typeid_type_info
,
741 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_typeid_copy_ctor
)
744 static const type_info bad_cast_type_info
=
746 &MSVCRT_type_info_vtable
,
751 static const rtti_base_descriptor bad_cast_rtti_base_descriptor
=
759 static const rtti_base_array bad_cast_rtti_base_array
=
762 &bad_cast_rtti_base_descriptor
,
763 &exception_rtti_base_descriptor
,
768 static const rtti_object_hierarchy bad_cast_type_hierarchy
=
773 &bad_cast_rtti_base_array
776 const rtti_object_locator bad_cast_rtti
=
782 &bad_cast_type_hierarchy
785 static const cxx_type_info bad_cast_cxx_type_info
=
791 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_cast_copy_ctor
)
794 static const type_info __non_rtti_object_type_info
=
796 &MSVCRT_type_info_vtable
,
798 ".?AV__non_rtti_object@@"
801 static const rtti_base_descriptor __non_rtti_object_rtti_base_descriptor
=
803 &__non_rtti_object_type_info
,
809 static const rtti_base_array __non_rtti_object_rtti_base_array
=
812 &__non_rtti_object_rtti_base_descriptor
,
813 &bad_typeid_rtti_base_descriptor
,
814 &exception_rtti_base_descriptor
818 static const rtti_object_hierarchy __non_rtti_object_type_hierarchy
=
823 &__non_rtti_object_rtti_base_array
826 const rtti_object_locator __non_rtti_object_rtti
=
831 &__non_rtti_object_type_info
,
832 &__non_rtti_object_type_hierarchy
835 static const cxx_type_info __non_rtti_object_cxx_type_info
=
838 &__non_rtti_object_type_info
,
841 (cxx_copy_ctor
)THISCALL(MSVCRT___non_rtti_object_copy_ctor
)
844 static const type_info type_info_type_info
=
846 &MSVCRT_type_info_vtable
,
851 static const rtti_base_descriptor type_info_rtti_base_descriptor
=
853 &type_info_type_info
,
859 static const rtti_base_array type_info_rtti_base_array
=
862 &type_info_rtti_base_descriptor
,
868 static const rtti_object_hierarchy type_info_type_hierarchy
=
873 &type_info_rtti_base_array
876 const rtti_object_locator type_info_rtti
=
881 &type_info_type_info
,
882 &type_info_type_hierarchy
886 * Exception RTTI for cpp objects
888 static const cxx_type_info_table bad_cast_type_info_table
=
892 &__non_rtti_object_cxx_type_info
,
893 &bad_typeid_cxx_type_info
,
894 &exception_cxx_type_info
898 static const cxx_exception_type bad_cast_exception_type
=
901 (void*)THISCALL(MSVCRT_bad_cast_dtor
),
903 &bad_cast_type_info_table
906 static const cxx_type_info_table bad_typeid_type_info_table
=
910 &bad_cast_cxx_type_info
,
911 &exception_cxx_type_info
,
916 static const cxx_exception_type bad_typeid_exception_type
=
919 (void*)THISCALL(MSVCRT_bad_typeid_dtor
),
921 &bad_cast_type_info_table
924 static const cxx_exception_type __non_rtti_object_exception_type
=
927 (void*)THISCALL(MSVCRT___non_rtti_object_dtor
),
929 &bad_typeid_type_info_table
933 /******************************************************************
934 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
936 * Install a handler to be called when terminate() is called.
939 * func [I] Handler function to install
942 * The previously installed handler function, if any.
944 terminate_function CDECL
MSVCRT_set_terminate(terminate_function func
)
946 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
947 terminate_function previous
= data
->terminate_handler
;
948 TRACE("(%p) returning %p\n",func
,previous
);
949 data
->terminate_handler
= func
;
953 /******************************************************************
954 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
956 * Install a handler to be called when unexpected() is called.
959 * func [I] Handler function to install
962 * The previously installed handler function, if any.
964 unexpected_function CDECL
MSVCRT_set_unexpected(unexpected_function func
)
966 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
967 unexpected_function previous
= data
->unexpected_handler
;
968 TRACE("(%p) returning %p\n",func
,previous
);
969 data
->unexpected_handler
= func
;
973 /******************************************************************
974 * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@)
976 _se_translator_function CDECL
MSVCRT__set_se_translator(_se_translator_function func
)
978 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
979 _se_translator_function previous
= data
->se_translator
;
980 TRACE("(%p) returning %p\n",func
,previous
);
981 data
->se_translator
= func
;
985 /******************************************************************
986 * ?terminate@@YAXXZ (MSVCRT.@)
988 * Default handler for an unhandled exception.
994 * This function does not return. Either control resumes from any
995 * handler installed by calling set_terminate(), or (by default) abort()
998 void CDECL
MSVCRT_terminate(void)
1000 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1001 if (data
->terminate_handler
) data
->terminate_handler();
1005 /******************************************************************
1006 * ?unexpected@@YAXXZ (MSVCRT.@)
1008 void CDECL
MSVCRT_unexpected(void)
1010 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
1011 if (data
->unexpected_handler
) data
->unexpected_handler();
1016 /******************************************************************
1017 * __RTtypeid (MSVCRT.@)
1019 * Retrieve the Run Time Type Information (RTTI) for a C++ object.
1022 * cppobj [I] C++ object to get type information for.
1025 * Success: A type_info object describing cppobj.
1026 * Failure: If the object to be cast has no RTTI, a __non_rtti_object
1027 * exception is thrown. If cppobj is NULL, a bad_typeid exception
1028 * is thrown. In either case, this function does not return.
1031 * This function is usually called by compiler generated code as a result
1032 * of using one of the C++ dynamic cast statements.
1034 const type_info
* CDECL
MSVCRT___RTtypeid(void *cppobj
)
1036 const type_info
*ret
;
1041 MSVCRT_bad_typeid_ctor( &e
, "Attempted a typeid of NULL pointer!" );
1042 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1048 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1049 ret
= obj_locator
->type_descriptor
;
1053 __non_rtti_object e
;
1054 MSVCRT___non_rtti_object_ctor( &e
, "Bad read pointer - no RTTI data!" );
1055 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1062 /******************************************************************
1063 * __RTDynamicCast (MSVCRT.@)
1065 * Dynamically cast a C++ object to one of its base classes.
1068 * cppobj [I] Any C++ object to cast
1069 * unknown [I] Reserved, set to 0
1070 * src [I] type_info object describing cppobj
1071 * dst [I] type_info object describing the base class to cast to
1072 * do_throw [I] TRUE = throw an exception if the cast fails, FALSE = don't
1075 * Success: The address of cppobj, cast to the object described by dst.
1076 * Failure: NULL, If the object to be cast has no RTTI, or dst is not a
1077 * valid cast for cppobj. If do_throw is TRUE, a bad_cast exception
1078 * is thrown and this function does not return.
1081 * This function is usually called by compiler generated code as a result
1082 * of using one of the C++ dynamic cast statements.
1084 void* CDECL
MSVCRT___RTDynamicCast(void *cppobj
, int unknown
,
1085 type_info
*src
, type_info
*dst
,
1090 if (!cppobj
) return NULL
;
1092 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1093 cppobj
, unknown
, src
, dbgstr_type_info(src
), dst
, dbgstr_type_info(dst
), do_throw
);
1095 /* To cast an object at runtime:
1096 * 1.Find out the true type of the object from the typeinfo at vtable[-1]
1097 * 2.Search for the destination type in the class hierarchy
1098 * 3.If destination type is found, return base object address + dest offset
1099 * Otherwise, fail the cast
1101 * FIXME: the unknown parameter doesn't seem to be used for anything
1106 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1107 const rtti_object_hierarchy
*obj_bases
= obj_locator
->type_hierarchy
;
1108 const rtti_base_descriptor
* const* base_desc
= obj_bases
->base_classes
->bases
;
1110 if (TRACE_ON(msvcrt
)) dump_obj_locator(obj_locator
);
1113 for (i
= 0; i
< obj_bases
->array_len
; i
++)
1115 const type_info
*typ
= base_desc
[i
]->type_descriptor
;
1117 if (!strcmp(typ
->mangled
, dst
->mangled
))
1119 /* compute the correct this pointer for that base class */
1120 void *this_ptr
= (char *)cppobj
- obj_locator
->base_class_offset
;
1121 ret
= get_this_pointer( &base_desc
[i
]->offsets
, this_ptr
);
1125 /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned
1126 * to a reference, since references cannot be NULL.
1128 if (!ret
&& do_throw
)
1130 const char *msg
= "Bad dynamic_cast!";
1132 MSVCRT_bad_cast_ctor( &e
, &msg
);
1133 _CxxThrowException( &e
, &bad_cast_exception_type
);
1138 __non_rtti_object e
;
1139 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1140 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1148 /******************************************************************
1149 * __RTCastToVoid (MSVCRT.@)
1151 * Dynamically cast a C++ object to a void*.
1154 * cppobj [I] The C++ object to cast
1157 * Success: The base address of the object as a void*.
1158 * Failure: NULL, if cppobj is NULL or has no RTTI.
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___RTCastToVoid(void *cppobj
)
1168 if (!cppobj
) return NULL
;
1172 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1173 ret
= (char *)cppobj
- obj_locator
->base_class_offset
;
1177 __non_rtti_object e
;
1178 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1179 _CxxThrowException( &e
, &bad_typeid_exception_type
);