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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
31 #include "wine/exception.h"
33 #include "wine/debug.h"
35 #include "cppexcept.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
40 typedef exception bad_cast
;
41 typedef exception bad_typeid
;
42 typedef exception __non_rtti_object
;
44 typedef struct _rtti_base_descriptor
46 const type_info
*type_descriptor
;
48 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
49 unsigned int attributes
;
50 } rtti_base_descriptor
;
52 typedef struct _rtti_base_array
54 const rtti_base_descriptor
*bases
[3]; /* First element is the class itself */
57 typedef struct _rtti_object_hierarchy
59 unsigned int signature
;
60 unsigned int attributes
;
61 int array_len
; /* Size of the array pointed to by 'base_classes' */
62 const rtti_base_array
*base_classes
;
63 } rtti_object_hierarchy
;
65 typedef struct _rtti_object_locator
67 unsigned int signature
;
68 int base_class_offset
;
70 const type_info
*type_descriptor
;
71 const rtti_object_hierarchy
*type_hierarchy
;
72 } rtti_object_locator
;
75 #ifdef __i386__ /* thiscall functions are i386-specific */
77 #define THISCALL(func) __thiscall_ ## func
78 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
79 #define DEFINE_THISCALL_WRAPPER(func) \
80 extern void THISCALL(func)(); \
81 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
85 "jmp " __ASM_NAME(#func) )
88 #define THISCALL(func) func
89 #define THISCALL_NAME(func) __ASM_NAME(#func)
90 #define DEFINE_THISCALL_WRAPPER(func) /* nothing */
94 extern const vtable_ptr MSVCRT_exception_vtable
;
95 extern const vtable_ptr MSVCRT_bad_typeid_vtable
;
96 extern const vtable_ptr MSVCRT_bad_cast_vtable
;
97 extern const vtable_ptr MSVCRT___non_rtti_object_vtable
;
98 extern const vtable_ptr MSVCRT_type_info_vtable
;
100 static inline const rtti_object_locator
*get_obj_locator( void *cppobj
)
102 const vtable_ptr
*vtable
= get_vtable( cppobj
);
103 return (const rtti_object_locator
*)vtable
[-1];
106 static void dump_obj_locator( const rtti_object_locator
*ptr
)
109 const rtti_object_hierarchy
*h
= ptr
->type_hierarchy
;
111 TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n",
112 ptr
, ptr
->signature
, ptr
->base_class_offset
, ptr
->flags
,
113 ptr
->type_descriptor
, dbgstr_type_info(ptr
->type_descriptor
), ptr
->type_hierarchy
);
114 TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n",
115 h
->signature
, h
->attributes
, h
->array_len
, h
->base_classes
);
116 for (i
= 0; i
< h
->array_len
; i
++)
118 TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n",
119 h
->base_classes
->bases
[i
],
120 h
->base_classes
->bases
[i
]->num_base_classes
,
121 h
->base_classes
->bases
[i
]->offsets
.this_offset
,
122 h
->base_classes
->bases
[i
]->offsets
.vbase_descr
,
123 h
->base_classes
->bases
[i
]->offsets
.vbase_offset
,
124 h
->base_classes
->bases
[i
]->attributes
,
125 h
->base_classes
->bases
[i
]->type_descriptor
,
126 dbgstr_type_info(h
->base_classes
->bases
[i
]->type_descriptor
) );
130 /* filter for page-fault exceptions */
131 static WINE_EXCEPTION_FILTER(page_fault
)
133 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
)
134 return EXCEPTION_EXECUTE_HANDLER
;
135 return EXCEPTION_CONTINUE_SEARCH
;
138 /* Internal common ctor for exception */
139 static void WINAPI
EXCEPTION_ctor(exception
*_this
, const char** name
)
141 _this
->vtable
= &MSVCRT_exception_vtable
;
144 size_t name_len
= strlen(*name
) + 1;
145 _this
->name
= MSVCRT_malloc(name_len
);
146 memcpy(_this
->name
, *name
, name_len
);
147 _this
->do_free
= TRUE
;
152 _this
->do_free
= FALSE
;
156 /******************************************************************
157 * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
159 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_ctor
);
160 exception
* __stdcall
MSVCRT_exception_ctor(exception
* _this
, const char ** name
)
162 TRACE("(%p,%s)\n", _this
, *name
);
163 EXCEPTION_ctor(_this
, name
);
167 /******************************************************************
168 * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
170 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_copy_ctor
);
171 exception
* __stdcall
MSVCRT_exception_copy_ctor(exception
* _this
, const exception
* rhs
)
173 TRACE("(%p,%p)\n", _this
, rhs
);
177 _this
->vtable
= &MSVCRT_exception_vtable
;
178 _this
->name
= rhs
->name
;
179 _this
->do_free
= FALSE
;
182 EXCEPTION_ctor(_this
, (const char**)&rhs
->name
);
183 TRACE("name = %s\n", _this
->name
);
187 /******************************************************************
188 * ??0exception@@QAE@XZ (MSVCRT.@)
190 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_default_ctor
);
191 exception
* __stdcall
MSVCRT_exception_default_ctor(exception
* _this
)
193 static const char* empty
= NULL
;
195 TRACE("(%p)\n", _this
);
196 EXCEPTION_ctor(_this
, &empty
);
200 /******************************************************************
201 * ??1exception@@UAE@XZ (MSVCRT.@)
203 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_dtor
);
204 void __stdcall
MSVCRT_exception_dtor(exception
* _this
)
206 TRACE("(%p)\n", _this
);
207 _this
->vtable
= &MSVCRT_exception_vtable
;
208 if (_this
->do_free
) MSVCRT_free(_this
->name
);
211 /******************************************************************
212 * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
214 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_opequals
);
215 exception
* __stdcall
MSVCRT_exception_opequals(exception
* _this
, const exception
* rhs
)
217 TRACE("(%p %p)\n", _this
, rhs
);
220 MSVCRT_exception_dtor(_this
);
221 MSVCRT_exception_copy_ctor(_this
, rhs
);
223 TRACE("name = %s\n", _this
->name
);
227 /******************************************************************
228 * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
230 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_vector_dtor
);
231 void * __stdcall
MSVCRT_exception_vector_dtor(exception
* _this
, unsigned int flags
)
233 TRACE("(%p %x)\n", _this
, flags
);
236 /* we have an array, with the number of elements stored before the first object */
237 int i
, *ptr
= (int *)_this
- 1;
239 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_exception_dtor(_this
+ i
);
240 MSVCRT_operator_delete(ptr
);
244 MSVCRT_exception_dtor(_this
);
245 if (flags
& 1) MSVCRT_operator_delete(_this
);
250 /******************************************************************
251 * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
253 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_scalar_dtor
);
254 void * __stdcall
MSVCRT_exception_scalar_dtor(exception
* _this
, unsigned int flags
)
256 TRACE("(%p %x)\n", _this
, flags
);
257 MSVCRT_exception_dtor(_this
);
258 if (flags
& 1) MSVCRT_operator_delete(_this
);
262 /******************************************************************
263 * ?what@exception@@UBEPBDXZ (MSVCRT.@)
265 DEFINE_THISCALL_WRAPPER(MSVCRT_what_exception
);
266 const char * __stdcall
MSVCRT_what_exception(exception
* _this
)
268 TRACE("(%p) returning %s\n", _this
, _this
->name
);
269 return _this
->name
? _this
->name
: "Unknown exception";
272 /******************************************************************
273 * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
275 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_copy_ctor
);
276 bad_typeid
* __stdcall
MSVCRT_bad_typeid_copy_ctor(bad_typeid
* _this
, const bad_typeid
* rhs
)
278 TRACE("(%p %p)\n", _this
, rhs
);
279 MSVCRT_exception_copy_ctor(_this
, rhs
);
280 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
284 /******************************************************************
285 * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
287 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_ctor
);
288 bad_typeid
* __stdcall
MSVCRT_bad_typeid_ctor(bad_typeid
* _this
, const char * name
)
290 TRACE("(%p %s)\n", _this
, name
);
291 EXCEPTION_ctor(_this
, &name
);
292 _this
->vtable
= &MSVCRT_bad_typeid_vtable
;
296 /******************************************************************
297 * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
299 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_dtor
);
300 void __stdcall
MSVCRT_bad_typeid_dtor(bad_typeid
* _this
)
302 TRACE("(%p)\n", _this
);
303 MSVCRT_exception_dtor(_this
);
306 /******************************************************************
307 * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
309 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_opequals
);
310 bad_typeid
* __stdcall
MSVCRT_bad_typeid_opequals(bad_typeid
* _this
, const bad_typeid
* rhs
)
312 TRACE("(%p %p)\n", _this
, rhs
);
313 MSVCRT_exception_opequals(_this
, rhs
);
317 /******************************************************************
318 * ??_Ebad_typeid@@UAEPAXI@Z (MSVCRT.@)
320 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_vector_dtor
);
321 void * __stdcall
MSVCRT_bad_typeid_vector_dtor(bad_typeid
* _this
, unsigned int flags
)
323 TRACE("(%p %x)\n", _this
, flags
);
326 /* we have an array, with the number of elements stored before the first object */
327 int i
, *ptr
= (int *)_this
- 1;
329 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_typeid_dtor(_this
+ i
);
330 MSVCRT_operator_delete(ptr
);
334 MSVCRT_bad_typeid_dtor(_this
);
335 if (flags
& 1) MSVCRT_operator_delete(_this
);
340 /******************************************************************
341 * ??_Gbad_typeid@@UAEPAXI@Z (MSVCRT.@)
343 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_scalar_dtor
);
344 void * __stdcall
MSVCRT_bad_typeid_scalar_dtor(bad_typeid
* _this
, unsigned int flags
)
346 TRACE("(%p %x)\n", _this
, flags
);
347 MSVCRT_bad_typeid_dtor(_this
);
348 if (flags
& 1) MSVCRT_operator_delete(_this
);
352 /******************************************************************
353 * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
355 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_copy_ctor
);
356 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object
* _this
,
357 const __non_rtti_object
* rhs
)
359 TRACE("(%p %p)\n", _this
, rhs
);
360 MSVCRT_bad_typeid_copy_ctor(_this
, rhs
);
361 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
365 /******************************************************************
366 * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
368 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_ctor
);
369 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_ctor(__non_rtti_object
* _this
,
372 TRACE("(%p %s)\n", _this
, name
);
373 EXCEPTION_ctor(_this
, &name
);
374 _this
->vtable
= &MSVCRT___non_rtti_object_vtable
;
378 /******************************************************************
379 * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
381 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_dtor
);
382 void __stdcall
MSVCRT___non_rtti_object_dtor(__non_rtti_object
* _this
)
384 TRACE("(%p)\n", _this
);
385 MSVCRT_bad_typeid_dtor(_this
);
388 /******************************************************************
389 * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
391 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_opequals
);
392 __non_rtti_object
* __stdcall
MSVCRT___non_rtti_object_opequals(__non_rtti_object
* _this
,
393 const __non_rtti_object
*rhs
)
395 TRACE("(%p %p)\n", _this
, rhs
);
396 MSVCRT_bad_typeid_opequals(_this
, rhs
);
400 /******************************************************************
401 * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
403 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_vector_dtor
);
404 void * __stdcall
MSVCRT___non_rtti_object_vector_dtor(__non_rtti_object
* _this
, unsigned int flags
)
406 TRACE("(%p %x)\n", _this
, flags
);
409 /* we have an array, with the number of elements stored before the first object */
410 int i
, *ptr
= (int *)_this
- 1;
412 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT___non_rtti_object_dtor(_this
+ i
);
413 MSVCRT_operator_delete(ptr
);
417 MSVCRT___non_rtti_object_dtor(_this
);
418 if (flags
& 1) MSVCRT_operator_delete(_this
);
423 /******************************************************************
424 * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
426 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_scalar_dtor
);
427 void * __stdcall
MSVCRT___non_rtti_object_scalar_dtor(__non_rtti_object
* _this
, unsigned int flags
)
429 TRACE("(%p %x)\n", _this
, flags
);
430 MSVCRT___non_rtti_object_dtor(_this
);
431 if (flags
& 1) MSVCRT_operator_delete(_this
);
435 /******************************************************************
436 * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
438 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_ctor
);
439 bad_cast
* __stdcall
MSVCRT_bad_cast_ctor(bad_cast
* _this
, const char ** name
)
441 TRACE("(%p %s)\n", _this
, *name
);
442 EXCEPTION_ctor(_this
, name
);
443 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
447 /******************************************************************
448 * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
450 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_copy_ctor
);
451 bad_cast
* __stdcall
MSVCRT_bad_cast_copy_ctor(bad_cast
* _this
, const bad_cast
* rhs
)
453 TRACE("(%p %p)\n", _this
, rhs
);
454 MSVCRT_exception_copy_ctor(_this
, rhs
);
455 _this
->vtable
= &MSVCRT_bad_cast_vtable
;
459 /******************************************************************
460 * ??1bad_cast@@UAE@XZ (MSVCRT.@)
462 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_dtor
);
463 void __stdcall
MSVCRT_bad_cast_dtor(bad_cast
* _this
)
465 TRACE("(%p)\n", _this
);
466 MSVCRT_exception_dtor(_this
);
469 /******************************************************************
470 * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
472 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_opequals
);
473 bad_cast
* __stdcall
MSVCRT_bad_cast_opequals(bad_cast
* _this
, const bad_cast
* rhs
)
475 TRACE("(%p %p)\n", _this
, rhs
);
476 MSVCRT_exception_opequals(_this
, rhs
);
480 /******************************************************************
481 * ??_Ebad_cast@@UAEPAXI@Z (MSVCRT.@)
483 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_vector_dtor
);
484 void * __stdcall
MSVCRT_bad_cast_vector_dtor(bad_cast
* _this
, unsigned int flags
)
486 TRACE("(%p %x)\n", _this
, flags
);
489 /* we have an array, with the number of elements stored before the first object */
490 int i
, *ptr
= (int *)_this
- 1;
492 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_bad_cast_dtor(_this
+ i
);
493 MSVCRT_operator_delete(ptr
);
497 MSVCRT_bad_cast_dtor(_this
);
498 if (flags
& 1) MSVCRT_operator_delete(_this
);
503 /******************************************************************
504 * ??_Gbad_cast@@UAEPAXI@Z (MSVCRT.@)
506 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_scalar_dtor
);
507 void * __stdcall
MSVCRT_bad_cast_scalar_dtor(bad_cast
* _this
, unsigned int flags
)
509 TRACE("(%p %x)\n", _this
, flags
);
510 MSVCRT_bad_cast_dtor(_this
);
511 if (flags
& 1) MSVCRT_operator_delete(_this
);
515 /******************************************************************
516 * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
518 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opequals_equals
);
519 int __stdcall
MSVCRT_type_info_opequals_equals(type_info
* _this
, const type_info
* rhs
)
521 int ret
= !strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
522 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
526 /******************************************************************
527 * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
529 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opnot_equals
);
530 int __stdcall
MSVCRT_type_info_opnot_equals(type_info
* _this
, const type_info
* rhs
)
532 int ret
= !!strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1);
533 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
537 /******************************************************************
538 * ?before@type_info@@QBEHABV1@@Z (MSVCRT.@)
540 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_before
);
541 int __stdcall
MSVCRT_type_info_before(type_info
* _this
, const type_info
* rhs
)
543 int ret
= strcmp(_this
->mangled
+ 1, rhs
->mangled
+ 1) < 0;
544 TRACE("(%p %p) returning %d\n", _this
, rhs
, ret
);
548 /******************************************************************
549 * ??1type_info@@UAE@XZ (MSVCRT.@)
551 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_dtor
);
552 void __stdcall
MSVCRT_type_info_dtor(type_info
* _this
)
554 TRACE("(%p)\n", _this
);
556 MSVCRT_free(_this
->name
);
559 /******************************************************************
560 * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
562 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_name
);
563 const char * __stdcall
MSVCRT_type_info_name(type_info
* _this
)
567 /* Create and set the demangled name */
568 /* Nota: mangled name in type_info struct always start with a '.', while
569 * it isn't valid for mangled name.
570 * Is this '.' really part of the mangled name, or has it some other meaning ?
572 char* name
= __unDName(0, _this
->mangled
+ 1, 0,
573 MSVCRT_malloc
, MSVCRT_free
, 0x2800);
577 unsigned int len
= strlen(name
);
579 /* It seems _unDName may leave blanks at the end of the demangled name */
580 while (len
&& name
[--len
] == ' ')
587 /* Another thread set this member since we checked above - use it */
593 _munlock(_EXIT_LOCK2
);
596 TRACE("(%p) returning %s\n", _this
, _this
->name
);
600 /******************************************************************
601 * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
603 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_raw_name
);
604 const char * __stdcall
MSVCRT_type_info_raw_name(type_info
* _this
)
606 TRACE("(%p) returning %s\n", _this
, _this
->mangled
);
607 return _this
->mangled
;
611 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_vector_dtor
);
612 void * __stdcall
MSVCRT_type_info_vector_dtor(type_info
* _this
, unsigned int flags
)
614 TRACE("(%p %x)\n", _this
, flags
);
617 /* we have an array, with the number of elements stored before the first object */
618 int i
, *ptr
= (int *)_this
- 1;
620 for (i
= *ptr
- 1; i
>= 0; i
--) MSVCRT_type_info_dtor(_this
+ i
);
621 MSVCRT_operator_delete(ptr
);
625 MSVCRT_type_info_dtor(_this
);
626 if (flags
& 1) MSVCRT_operator_delete(_this
);
633 #define __ASM_VTABLE(name,funcs) \
636 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
637 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
638 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
639 "\t.long " THISCALL_NAME(MSVCRT_ ## name ## _vector_dtor) "\n" \
642 #define __ASM_EXCEPTION_VTABLE(name) \
643 __ASM_VTABLE(name, "\t.long " THISCALL_NAME(MSVCRT_what_exception) );
646 void __asm_dummy_vtables(void) {
649 __ASM_VTABLE(type_info
,"");
650 __ASM_EXCEPTION_VTABLE(exception
);
651 __ASM_EXCEPTION_VTABLE(bad_typeid
);
652 __ASM_EXCEPTION_VTABLE(bad_cast
);
653 __ASM_EXCEPTION_VTABLE(__non_rtti_object
);
659 /* Static RTTI for exported objects */
661 static const type_info exception_type_info
=
663 &MSVCRT_type_info_vtable
,
668 static const rtti_base_descriptor exception_rtti_base_descriptor
=
670 &exception_type_info
,
676 static const rtti_base_array exception_rtti_base_array
=
679 &exception_rtti_base_descriptor
,
685 static const rtti_object_hierarchy exception_type_hierarchy
=
690 &exception_rtti_base_array
693 const rtti_object_locator exception_rtti
=
698 &exception_type_info
,
699 &exception_type_hierarchy
702 static const cxx_type_info exception_cxx_type_info
=
705 &exception_type_info
,
708 (cxx_copy_ctor
)THISCALL(MSVCRT_exception_copy_ctor
)
711 static const type_info bad_typeid_type_info
=
713 &MSVCRT_type_info_vtable
,
718 static const rtti_base_descriptor bad_typeid_rtti_base_descriptor
=
720 &bad_typeid_type_info
,
726 static const rtti_base_array bad_typeid_rtti_base_array
=
729 &bad_typeid_rtti_base_descriptor
,
730 &exception_rtti_base_descriptor
,
735 static const rtti_object_hierarchy bad_typeid_type_hierarchy
=
740 &bad_typeid_rtti_base_array
743 const rtti_object_locator bad_typeid_rtti
=
748 &bad_typeid_type_info
,
749 &bad_typeid_type_hierarchy
752 static const cxx_type_info bad_typeid_cxx_type_info
=
755 &bad_typeid_type_info
,
758 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_typeid_copy_ctor
)
761 static const type_info bad_cast_type_info
=
763 &MSVCRT_type_info_vtable
,
768 static const rtti_base_descriptor bad_cast_rtti_base_descriptor
=
776 static const rtti_base_array bad_cast_rtti_base_array
=
779 &bad_cast_rtti_base_descriptor
,
780 &exception_rtti_base_descriptor
,
785 static const rtti_object_hierarchy bad_cast_type_hierarchy
=
790 &bad_cast_rtti_base_array
793 const rtti_object_locator bad_cast_rtti
=
799 &bad_cast_type_hierarchy
802 static const cxx_type_info bad_cast_cxx_type_info
=
808 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_cast_copy_ctor
)
811 static const type_info __non_rtti_object_type_info
=
813 &MSVCRT_type_info_vtable
,
815 ".?AV__non_rtti_object@@"
818 static const rtti_base_descriptor __non_rtti_object_rtti_base_descriptor
=
820 &__non_rtti_object_type_info
,
826 static const rtti_base_array __non_rtti_object_rtti_base_array
=
829 &__non_rtti_object_rtti_base_descriptor
,
830 &bad_typeid_rtti_base_descriptor
,
831 &exception_rtti_base_descriptor
835 static const rtti_object_hierarchy __non_rtti_object_type_hierarchy
=
840 &__non_rtti_object_rtti_base_array
843 const rtti_object_locator __non_rtti_object_rtti
=
848 &__non_rtti_object_type_info
,
849 &__non_rtti_object_type_hierarchy
852 static const cxx_type_info __non_rtti_object_cxx_type_info
=
855 &__non_rtti_object_type_info
,
858 (cxx_copy_ctor
)THISCALL(MSVCRT___non_rtti_object_copy_ctor
)
861 static const type_info type_info_type_info
=
863 &MSVCRT_type_info_vtable
,
868 static const rtti_base_descriptor type_info_rtti_base_descriptor
=
870 &type_info_type_info
,
876 static const rtti_base_array type_info_rtti_base_array
=
879 &type_info_rtti_base_descriptor
,
885 static const rtti_object_hierarchy type_info_type_hierarchy
=
890 &type_info_rtti_base_array
893 const rtti_object_locator type_info_rtti
=
898 &type_info_type_info
,
899 &type_info_type_hierarchy
903 * Exception RTTI for cpp objects
905 static const cxx_type_info_table bad_cast_type_info_table
=
909 &__non_rtti_object_cxx_type_info
,
910 &bad_typeid_cxx_type_info
,
911 &exception_cxx_type_info
915 static const cxx_exception_type bad_cast_exception_type
=
918 (void*)THISCALL(MSVCRT_bad_cast_dtor
),
920 &bad_cast_type_info_table
923 static const cxx_type_info_table bad_typeid_type_info_table
=
927 &bad_cast_cxx_type_info
,
928 &exception_cxx_type_info
,
933 static const cxx_exception_type bad_typeid_exception_type
=
936 (void*)THISCALL(MSVCRT_bad_typeid_dtor
),
938 &bad_cast_type_info_table
941 static const cxx_exception_type __non_rtti_object_exception_type
=
944 (void*)THISCALL(MSVCRT___non_rtti_object_dtor
),
946 &bad_typeid_type_info_table
950 /******************************************************************
951 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
953 * Install a handler to be called when terminate() is called.
956 * func [I] Handler function to install
959 * The previously installed handler function, if any.
961 MSVCRT_terminate_function
MSVCRT_set_terminate(MSVCRT_terminate_function func
)
963 thread_data_t
*data
= msvcrt_get_thread_data();
964 MSVCRT_terminate_function previous
= data
->terminate_handler
;
965 TRACE("(%p) returning %p\n",func
,previous
);
966 data
->terminate_handler
= func
;
970 /******************************************************************
971 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
973 * Install a handler to be called when unexpected() is called.
976 * func [I] Handler function to install
979 * The previously installed handler function, if any.
981 MSVCRT_unexpected_function
MSVCRT_set_unexpected(MSVCRT_unexpected_function func
)
983 thread_data_t
*data
= msvcrt_get_thread_data();
984 MSVCRT_unexpected_function previous
= data
->unexpected_handler
;
985 TRACE("(%p) returning %p\n",func
,previous
);
986 data
->unexpected_handler
= func
;
990 /******************************************************************
991 * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@)
993 MSVCRT__se_translator_function
MSVCRT__set_se_translator(MSVCRT__se_translator_function func
)
995 thread_data_t
*data
= msvcrt_get_thread_data();
996 MSVCRT__se_translator_function previous
= data
->se_translator
;
997 TRACE("(%p) returning %p\n",func
,previous
);
998 data
->se_translator
= func
;
1002 /******************************************************************
1003 * ?terminate@@YAXXZ (MSVCRT.@)
1005 * Default handler for an unhandled exception.
1011 * This function does not return. Either control resumes from any
1012 * handler installed by calling set_terminate(), or (by default) abort()
1015 void MSVCRT_terminate(void)
1017 thread_data_t
*data
= msvcrt_get_thread_data();
1018 if (data
->terminate_handler
) data
->terminate_handler();
1022 /******************************************************************
1023 * ?unexpected@@YAXXZ (MSVCRT.@)
1025 void MSVCRT_unexpected(void)
1027 thread_data_t
*data
= msvcrt_get_thread_data();
1028 if (data
->unexpected_handler
) data
->unexpected_handler();
1033 /******************************************************************
1034 * __RTtypeid (MSVCRT.@)
1036 * Retrieve the Run Time Type Information (RTTI) for a C++ object.
1039 * cppobj [I] C++ object to get type information for.
1042 * Success: A type_info object describing cppobj.
1043 * Failure: If the object to be cast has no RTTI, a __non_rtti_object
1044 * exception is thrown. If cppobj is NULL, a bad_typeid exception
1045 * is thrown. In either case, this function does not return.
1048 * This function is usually called by compiler generated code as a result
1049 * of using one of the C++ dynamic cast statements.
1051 const type_info
* MSVCRT___RTtypeid(void *cppobj
)
1053 const type_info
*ret
;
1058 MSVCRT_bad_typeid_ctor( &e
, "Attempted a typeid of NULL pointer!" );
1059 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1065 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1066 ret
= obj_locator
->type_descriptor
;
1068 __EXCEPT(page_fault
)
1070 __non_rtti_object e
;
1071 MSVCRT___non_rtti_object_ctor( &e
, "Bad read pointer - no RTTI data!" );
1072 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1079 /******************************************************************
1080 * __RTDynamicCast (MSVCRT.@)
1082 * Dynamically cast a C++ object to one of its base classes.
1085 * cppobj [I] Any C++ object to cast
1086 * unknown [I] Reserved, set to 0
1087 * src [I] type_info object describing cppobj
1088 * dst [I] type_info object describing the base class to cast to
1089 * do_throw [I] TRUE = throw an exception if the cast fails, FALSE = don't
1092 * Success: The address of cppobj, cast to the object described by dst.
1093 * Failure: NULL, If the object to be cast has no RTTI, or dst is not a
1094 * valid cast for cppobj. If do_throw is TRUE, a bad_cast exception
1095 * is thrown and this function does not return.
1098 * This function is usually called by compiler generated code as a result
1099 * of using one of the C++ dynamic cast statements.
1101 void* MSVCRT___RTDynamicCast(void *cppobj
, int unknown
,
1102 type_info
*src
, type_info
*dst
,
1107 if (!cppobj
) return NULL
;
1109 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1110 cppobj
, unknown
, src
, dbgstr_type_info(src
), dst
, dbgstr_type_info(dst
), do_throw
);
1112 if (unknown
) FIXME("Unknown parameter is non-zero: please report\n");
1114 /* To cast an object at runtime:
1115 * 1.Find out the true type of the object from the typeinfo at vtable[-1]
1116 * 2.Search for the destination type in the class hierarchy
1117 * 3.If destination type is found, return base object address + dest offset
1118 * Otherwise, fail the cast
1123 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1124 const rtti_object_hierarchy
*obj_bases
= obj_locator
->type_hierarchy
;
1125 const rtti_base_descriptor
* const* base_desc
= obj_bases
->base_classes
->bases
;
1127 if (TRACE_ON(msvcrt
)) dump_obj_locator(obj_locator
);
1130 for (i
= 0; i
< obj_bases
->array_len
; i
++)
1132 const type_info
*typ
= base_desc
[i
]->type_descriptor
;
1134 if (!strcmp(typ
->mangled
, dst
->mangled
))
1136 /* compute the correct this pointer for that base class */
1137 void *this_ptr
= (char *)cppobj
- obj_locator
->base_class_offset
;
1138 ret
= get_this_pointer( &base_desc
[i
]->offsets
, this_ptr
);
1142 /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned
1143 * to a reference, since references cannot be NULL.
1145 if (!ret
&& do_throw
)
1147 const char *msg
= "Bad dynamic_cast!";
1149 MSVCRT_bad_cast_ctor( &e
, &msg
);
1150 _CxxThrowException( &e
, &bad_cast_exception_type
);
1153 __EXCEPT(page_fault
)
1155 __non_rtti_object e
;
1156 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1157 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1165 /******************************************************************
1166 * __RTCastToVoid (MSVCRT.@)
1168 * Dynamically cast a C++ object to a void*.
1171 * cppobj [I] The C++ object to cast
1174 * Success: The base address of the object as a void*.
1175 * Failure: NULL, if cppobj is NULL or has no RTTI.
1178 * This function is usually called by compiler generated code as a result
1179 * of using one of the C++ dynamic cast statements.
1181 void* MSVCRT___RTCastToVoid(void *cppobj
)
1185 if (!cppobj
) return NULL
;
1189 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1190 ret
= (char *)cppobj
- obj_locator
->base_class_offset
;
1192 __EXCEPT(page_fault
)
1194 __non_rtti_object e
;
1195 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1196 _CxxThrowException( &e
, &bad_typeid_exception_type
);