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) \
634 __asm__(".align 4\n" \
635 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
636 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
637 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
638 "\t.long " THISCALL_NAME(MSVCRT_ ## name ## _vector_dtor) "\n" \
641 #define __ASM_EXCEPTION_VTABLE(name) \
642 __ASM_VTABLE(name, "\t.long " THISCALL_NAME(MSVCRT_what_exception) );
645 void __asm_dummy_vtables(void) {
648 __ASM_VTABLE(type_info
,"");
649 __ASM_EXCEPTION_VTABLE(exception
);
650 __ASM_EXCEPTION_VTABLE(bad_typeid
);
651 __ASM_EXCEPTION_VTABLE(bad_cast
);
652 __ASM_EXCEPTION_VTABLE(__non_rtti_object
);
658 /* Static RTTI for exported objects */
660 static const type_info exception_type_info
=
662 &MSVCRT_type_info_vtable
,
667 static const rtti_base_descriptor exception_rtti_base_descriptor
=
669 &exception_type_info
,
675 static const rtti_base_array exception_rtti_base_array
=
678 &exception_rtti_base_descriptor
,
684 static const rtti_object_hierarchy exception_type_hierarchy
=
689 &exception_rtti_base_array
692 const rtti_object_locator exception_rtti
=
697 &exception_type_info
,
698 &exception_type_hierarchy
701 static const cxx_type_info exception_cxx_type_info
=
704 &exception_type_info
,
707 (cxx_copy_ctor
)THISCALL(MSVCRT_exception_copy_ctor
)
710 static const type_info bad_typeid_type_info
=
712 &MSVCRT_type_info_vtable
,
717 static const rtti_base_descriptor bad_typeid_rtti_base_descriptor
=
719 &bad_typeid_type_info
,
725 static const rtti_base_array bad_typeid_rtti_base_array
=
728 &bad_typeid_rtti_base_descriptor
,
729 &exception_rtti_base_descriptor
,
734 static const rtti_object_hierarchy bad_typeid_type_hierarchy
=
739 &bad_typeid_rtti_base_array
742 const rtti_object_locator bad_typeid_rtti
=
747 &bad_typeid_type_info
,
748 &bad_typeid_type_hierarchy
751 static const cxx_type_info bad_typeid_cxx_type_info
=
754 &bad_typeid_type_info
,
757 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_typeid_copy_ctor
)
760 static const type_info bad_cast_type_info
=
762 &MSVCRT_type_info_vtable
,
767 static const rtti_base_descriptor bad_cast_rtti_base_descriptor
=
775 static const rtti_base_array bad_cast_rtti_base_array
=
778 &bad_cast_rtti_base_descriptor
,
779 &exception_rtti_base_descriptor
,
784 static const rtti_object_hierarchy bad_cast_type_hierarchy
=
789 &bad_cast_rtti_base_array
792 const rtti_object_locator bad_cast_rtti
=
798 &bad_cast_type_hierarchy
801 static const cxx_type_info bad_cast_cxx_type_info
=
807 (cxx_copy_ctor
)THISCALL(MSVCRT_bad_cast_copy_ctor
)
810 static const type_info __non_rtti_object_type_info
=
812 &MSVCRT_type_info_vtable
,
814 ".?AV__non_rtti_object@@"
817 static const rtti_base_descriptor __non_rtti_object_rtti_base_descriptor
=
819 &__non_rtti_object_type_info
,
825 static const rtti_base_array __non_rtti_object_rtti_base_array
=
828 &__non_rtti_object_rtti_base_descriptor
,
829 &bad_typeid_rtti_base_descriptor
,
830 &exception_rtti_base_descriptor
834 static const rtti_object_hierarchy __non_rtti_object_type_hierarchy
=
839 &__non_rtti_object_rtti_base_array
842 const rtti_object_locator __non_rtti_object_rtti
=
847 &__non_rtti_object_type_info
,
848 &__non_rtti_object_type_hierarchy
851 static const cxx_type_info __non_rtti_object_cxx_type_info
=
854 &__non_rtti_object_type_info
,
857 (cxx_copy_ctor
)THISCALL(MSVCRT___non_rtti_object_copy_ctor
)
860 static const type_info type_info_type_info
=
862 &MSVCRT_type_info_vtable
,
867 static const rtti_base_descriptor type_info_rtti_base_descriptor
=
869 &type_info_type_info
,
875 static const rtti_base_array type_info_rtti_base_array
=
878 &type_info_rtti_base_descriptor
,
884 static const rtti_object_hierarchy type_info_type_hierarchy
=
889 &type_info_rtti_base_array
892 const rtti_object_locator type_info_rtti
=
897 &type_info_type_info
,
898 &type_info_type_hierarchy
902 * Exception RTTI for cpp objects
904 static const cxx_type_info_table bad_cast_type_info_table
=
908 &__non_rtti_object_cxx_type_info
,
909 &bad_typeid_cxx_type_info
,
910 &exception_cxx_type_info
914 static const cxx_exception_type bad_cast_exception_type
=
917 (void*)THISCALL(MSVCRT_bad_cast_dtor
),
919 &bad_cast_type_info_table
922 static const cxx_type_info_table bad_typeid_type_info_table
=
926 &bad_cast_cxx_type_info
,
927 &exception_cxx_type_info
,
932 static const cxx_exception_type bad_typeid_exception_type
=
935 (void*)THISCALL(MSVCRT_bad_typeid_dtor
),
937 &bad_cast_type_info_table
940 static const cxx_exception_type __non_rtti_object_exception_type
=
943 (void*)THISCALL(MSVCRT___non_rtti_object_dtor
),
945 &bad_typeid_type_info_table
949 /******************************************************************
950 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
952 * Install a handler to be called when terminate() is called.
955 * func [I] Handler function to install
958 * The previously installed handler function, if any.
960 MSVCRT_terminate_function
MSVCRT_set_terminate(MSVCRT_terminate_function func
)
962 thread_data_t
*data
= msvcrt_get_thread_data();
963 MSVCRT_terminate_function previous
= data
->terminate_handler
;
964 TRACE("(%p) returning %p\n",func
,previous
);
965 data
->terminate_handler
= func
;
969 /******************************************************************
970 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
972 * Install a handler to be called when unexpected() is called.
975 * func [I] Handler function to install
978 * The previously installed handler function, if any.
980 MSVCRT_unexpected_function
MSVCRT_set_unexpected(MSVCRT_unexpected_function func
)
982 thread_data_t
*data
= msvcrt_get_thread_data();
983 MSVCRT_unexpected_function previous
= data
->unexpected_handler
;
984 TRACE("(%p) returning %p\n",func
,previous
);
985 data
->unexpected_handler
= func
;
989 /******************************************************************
990 * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@)
992 MSVCRT__se_translator_function
MSVCRT__set_se_translator(MSVCRT__se_translator_function func
)
994 thread_data_t
*data
= msvcrt_get_thread_data();
995 MSVCRT__se_translator_function previous
= data
->se_translator
;
996 TRACE("(%p) returning %p\n",func
,previous
);
997 data
->se_translator
= func
;
1001 /******************************************************************
1002 * ?terminate@@YAXXZ (MSVCRT.@)
1004 * Default handler for an unhandled exception.
1010 * This function does not return. Either control resumes from any
1011 * handler installed by calling set_terminate(), or (by default) abort()
1014 void MSVCRT_terminate(void)
1016 thread_data_t
*data
= msvcrt_get_thread_data();
1017 if (data
->terminate_handler
) data
->terminate_handler();
1021 /******************************************************************
1022 * ?unexpected@@YAXXZ (MSVCRT.@)
1024 void MSVCRT_unexpected(void)
1026 thread_data_t
*data
= msvcrt_get_thread_data();
1027 if (data
->unexpected_handler
) data
->unexpected_handler();
1032 /******************************************************************
1033 * __RTtypeid (MSVCRT.@)
1035 * Retrieve the Run Time Type Information (RTTI) for a C++ object.
1038 * cppobj [I] C++ object to get type information for.
1041 * Success: A type_info object describing cppobj.
1042 * Failure: If the object to be cast has no RTTI, a __non_rtti_object
1043 * exception is thrown. If cppobj is NULL, a bad_typeid exception
1044 * is thrown. In either case, this function does not return.
1047 * This function is usually called by compiler generated code as a result
1048 * of using one of the C++ dynamic cast statements.
1050 const type_info
* MSVCRT___RTtypeid(void *cppobj
)
1052 const type_info
*ret
;
1057 MSVCRT_bad_typeid_ctor( &e
, "Attempted a typeid of NULL pointer!" );
1058 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1064 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1065 ret
= obj_locator
->type_descriptor
;
1067 __EXCEPT(page_fault
)
1069 __non_rtti_object e
;
1070 MSVCRT___non_rtti_object_ctor( &e
, "Bad read pointer - no RTTI data!" );
1071 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1078 /******************************************************************
1079 * __RTDynamicCast (MSVCRT.@)
1081 * Dynamically cast a C++ object to one of its base classes.
1084 * cppobj [I] Any C++ object to cast
1085 * unknown [I] Reserved, set to 0
1086 * src [I] type_info object describing cppobj
1087 * dst [I] type_info object describing the base class to cast to
1088 * do_throw [I] TRUE = throw an exception if the cast fails, FALSE = don't
1091 * Success: The address of cppobj, cast to the object described by dst.
1092 * Failure: NULL, If the object to be cast has no RTTI, or dst is not a
1093 * valid cast for cppobj. If do_throw is TRUE, a bad_cast exception
1094 * is thrown and this function does not return.
1097 * This function is usually called by compiler generated code as a result
1098 * of using one of the C++ dynamic cast statements.
1100 void* MSVCRT___RTDynamicCast(void *cppobj
, int unknown
,
1101 type_info
*src
, type_info
*dst
,
1106 if (!cppobj
) return NULL
;
1108 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1109 cppobj
, unknown
, src
, dbgstr_type_info(src
), dst
, dbgstr_type_info(dst
), do_throw
);
1111 if (unknown
) FIXME("Unknown parameter is non-zero: please report\n");
1113 /* To cast an object at runtime:
1114 * 1.Find out the true type of the object from the typeinfo at vtable[-1]
1115 * 2.Search for the destination type in the class hierarchy
1116 * 3.If destination type is found, return base object address + dest offset
1117 * Otherwise, fail the cast
1122 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1123 const rtti_object_hierarchy
*obj_bases
= obj_locator
->type_hierarchy
;
1124 const rtti_base_descriptor
* const* base_desc
= obj_bases
->base_classes
->bases
;
1126 if (TRACE_ON(msvcrt
)) dump_obj_locator(obj_locator
);
1129 for (i
= 0; i
< obj_bases
->array_len
; i
++)
1131 const type_info
*typ
= base_desc
[i
]->type_descriptor
;
1133 if (!strcmp(typ
->mangled
, dst
->mangled
))
1135 /* compute the correct this pointer for that base class */
1136 void *this_ptr
= (char *)cppobj
- obj_locator
->base_class_offset
;
1137 ret
= get_this_pointer( &base_desc
[i
]->offsets
, this_ptr
);
1141 /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned
1142 * to a reference, since references cannot be NULL.
1144 if (!ret
&& do_throw
)
1146 const char *msg
= "Bad dynamic_cast!";
1148 MSVCRT_bad_cast_ctor( &e
, &msg
);
1149 _CxxThrowException( &e
, &bad_cast_exception_type
);
1152 __EXCEPT(page_fault
)
1154 __non_rtti_object e
;
1155 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1156 _CxxThrowException( &e
, &bad_typeid_exception_type
);
1164 /******************************************************************
1165 * __RTCastToVoid (MSVCRT.@)
1167 * Dynamically cast a C++ object to a void*.
1170 * cppobj [I] The C++ object to cast
1173 * Success: The base address of the object as a void*.
1174 * Failure: NULL, if cppobj is NULL or has no RTTI.
1177 * This function is usually called by compiler generated code as a result
1178 * of using one of the C++ dynamic cast statements.
1180 void* MSVCRT___RTCastToVoid(void *cppobj
)
1184 if (!cppobj
) return NULL
;
1188 const rtti_object_locator
*obj_locator
= get_obj_locator( cppobj
);
1189 ret
= (char *)cppobj
- obj_locator
->base_class_offset
;
1191 __EXCEPT(page_fault
)
1193 __non_rtti_object e
;
1194 MSVCRT___non_rtti_object_ctor( &e
, "Access violation - no RTTI data!" );
1195 _CxxThrowException( &e
, &bad_typeid_exception_type
);