kernel32/tests: Add a test to check some fields in fake dlls.
[wine.git] / dlls / msvcrt / cpp.c
blob4857d295facd9090da81b1b4bbed0a1e98acfd6f
1 /*
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winternl.h"
29 #include "wine/exception.h"
30 #include "wine/debug.h"
31 #include "msvcrt.h"
32 #include "cppexcept.h"
33 #include "mtdll.h"
34 #include "cxx.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
38 struct __type_info_node
40 void *memPtr;
41 struct __type_info_node* next;
44 typedef exception bad_cast;
45 typedef exception bad_typeid;
46 typedef exception __non_rtti_object;
48 extern const vtable_ptr MSVCRT_exception_vtable;
49 extern const vtable_ptr MSVCRT_bad_typeid_vtable;
50 extern const vtable_ptr MSVCRT_bad_cast_vtable;
51 extern const vtable_ptr MSVCRT___non_rtti_object_vtable;
52 extern const vtable_ptr MSVCRT_type_info_vtable;
54 /* get the vtable pointer for a C++ object */
55 static inline const vtable_ptr *get_vtable( void *obj )
57 return *(const vtable_ptr **)obj;
60 static inline const rtti_object_locator *get_obj_locator( void *cppobj )
62 const vtable_ptr *vtable = get_vtable( cppobj );
63 return (const rtti_object_locator *)vtable[-1];
66 #ifndef __x86_64__
67 static void dump_obj_locator( const rtti_object_locator *ptr )
69 int i;
70 const rtti_object_hierarchy *h = ptr->type_hierarchy;
72 TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n",
73 ptr, ptr->signature, ptr->base_class_offset, ptr->flags,
74 ptr->type_descriptor, dbgstr_type_info(ptr->type_descriptor), ptr->type_hierarchy );
75 TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n",
76 h->signature, h->attributes, h->array_len, h->base_classes );
77 for (i = 0; i < h->array_len; i++)
79 TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n",
80 h->base_classes->bases[i],
81 h->base_classes->bases[i]->num_base_classes,
82 h->base_classes->bases[i]->offsets.this_offset,
83 h->base_classes->bases[i]->offsets.vbase_descr,
84 h->base_classes->bases[i]->offsets.vbase_offset,
85 h->base_classes->bases[i]->attributes,
86 h->base_classes->bases[i]->type_descriptor,
87 dbgstr_type_info(h->base_classes->bases[i]->type_descriptor) );
91 #else
93 static void dump_obj_locator( const rtti_object_locator *ptr )
95 int i;
96 char *base = ptr->signature == 0 ? RtlPcToFileHeader((void*)ptr, (void**)&base) : (char*)ptr - ptr->object_locator;
97 const rtti_object_hierarchy *h = (const rtti_object_hierarchy*)(base + ptr->type_hierarchy);
98 const type_info *type_descriptor = (const type_info*)(base + ptr->type_descriptor);
100 TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n",
101 ptr, ptr->signature, ptr->base_class_offset, ptr->flags,
102 type_descriptor, dbgstr_type_info(type_descriptor), h );
103 TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n",
104 h->signature, h->attributes, h->array_len, base + h->base_classes );
105 for (i = 0; i < h->array_len; i++)
107 const rtti_base_descriptor *bases = (rtti_base_descriptor*)(base +
108 ((const rtti_base_array*)(base + h->base_classes))->bases[i]);
110 TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n",
111 bases,
112 bases->num_base_classes,
113 bases->offsets.this_offset,
114 bases->offsets.vbase_descr,
115 bases->offsets.vbase_offset,
116 bases->attributes,
117 base + bases->type_descriptor,
118 dbgstr_type_info((const type_info*)(base + bases->type_descriptor)) );
121 #endif
123 /* Internal common ctor for exception */
124 static void EXCEPTION_ctor(exception *_this, const char** name)
126 _this->vtable = &MSVCRT_exception_vtable;
127 if (*name)
129 unsigned int name_len = strlen(*name) + 1;
130 _this->name = MSVCRT_malloc(name_len);
131 memcpy(_this->name, *name, name_len);
132 _this->do_free = TRUE;
134 else
136 _this->name = NULL;
137 _this->do_free = FALSE;
141 /******************************************************************
142 * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
144 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_ctor,8)
145 exception * __thiscall MSVCRT_exception_ctor(exception * _this, const char ** name)
147 TRACE("(%p,%s)\n", _this, *name);
148 EXCEPTION_ctor(_this, name);
149 return _this;
152 /******************************************************************
153 * ??0exception@@QAE@ABQBDH@Z (MSVCRT.@)
155 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_ctor_noalloc,12)
156 exception * __thiscall MSVCRT_exception_ctor_noalloc(exception * _this, char ** name, int noalloc)
158 TRACE("(%p,%s)\n", _this, *name);
159 _this->vtable = &MSVCRT_exception_vtable;
160 _this->name = *name;
161 _this->do_free = FALSE;
162 return _this;
165 /******************************************************************
166 * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
168 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_copy_ctor,8)
169 exception * __thiscall MSVCRT_exception_copy_ctor(exception * _this, const exception * rhs)
171 TRACE("(%p,%p)\n", _this, rhs);
173 if (!rhs->do_free)
175 _this->vtable = &MSVCRT_exception_vtable;
176 _this->name = rhs->name;
177 _this->do_free = FALSE;
179 else
180 EXCEPTION_ctor(_this, (const char**)&rhs->name);
181 TRACE("name = %s\n", _this->name);
182 return _this;
185 /******************************************************************
186 * ??0exception@@QAE@XZ (MSVCRT.@)
188 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_default_ctor,4)
189 exception * __thiscall MSVCRT_exception_default_ctor(exception * _this)
191 static const char* empty = NULL;
193 TRACE("(%p)\n", _this);
194 EXCEPTION_ctor(_this, &empty);
195 return _this;
198 /******************************************************************
199 * ??1exception@@UAE@XZ (MSVCRT.@)
201 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_dtor,4)
202 void __thiscall MSVCRT_exception_dtor(exception * _this)
204 TRACE("(%p)\n", _this);
205 _this->vtable = &MSVCRT_exception_vtable;
206 if (_this->do_free) MSVCRT_free(_this->name);
209 /******************************************************************
210 * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
212 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_opequals,8)
213 exception * __thiscall MSVCRT_exception_opequals(exception * _this, const exception * rhs)
215 TRACE("(%p %p)\n", _this, rhs);
216 if (_this != rhs)
218 MSVCRT_exception_dtor(_this);
219 MSVCRT_exception_copy_ctor(_this, rhs);
221 TRACE("name = %s\n", _this->name);
222 return _this;
225 /******************************************************************
226 * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
228 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_vector_dtor,8)
229 void * __thiscall MSVCRT_exception_vector_dtor(exception * _this, unsigned int flags)
231 TRACE("(%p %x)\n", _this, flags);
232 if (flags & 2)
234 /* we have an array, with the number of elements stored before the first object */
235 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
237 for (i = *ptr - 1; i >= 0; i--) MSVCRT_exception_dtor(_this + i);
238 MSVCRT_operator_delete(ptr);
240 else
242 MSVCRT_exception_dtor(_this);
243 if (flags & 1) MSVCRT_operator_delete(_this);
245 return _this;
248 /******************************************************************
249 * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
251 DEFINE_THISCALL_WRAPPER(MSVCRT_exception_scalar_dtor,8)
252 void * __thiscall MSVCRT_exception_scalar_dtor(exception * _this, unsigned int flags)
254 TRACE("(%p %x)\n", _this, flags);
255 MSVCRT_exception_dtor(_this);
256 if (flags & 1) MSVCRT_operator_delete(_this);
257 return _this;
260 /******************************************************************
261 * ?what@exception@@UBEPBDXZ (MSVCRT.@)
263 DEFINE_THISCALL_WRAPPER(MSVCRT_what_exception,4)
264 const char * __thiscall MSVCRT_what_exception(exception * _this)
266 TRACE("(%p) returning %s\n", _this, _this->name);
267 return _this->name ? _this->name : "Unknown exception";
270 /******************************************************************
271 * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
273 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_copy_ctor,8)
274 bad_typeid * __thiscall MSVCRT_bad_typeid_copy_ctor(bad_typeid * _this, const bad_typeid * rhs)
276 TRACE("(%p %p)\n", _this, rhs);
277 MSVCRT_exception_copy_ctor(_this, rhs);
278 _this->vtable = &MSVCRT_bad_typeid_vtable;
279 return _this;
282 /******************************************************************
283 * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
285 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_ctor,8)
286 bad_typeid * __thiscall MSVCRT_bad_typeid_ctor(bad_typeid * _this, const char * name)
288 TRACE("(%p %s)\n", _this, name);
289 EXCEPTION_ctor(_this, &name);
290 _this->vtable = &MSVCRT_bad_typeid_vtable;
291 return _this;
294 /******************************************************************
295 * ??_Fbad_typeid@@QAEXXZ (MSVCRT.@)
297 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_default_ctor,4)
298 bad_typeid * __thiscall MSVCRT_bad_typeid_default_ctor(bad_typeid * _this)
300 return MSVCRT_bad_typeid_ctor( _this, "bad typeid" );
303 /******************************************************************
304 * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
306 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_dtor,4)
307 void __thiscall MSVCRT_bad_typeid_dtor(bad_typeid * _this)
309 TRACE("(%p)\n", _this);
310 MSVCRT_exception_dtor(_this);
313 /******************************************************************
314 * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
316 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_opequals,8)
317 bad_typeid * __thiscall MSVCRT_bad_typeid_opequals(bad_typeid * _this, const bad_typeid * rhs)
319 TRACE("(%p %p)\n", _this, rhs);
320 MSVCRT_exception_opequals(_this, rhs);
321 return _this;
324 /******************************************************************
325 * ??_Ebad_typeid@@UAEPAXI@Z (MSVCRT.@)
327 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_vector_dtor,8)
328 void * __thiscall MSVCRT_bad_typeid_vector_dtor(bad_typeid * _this, unsigned int flags)
330 TRACE("(%p %x)\n", _this, flags);
331 if (flags & 2)
333 /* we have an array, with the number of elements stored before the first object */
334 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
336 for (i = *ptr - 1; i >= 0; i--) MSVCRT_bad_typeid_dtor(_this + i);
337 MSVCRT_operator_delete(ptr);
339 else
341 MSVCRT_bad_typeid_dtor(_this);
342 if (flags & 1) MSVCRT_operator_delete(_this);
344 return _this;
347 /******************************************************************
348 * ??_Gbad_typeid@@UAEPAXI@Z (MSVCRT.@)
350 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_typeid_scalar_dtor,8)
351 void * __thiscall MSVCRT_bad_typeid_scalar_dtor(bad_typeid * _this, unsigned int flags)
353 TRACE("(%p %x)\n", _this, flags);
354 MSVCRT_bad_typeid_dtor(_this);
355 if (flags & 1) MSVCRT_operator_delete(_this);
356 return _this;
359 /******************************************************************
360 * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
362 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_copy_ctor,8)
363 __non_rtti_object * __thiscall MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object * _this,
364 const __non_rtti_object * rhs)
366 TRACE("(%p %p)\n", _this, rhs);
367 MSVCRT_bad_typeid_copy_ctor(_this, rhs);
368 _this->vtable = &MSVCRT___non_rtti_object_vtable;
369 return _this;
372 /******************************************************************
373 * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
375 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_ctor,8)
376 __non_rtti_object * __thiscall MSVCRT___non_rtti_object_ctor(__non_rtti_object * _this,
377 const char * name)
379 TRACE("(%p %s)\n", _this, name);
380 EXCEPTION_ctor(_this, &name);
381 _this->vtable = &MSVCRT___non_rtti_object_vtable;
382 return _this;
385 /******************************************************************
386 * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
388 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_dtor,4)
389 void __thiscall MSVCRT___non_rtti_object_dtor(__non_rtti_object * _this)
391 TRACE("(%p)\n", _this);
392 MSVCRT_bad_typeid_dtor(_this);
395 /******************************************************************
396 * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
398 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_opequals,8)
399 __non_rtti_object * __thiscall MSVCRT___non_rtti_object_opequals(__non_rtti_object * _this,
400 const __non_rtti_object *rhs)
402 TRACE("(%p %p)\n", _this, rhs);
403 MSVCRT_bad_typeid_opequals(_this, rhs);
404 return _this;
407 /******************************************************************
408 * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
410 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_vector_dtor,8)
411 void * __thiscall MSVCRT___non_rtti_object_vector_dtor(__non_rtti_object * _this, unsigned int flags)
413 TRACE("(%p %x)\n", _this, flags);
414 if (flags & 2)
416 /* we have an array, with the number of elements stored before the first object */
417 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
419 for (i = *ptr - 1; i >= 0; i--) MSVCRT___non_rtti_object_dtor(_this + i);
420 MSVCRT_operator_delete(ptr);
422 else
424 MSVCRT___non_rtti_object_dtor(_this);
425 if (flags & 1) MSVCRT_operator_delete(_this);
427 return _this;
430 /******************************************************************
431 * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
433 DEFINE_THISCALL_WRAPPER(MSVCRT___non_rtti_object_scalar_dtor,8)
434 void * __thiscall MSVCRT___non_rtti_object_scalar_dtor(__non_rtti_object * _this, unsigned int flags)
436 TRACE("(%p %x)\n", _this, flags);
437 MSVCRT___non_rtti_object_dtor(_this);
438 if (flags & 1) MSVCRT_operator_delete(_this);
439 return _this;
442 /******************************************************************
443 * ??0bad_cast@@AAE@PBQBD@Z (MSVCRT.@)
444 * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
446 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_ctor,8)
447 bad_cast * __thiscall MSVCRT_bad_cast_ctor(bad_cast * _this, const char ** name)
449 TRACE("(%p %s)\n", _this, *name);
450 EXCEPTION_ctor(_this, name);
451 _this->vtable = &MSVCRT_bad_cast_vtable;
452 return _this;
455 /******************************************************************
456 * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
458 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_copy_ctor,8)
459 bad_cast * __thiscall MSVCRT_bad_cast_copy_ctor(bad_cast * _this, const bad_cast * rhs)
461 TRACE("(%p %p)\n", _this, rhs);
462 MSVCRT_exception_copy_ctor(_this, rhs);
463 _this->vtable = &MSVCRT_bad_cast_vtable;
464 return _this;
467 /******************************************************************
468 * ??0bad_cast@@QAE@PBD@Z (MSVCRT.@)
470 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_ctor_charptr,8)
471 bad_cast * __thiscall MSVCRT_bad_cast_ctor_charptr(bad_cast * _this, const char * name)
473 TRACE("(%p %s)\n", _this, name);
474 EXCEPTION_ctor(_this, &name);
475 _this->vtable = &MSVCRT_bad_cast_vtable;
476 return _this;
479 /******************************************************************
480 * ??_Fbad_cast@@QAEXXZ (MSVCRT.@)
482 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_default_ctor,4)
483 bad_cast * __thiscall MSVCRT_bad_cast_default_ctor(bad_cast * _this)
485 return MSVCRT_bad_cast_ctor_charptr( _this, "bad cast" );
488 /******************************************************************
489 * ??1bad_cast@@UAE@XZ (MSVCRT.@)
491 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_dtor,4)
492 void __thiscall MSVCRT_bad_cast_dtor(bad_cast * _this)
494 TRACE("(%p)\n", _this);
495 MSVCRT_exception_dtor(_this);
498 /******************************************************************
499 * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
501 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_opequals,8)
502 bad_cast * __thiscall MSVCRT_bad_cast_opequals(bad_cast * _this, const bad_cast * rhs)
504 TRACE("(%p %p)\n", _this, rhs);
505 MSVCRT_exception_opequals(_this, rhs);
506 return _this;
509 /******************************************************************
510 * ??_Ebad_cast@@UAEPAXI@Z (MSVCRT.@)
512 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_vector_dtor,8)
513 void * __thiscall MSVCRT_bad_cast_vector_dtor(bad_cast * _this, unsigned int flags)
515 TRACE("(%p %x)\n", _this, flags);
516 if (flags & 2)
518 /* we have an array, with the number of elements stored before the first object */
519 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
521 for (i = *ptr - 1; i >= 0; i--) MSVCRT_bad_cast_dtor(_this + i);
522 MSVCRT_operator_delete(ptr);
524 else
526 MSVCRT_bad_cast_dtor(_this);
527 if (flags & 1) MSVCRT_operator_delete(_this);
529 return _this;
532 /******************************************************************
533 * ??_Gbad_cast@@UAEPAXI@Z (MSVCRT.@)
535 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_cast_scalar_dtor,8)
536 void * __thiscall MSVCRT_bad_cast_scalar_dtor(bad_cast * _this, unsigned int flags)
538 TRACE("(%p %x)\n", _this, flags);
539 MSVCRT_bad_cast_dtor(_this);
540 if (flags & 1) MSVCRT_operator_delete(_this);
541 return _this;
544 /******************************************************************
545 * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
547 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opequals_equals,8)
548 int __thiscall MSVCRT_type_info_opequals_equals(type_info * _this, const type_info * rhs)
550 int ret = !strcmp(_this->mangled + 1, rhs->mangled + 1);
551 TRACE("(%p %p) returning %d\n", _this, rhs, ret);
552 return ret;
555 /******************************************************************
556 * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
558 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_opnot_equals,8)
559 int __thiscall MSVCRT_type_info_opnot_equals(type_info * _this, const type_info * rhs)
561 int ret = !!strcmp(_this->mangled + 1, rhs->mangled + 1);
562 TRACE("(%p %p) returning %d\n", _this, rhs, ret);
563 return ret;
566 /******************************************************************
567 * ?before@type_info@@QBEHABV1@@Z (MSVCRT.@)
569 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_before,8)
570 int __thiscall MSVCRT_type_info_before(type_info * _this, const type_info * rhs)
572 int ret = strcmp(_this->mangled + 1, rhs->mangled + 1) < 0;
573 TRACE("(%p %p) returning %d\n", _this, rhs, ret);
574 return ret;
577 /******************************************************************
578 * ??1type_info@@UAE@XZ (MSVCRT.@)
580 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_dtor,4)
581 void __thiscall MSVCRT_type_info_dtor(type_info * _this)
583 TRACE("(%p)\n", _this);
584 MSVCRT_free(_this->name);
587 /******************************************************************
588 * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
590 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_name,4)
591 const char * __thiscall MSVCRT_type_info_name(type_info * _this)
593 if (!_this->name)
595 /* Create and set the demangled name */
596 /* Note: mangled name in type_info struct always starts with a '.', while
597 * it isn't valid for mangled name.
598 * Is this '.' really part of the mangled name, or has it some other meaning ?
600 char* name = __unDName(0, _this->mangled + 1, 0,
601 MSVCRT_malloc, MSVCRT_free, UNDNAME_NO_ARGUMENTS | UNDNAME_32_BIT_DECODE);
602 if (name)
604 unsigned int len = strlen(name);
606 /* It seems _unDName may leave blanks at the end of the demangled name */
607 while (len && name[--len] == ' ')
608 name[len] = '\0';
610 if (InterlockedCompareExchangePointer((void**)&_this->name, name, NULL))
612 /* Another thread set this member since we checked above - use it */
613 MSVCRT_free(name);
617 TRACE("(%p) returning %s\n", _this, _this->name);
618 return _this->name;
621 /******************************************************************
622 * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
624 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_raw_name,4)
625 const char * __thiscall MSVCRT_type_info_raw_name(type_info * _this)
627 TRACE("(%p) returning %s\n", _this, _this->mangled);
628 return _this->mangled;
631 /* Unexported */
632 DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_vector_dtor,8)
633 void * __thiscall MSVCRT_type_info_vector_dtor(type_info * _this, unsigned int flags)
635 TRACE("(%p %x)\n", _this, flags);
636 if (flags & 2)
638 /* we have an array, with the number of elements stored before the first object */
639 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
641 for (i = *ptr - 1; i >= 0; i--) MSVCRT_type_info_dtor(_this + i);
642 MSVCRT_operator_delete(ptr);
644 else
646 MSVCRT_type_info_dtor(_this);
647 if (flags & 1) MSVCRT_operator_delete(_this);
649 return _this;
652 #if _MSVCR_VER >= 80
654 typedef exception bad_alloc;
655 extern const vtable_ptr MSVCRT_bad_alloc_vtable;
657 static void bad_alloc_ctor(bad_alloc *this, const char **name)
659 MSVCRT_exception_ctor(this, name);
660 this->vtable = &MSVCRT_bad_alloc_vtable;
663 /* bad_alloc class implementation */
664 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_alloc_copy_ctor,8)
665 bad_alloc * __thiscall MSVCRT_bad_alloc_copy_ctor(bad_alloc * _this, const bad_alloc * rhs)
667 TRACE("(%p %p)\n", _this, rhs);
668 MSVCRT_exception_copy_ctor(_this, rhs);
669 _this->vtable = &MSVCRT_bad_alloc_vtable;
670 return _this;
673 DEFINE_THISCALL_WRAPPER(MSVCRT_bad_alloc_dtor,4)
674 void __thiscall MSVCRT_bad_alloc_dtor(bad_alloc * _this)
676 TRACE("(%p)\n", _this);
677 MSVCRT_exception_dtor(_this);
680 #endif /* _MSVCR_VER >= 80 */
682 #if _MSVCR_VER >= 100
684 typedef struct {
685 exception e;
686 HRESULT hr;
687 } scheduler_resource_allocation_error;
688 extern const vtable_ptr MSVCRT_scheduler_resource_allocation_error_vtable;
690 /* ??0scheduler_resource_allocation_error@Concurrency@@QAE@PBDJ@Z */
691 /* ??0scheduler_resource_allocation_error@Concurrency@@QEAA@PEBDJ@Z */
692 DEFINE_THISCALL_WRAPPER(scheduler_resource_allocation_error_ctor_name, 12)
693 scheduler_resource_allocation_error* __thiscall scheduler_resource_allocation_error_ctor_name(
694 scheduler_resource_allocation_error *this, const char *name, HRESULT hr)
696 TRACE("(%p %s %x)\n", this, wine_dbgstr_a(name), hr);
697 MSVCRT_exception_ctor(&this->e, &name);
698 this->e.vtable = &MSVCRT_scheduler_resource_allocation_error_vtable;
699 this->hr = hr;
700 return this;
703 /* ??0scheduler_resource_allocation_error@Concurrency@@QAE@J@Z */
704 /* ??0scheduler_resource_allocation_error@Concurrency@@QEAA@J@Z */
705 DEFINE_THISCALL_WRAPPER(scheduler_resource_allocation_error_ctor, 8)
706 scheduler_resource_allocation_error* __thiscall scheduler_resource_allocation_error_ctor(
707 scheduler_resource_allocation_error *this, HRESULT hr)
709 return scheduler_resource_allocation_error_ctor_name(this, NULL, hr);
712 DEFINE_THISCALL_WRAPPER(MSVCRT_scheduler_resource_allocation_error_copy_ctor,8)
713 scheduler_resource_allocation_error* __thiscall MSVCRT_scheduler_resource_allocation_error_copy_ctor(
714 scheduler_resource_allocation_error *this,
715 const scheduler_resource_allocation_error *rhs)
717 TRACE("(%p,%p)\n", this, rhs);
719 if (!rhs->e.do_free)
720 memcpy(this, rhs, sizeof(*this));
721 else
722 scheduler_resource_allocation_error_ctor_name(this, rhs->e.name, rhs->hr);
723 return this;
726 /* ?get_error_code@scheduler_resource_allocation_error@Concurrency@@QBEJXZ */
727 /* ?get_error_code@scheduler_resource_allocation_error@Concurrency@@QEBAJXZ */
728 DEFINE_THISCALL_WRAPPER(scheduler_resource_allocation_error_get_error_code, 4)
729 HRESULT __thiscall scheduler_resource_allocation_error_get_error_code(
730 const scheduler_resource_allocation_error *this)
732 TRACE("(%p)\n", this);
733 return this->hr;
736 DEFINE_THISCALL_WRAPPER(MSVCRT_scheduler_resource_allocation_error_dtor,4)
737 void __thiscall MSVCRT_scheduler_resource_allocation_error_dtor(
738 scheduler_resource_allocation_error * this)
740 TRACE("(%p)\n", this);
741 MSVCRT_exception_dtor(&this->e);
744 typedef exception improper_lock;
745 extern const vtable_ptr MSVCRT_improper_lock_vtable;
747 /* ??0improper_lock@Concurrency@@QAE@PBD@Z */
748 /* ??0improper_lock@Concurrency@@QEAA@PEBD@Z */
749 DEFINE_THISCALL_WRAPPER(improper_lock_ctor_str, 8)
750 improper_lock* __thiscall improper_lock_ctor_str(improper_lock *this, const char *str)
752 TRACE("(%p %p)\n", this, str);
753 MSVCRT_exception_ctor(this, &str);
754 this->vtable = &MSVCRT_improper_lock_vtable;
755 return this;
758 /* ??0improper_lock@Concurrency@@QAE@XZ */
759 /* ??0improper_lock@Concurrency@@QEAA@XZ */
760 DEFINE_THISCALL_WRAPPER(improper_lock_ctor, 4)
761 improper_lock* __thiscall improper_lock_ctor(improper_lock *this)
763 return improper_lock_ctor_str(this, NULL);
766 DEFINE_THISCALL_WRAPPER(MSVCRT_improper_lock_copy_ctor,8)
767 improper_lock * __thiscall MSVCRT_improper_lock_copy_ctor(improper_lock * _this, const improper_lock * rhs)
769 TRACE("(%p %p)\n", _this, rhs);
770 MSVCRT_exception_copy_ctor(_this, rhs);
771 _this->vtable = &MSVCRT_improper_lock_vtable;
772 return _this;
775 DEFINE_THISCALL_WRAPPER(MSVCRT_improper_lock_dtor,4)
776 void __thiscall MSVCRT_improper_lock_dtor(improper_lock * _this)
778 TRACE("(%p)\n", _this);
779 MSVCRT_exception_dtor(_this);
782 typedef exception invalid_scheduler_policy_key;
783 extern const vtable_ptr MSVCRT_invalid_scheduler_policy_key_vtable;
785 /* ??0invalid_scheduler_policy_key@Concurrency@@QAE@PBD@Z */
786 /* ??0invalid_scheduler_policy_key@Concurrency@@QEAA@PEBD@Z */
787 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_key_ctor_str, 8)
788 invalid_scheduler_policy_key* __thiscall invalid_scheduler_policy_key_ctor_str(
789 invalid_scheduler_policy_key *this, const char *str)
791 TRACE("(%p %p)\n", this, str);
792 MSVCRT_exception_ctor(this, &str);
793 this->vtable = &MSVCRT_invalid_scheduler_policy_key_vtable;
794 return this;
797 /* ??0invalid_scheduler_policy_key@Concurrency@@QAE@XZ */
798 /* ??0invalid_scheduler_policy_key@Concurrency@@QEAA@XZ */
799 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_key_ctor, 4)
800 invalid_scheduler_policy_key* __thiscall invalid_scheduler_policy_key_ctor(
801 invalid_scheduler_policy_key *this)
803 return invalid_scheduler_policy_key_ctor_str(this, NULL);
806 DEFINE_THISCALL_WRAPPER(MSVCRT_invalid_scheduler_policy_key_copy_ctor,8)
807 invalid_scheduler_policy_key * __thiscall MSVCRT_invalid_scheduler_policy_key_copy_ctor(
808 invalid_scheduler_policy_key * _this, const invalid_scheduler_policy_key * rhs)
810 TRACE("(%p %p)\n", _this, rhs);
811 MSVCRT_exception_copy_ctor(_this, rhs);
812 _this->vtable = &MSVCRT_invalid_scheduler_policy_key_vtable;
813 return _this;
816 DEFINE_THISCALL_WRAPPER(MSVCRT_invalid_scheduler_policy_key_dtor,4)
817 void __thiscall MSVCRT_invalid_scheduler_policy_key_dtor(
818 invalid_scheduler_policy_key * _this)
820 TRACE("(%p)\n", _this);
821 MSVCRT_exception_dtor(_this);
824 typedef exception invalid_scheduler_policy_value;
825 extern const vtable_ptr MSVCRT_invalid_scheduler_policy_value_vtable;
827 /* ??0invalid_scheduler_policy_value@Concurrency@@QAE@PBD@Z */
828 /* ??0invalid_scheduler_policy_value@Concurrency@@QEAA@PEBD@Z */
829 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_value_ctor_str, 8)
830 invalid_scheduler_policy_value* __thiscall invalid_scheduler_policy_value_ctor_str(
831 invalid_scheduler_policy_value *this, const char *str)
833 TRACE("(%p %p)\n", this, str);
834 MSVCRT_exception_ctor(this, &str);
835 this->vtable = &MSVCRT_invalid_scheduler_policy_value_vtable;
836 return this;
839 /* ??0invalid_scheduler_policy_value@Concurrency@@QAE@XZ */
840 /* ??0invalid_scheduler_policy_value@Concurrency@@QEAA@XZ */
841 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_value_ctor, 4)
842 invalid_scheduler_policy_value* __thiscall invalid_scheduler_policy_value_ctor(
843 invalid_scheduler_policy_value *this)
845 return invalid_scheduler_policy_value_ctor_str(this, NULL);
848 DEFINE_THISCALL_WRAPPER(MSVCRT_invalid_scheduler_policy_value_copy_ctor,8)
849 invalid_scheduler_policy_value * __thiscall MSVCRT_invalid_scheduler_policy_value_copy_ctor(
850 invalid_scheduler_policy_value * _this, const invalid_scheduler_policy_value * rhs)
852 TRACE("(%p %p)\n", _this, rhs);
853 MSVCRT_exception_copy_ctor(_this, rhs);
854 _this->vtable = &MSVCRT_invalid_scheduler_policy_value_vtable;
855 return _this;
858 DEFINE_THISCALL_WRAPPER(MSVCRT_invalid_scheduler_policy_value_dtor,4)
859 void __thiscall MSVCRT_invalid_scheduler_policy_value_dtor(
860 invalid_scheduler_policy_value * _this)
862 TRACE("(%p)\n", _this);
863 MSVCRT_exception_dtor(_this);
866 typedef exception invalid_scheduler_policy_thread_specification;
867 extern const vtable_ptr MSVCRT_invalid_scheduler_policy_thread_specification_vtable;
869 /* ??0invalid_scheduler_policy_thread_specification@Concurrency@@QAE@PBD@Z */
870 /* ??0invalid_scheduler_policy_thread_specification@Concurrency@@QEAA@PEBD@Z */
871 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_thread_specification_ctor_str, 8)
872 invalid_scheduler_policy_thread_specification* __thiscall invalid_scheduler_policy_thread_specification_ctor_str(
873 invalid_scheduler_policy_thread_specification *this, const char *str)
875 TRACE("(%p %p)\n", this, str);
876 MSVCRT_exception_ctor(this, &str);
877 this->vtable = &MSVCRT_invalid_scheduler_policy_thread_specification_vtable;
878 return this;
881 /* ??0invalid_scheduler_policy_thread_specification@Concurrency@@QAE@XZ */
882 /* ??0invalid_scheduler_policy_thread_specification@Concurrency@@QEAA@XZ */
883 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_thread_specification_ctor, 4)
884 invalid_scheduler_policy_thread_specification* __thiscall invalid_scheduler_policy_thread_specification_ctor(
885 invalid_scheduler_policy_thread_specification *this)
887 return invalid_scheduler_policy_thread_specification_ctor_str(this, NULL);
890 DEFINE_THISCALL_WRAPPER(MSVCRT_invalid_scheduler_policy_thread_specification_copy_ctor,8)
891 invalid_scheduler_policy_thread_specification * __thiscall MSVCRT_invalid_scheduler_policy_thread_specification_copy_ctor(
892 invalid_scheduler_policy_thread_specification * _this, const invalid_scheduler_policy_thread_specification * rhs)
894 TRACE("(%p %p)\n", _this, rhs);
895 MSVCRT_exception_copy_ctor(_this, rhs);
896 _this->vtable = &MSVCRT_invalid_scheduler_policy_thread_specification_vtable;
897 return _this;
900 DEFINE_THISCALL_WRAPPER(MSVCRT_invalid_scheduler_policy_thread_specification_dtor,4)
901 void __thiscall MSVCRT_invalid_scheduler_policy_thread_specification_dtor(
902 invalid_scheduler_policy_thread_specification * _this)
904 TRACE("(%p)\n", _this);
905 MSVCRT_exception_dtor(_this);
908 typedef exception improper_scheduler_attach;
909 extern const vtable_ptr MSVCRT_improper_scheduler_attach_vtable;
911 /* ??0improper_scheduler_attach@Concurrency@@QAE@PBD@Z */
912 /* ??0improper_scheduler_attach@Concurrency@@QEAA@PEBD@Z */
913 DEFINE_THISCALL_WRAPPER(improper_scheduler_attach_ctor_str, 8)
914 improper_scheduler_attach* __thiscall improper_scheduler_attach_ctor_str(
915 improper_scheduler_attach *this, const char *str)
917 TRACE("(%p %p)\n", this, str);
918 MSVCRT_exception_ctor(this, &str);
919 this->vtable = &MSVCRT_improper_scheduler_attach_vtable;
920 return this;
923 /* ??0improper_scheduler_attach@Concurrency@@QAE@XZ */
924 /* ??0improper_scheduler_attach@Concurrency@@QEAA@XZ */
925 DEFINE_THISCALL_WRAPPER(improper_scheduler_attach_ctor, 4)
926 improper_scheduler_attach* __thiscall improper_scheduler_attach_ctor(
927 improper_scheduler_attach *this)
929 return improper_scheduler_attach_ctor_str(this, NULL);
932 DEFINE_THISCALL_WRAPPER(MSVCRT_improper_scheduler_attach_copy_ctor,8)
933 improper_scheduler_attach * __thiscall MSVCRT_improper_scheduler_attach_copy_ctor(
934 improper_scheduler_attach * _this, const improper_scheduler_attach * rhs)
936 TRACE("(%p %p)\n", _this, rhs);
937 MSVCRT_exception_copy_ctor(_this, rhs);
938 _this->vtable = &MSVCRT_improper_scheduler_attach_vtable;
939 return _this;
942 DEFINE_THISCALL_WRAPPER(MSVCRT_improper_scheduler_attach_dtor,4)
943 void __thiscall MSVCRT_improper_scheduler_attach_dtor(
944 improper_scheduler_attach * _this)
946 TRACE("(%p)\n", _this);
947 MSVCRT_exception_dtor(_this);
950 typedef exception improper_scheduler_detach;
951 extern const vtable_ptr MSVCRT_improper_scheduler_detach_vtable;
953 /* ??0improper_scheduler_detach@Concurrency@@QAE@PBD@Z */
954 /* ??0improper_scheduler_detach@Concurrency@@QEAA@PEBD@Z */
955 DEFINE_THISCALL_WRAPPER(improper_scheduler_detach_ctor_str, 8)
956 improper_scheduler_detach* __thiscall improper_scheduler_detach_ctor_str(
957 improper_scheduler_detach *this, const char *str)
959 TRACE("(%p %p)\n", this, str);
960 MSVCRT_exception_ctor(this, &str);
961 this->vtable = &MSVCRT_improper_scheduler_detach_vtable;
962 return this;
965 /* ??0improper_scheduler_detach@Concurrency@@QAE@XZ */
966 /* ??0improper_scheduler_detach@Concurrency@@QEAA@XZ */
967 DEFINE_THISCALL_WRAPPER(improper_scheduler_detach_ctor, 4)
968 improper_scheduler_detach* __thiscall improper_scheduler_detach_ctor(
969 improper_scheduler_detach *this)
971 return improper_scheduler_detach_ctor_str(this, NULL);
974 DEFINE_THISCALL_WRAPPER(MSVCRT_improper_scheduler_detach_copy_ctor,8)
975 improper_scheduler_detach * __thiscall MSVCRT_improper_scheduler_detach_copy_ctor(
976 improper_scheduler_detach * _this, const improper_scheduler_detach * rhs)
978 TRACE("(%p %p)\n", _this, rhs);
979 MSVCRT_exception_copy_ctor(_this, rhs);
980 _this->vtable = &MSVCRT_improper_scheduler_detach_vtable;
981 return _this;
984 DEFINE_THISCALL_WRAPPER(MSVCRT_improper_scheduler_detach_dtor,4)
985 void __thiscall MSVCRT_improper_scheduler_detach_dtor(
986 improper_scheduler_detach * _this)
988 TRACE("(%p)\n", _this);
989 MSVCRT_exception_dtor(_this);
992 #endif /* _MSVCR_VER >= 100 */
994 #ifndef __GNUC__
995 void __asm_dummy_vtables(void) {
996 #endif
998 __ASM_VTABLE(type_info,
999 VTABLE_ADD_FUNC(MSVCRT_type_info_vector_dtor));
1000 __ASM_VTABLE(exception,
1001 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1002 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1003 #if _MSVCR_VER >= 80
1004 __ASM_VTABLE(exception_old,
1005 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1006 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1007 __ASM_VTABLE(bad_alloc,
1008 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1009 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1010 #endif
1011 __ASM_VTABLE(bad_typeid,
1012 VTABLE_ADD_FUNC(MSVCRT_bad_typeid_vector_dtor)
1013 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1014 __ASM_VTABLE(bad_cast,
1015 VTABLE_ADD_FUNC(MSVCRT_bad_cast_vector_dtor)
1016 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1017 __ASM_VTABLE(__non_rtti_object,
1018 VTABLE_ADD_FUNC(MSVCRT___non_rtti_object_vector_dtor)
1019 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1020 #if _MSVCR_VER >= 100
1021 __ASM_VTABLE(scheduler_resource_allocation_error,
1022 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1023 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1024 __ASM_VTABLE(improper_lock,
1025 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1026 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1027 __ASM_VTABLE(invalid_scheduler_policy_key,
1028 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1029 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1030 __ASM_VTABLE(invalid_scheduler_policy_value,
1031 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1032 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1033 __ASM_VTABLE(invalid_scheduler_policy_thread_specification,
1034 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1035 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1036 __ASM_VTABLE(improper_scheduler_attach,
1037 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1038 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1039 __ASM_VTABLE(improper_scheduler_detach,
1040 VTABLE_ADD_FUNC(MSVCRT_exception_vector_dtor)
1041 VTABLE_ADD_FUNC(MSVCRT_what_exception));
1042 #endif
1044 #ifndef __GNUC__
1046 #endif
1048 DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" )
1049 #if _MSVCR_VER >= 80
1050 DEFINE_RTTI_DATA0( exception, 0, ".?AVexception@std@@" )
1051 DEFINE_RTTI_DATA0( exception_old, 0, ".?AVexception@@" )
1052 DEFINE_RTTI_DATA1( bad_typeid, 0, &exception_rtti_base_descriptor, ".?AVbad_typeid@std@@" )
1053 DEFINE_RTTI_DATA1( bad_cast, 0, &exception_rtti_base_descriptor, ".?AVbad_cast@std@@" )
1054 DEFINE_RTTI_DATA2( __non_rtti_object, 0, &bad_typeid_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AV__non_rtti_object@std@@" )
1055 DEFINE_RTTI_DATA1( bad_alloc, 0, &exception_rtti_base_descriptor, ".?AVbad_alloc@std@@" )
1056 #else
1057 DEFINE_RTTI_DATA0( exception, 0, ".?AVexception@@" )
1058 DEFINE_RTTI_DATA1( bad_typeid, 0, &exception_rtti_base_descriptor, ".?AVbad_typeid@@" )
1059 DEFINE_RTTI_DATA1( bad_cast, 0, &exception_rtti_base_descriptor, ".?AVbad_cast@@" )
1060 DEFINE_RTTI_DATA2( __non_rtti_object, 0, &bad_typeid_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AV__non_rtti_object@@" )
1061 #endif
1062 #if _MSVCR_VER >= 100
1063 DEFINE_RTTI_DATA1(scheduler_resource_allocation_error, 0, &exception_rtti_base_descriptor,
1064 ".?AVscheduler_resource_allocation_error@Concurrency@@")
1065 DEFINE_RTTI_DATA1(improper_lock, 0, &exception_rtti_base_descriptor, ".?AVimproper_lock@Concurrency@@" )
1066 DEFINE_RTTI_DATA1(invalid_scheduler_policy_key, 0, &exception_rtti_base_descriptor,
1067 ".?AVinvalid_scheduler_policy_key@Concurrency@@" )
1068 DEFINE_RTTI_DATA1(invalid_scheduler_policy_value, 0, &exception_rtti_base_descriptor,
1069 ".?AVinvalid_scheduler_policy_value@Concurrency@@" )
1070 DEFINE_RTTI_DATA1(invalid_scheduler_policy_thread_specification, 0, &exception_rtti_base_descriptor,
1071 ".?AVinvalid_scheduler_policy_thread_specification@Concurrency@@" )
1072 DEFINE_RTTI_DATA1(improper_scheduler_attach, 0, &exception_rtti_base_descriptor,
1073 ".?AVimproper_scheduler_attach@Concurrency@@" )
1074 DEFINE_RTTI_DATA1(improper_scheduler_detach, 0, &exception_rtti_base_descriptor,
1075 ".?AVimproper_scheduler_detach@Concurrency@@" )
1076 #endif
1078 DEFINE_EXCEPTION_TYPE_INFO( exception, 0, NULL, NULL )
1079 DEFINE_EXCEPTION_TYPE_INFO( bad_typeid, 1, &exception_cxx_type_info, NULL )
1080 DEFINE_EXCEPTION_TYPE_INFO( bad_cast, 1, &exception_cxx_type_info, NULL )
1081 DEFINE_EXCEPTION_TYPE_INFO( __non_rtti_object, 2, &bad_typeid_cxx_type_info, &exception_cxx_type_info )
1082 #if _MSVCR_VER >= 80
1083 DEFINE_EXCEPTION_TYPE_INFO( bad_alloc, 1, &exception_cxx_type_info, NULL )
1084 #endif
1085 #if _MSVCR_VER >= 100
1086 DEFINE_EXCEPTION_TYPE_INFO(scheduler_resource_allocation_error, 1, &exception_cxx_type_info, NULL)
1087 DEFINE_EXCEPTION_TYPE_INFO(improper_lock, 1, &exception_cxx_type_info, NULL)
1088 DEFINE_EXCEPTION_TYPE_INFO(invalid_scheduler_policy_key, 1, &exception_cxx_type_info, NULL)
1089 DEFINE_EXCEPTION_TYPE_INFO(invalid_scheduler_policy_value, 1, &exception_cxx_type_info, NULL)
1090 DEFINE_EXCEPTION_TYPE_INFO(invalid_scheduler_policy_thread_specification, 1, &exception_cxx_type_info, NULL)
1091 DEFINE_EXCEPTION_TYPE_INFO(improper_scheduler_attach, 1, &exception_cxx_type_info, NULL)
1092 DEFINE_EXCEPTION_TYPE_INFO(improper_scheduler_detach, 1, &exception_cxx_type_info, NULL)
1093 #endif
1095 void msvcrt_init_exception(void *base)
1097 #ifdef __x86_64__
1098 init_type_info_rtti(base);
1099 init_exception_rtti(base);
1100 #if _MSVCR_VER >= 80
1101 init_exception_old_rtti(base);
1102 init_bad_alloc_rtti(base);
1103 #endif
1104 init_bad_typeid_rtti(base);
1105 init_bad_cast_rtti(base);
1106 init___non_rtti_object_rtti(base);
1107 #if _MSVCR_VER >= 100
1108 init_scheduler_resource_allocation_error_rtti(base);
1109 init_improper_lock_rtti(base);
1110 init_invalid_scheduler_policy_key_rtti(base);
1111 init_invalid_scheduler_policy_value_rtti(base);
1112 init_invalid_scheduler_policy_thread_specification_rtti(base);
1113 init_improper_scheduler_attach_rtti(base);
1114 init_improper_scheduler_detach_rtti(base);
1115 #endif
1117 init_exception_cxx(base);
1118 init_bad_typeid_cxx(base);
1119 init_bad_cast_cxx(base);
1120 init___non_rtti_object_cxx(base);
1121 #if _MSVCR_VER >= 80
1122 init_bad_alloc_cxx(base);
1123 #endif
1124 #if _MSVCR_VER >= 100
1125 init_scheduler_resource_allocation_error_cxx(base);
1126 init_improper_lock_cxx(base);
1127 init_invalid_scheduler_policy_key_cxx(base);
1128 init_invalid_scheduler_policy_value_cxx(base);
1129 init_invalid_scheduler_policy_thread_specification_cxx(base);
1130 init_improper_scheduler_attach_cxx(base);
1131 init_improper_scheduler_detach_cxx(base);
1132 #endif
1133 #endif
1136 #if _MSVCR_VER >= 80
1137 void throw_exception(exception_type et, HRESULT hr, const char *str)
1139 switch(et) {
1140 case EXCEPTION_BAD_ALLOC: {
1141 bad_alloc e;
1142 bad_alloc_ctor(&e, &str);
1143 _CxxThrowException(&e, &bad_alloc_exception_type);
1145 #if _MSVCR_VER >= 100
1146 case EXCEPTION_SCHEDULER_RESOURCE_ALLOCATION_ERROR: {
1147 scheduler_resource_allocation_error e;
1148 scheduler_resource_allocation_error_ctor_name(&e, str, hr);
1149 _CxxThrowException(&e.e, &scheduler_resource_allocation_error_exception_type);
1151 case EXCEPTION_IMPROPER_LOCK: {
1152 improper_lock e;
1153 improper_lock_ctor_str(&e, str);
1154 _CxxThrowException(&e, &improper_lock_exception_type);
1156 case EXCEPTION_INVALID_SCHEDULER_POLICY_KEY: {
1157 invalid_scheduler_policy_key e;
1158 invalid_scheduler_policy_key_ctor_str(&e, str);
1159 _CxxThrowException(&e, &invalid_scheduler_policy_key_exception_type);
1161 case EXCEPTION_INVALID_SCHEDULER_POLICY_VALUE: {
1162 invalid_scheduler_policy_value e;
1163 invalid_scheduler_policy_value_ctor_str(&e, str);
1164 _CxxThrowException(&e, &invalid_scheduler_policy_value_exception_type);
1166 case EXCEPTION_INVALID_SCHEDULER_POLICY_THREAD_SPECIFICATION: {
1167 invalid_scheduler_policy_thread_specification e;
1168 invalid_scheduler_policy_thread_specification_ctor_str(&e, str);
1169 _CxxThrowException(&e, &invalid_scheduler_policy_thread_specification_exception_type);
1171 case EXCEPTION_IMPROPER_SCHEDULER_ATTACH: {
1172 improper_scheduler_attach e;
1173 improper_scheduler_attach_ctor_str(&e, str);
1174 _CxxThrowException(&e, &improper_scheduler_attach_exception_type);
1176 case EXCEPTION_IMPROPER_SCHEDULER_DETACH: {
1177 improper_scheduler_detach e;
1178 improper_scheduler_detach_ctor_str(&e, str);
1179 _CxxThrowException(&e, &improper_scheduler_detach_exception_type);
1181 #endif
1184 #endif
1186 /******************************************************************
1187 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
1189 * Install a handler to be called when terminate() is called.
1191 * PARAMS
1192 * func [I] Handler function to install
1194 * RETURNS
1195 * The previously installed handler function, if any.
1197 MSVCRT_terminate_function CDECL MSVCRT_set_terminate(MSVCRT_terminate_function func)
1199 thread_data_t *data = msvcrt_get_thread_data();
1200 MSVCRT_terminate_function previous = data->terminate_handler;
1201 TRACE("(%p) returning %p\n",func,previous);
1202 data->terminate_handler = func;
1203 return previous;
1206 /******************************************************************
1207 * _get_terminate (MSVCRT.@)
1209 MSVCRT_terminate_function CDECL MSVCRT__get_terminate(void)
1211 thread_data_t *data = msvcrt_get_thread_data();
1212 TRACE("returning %p\n", data->terminate_handler);
1213 return data->terminate_handler;
1216 /******************************************************************
1217 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
1219 * Install a handler to be called when unexpected() is called.
1221 * PARAMS
1222 * func [I] Handler function to install
1224 * RETURNS
1225 * The previously installed handler function, if any.
1227 MSVCRT_unexpected_function CDECL MSVCRT_set_unexpected(MSVCRT_unexpected_function func)
1229 thread_data_t *data = msvcrt_get_thread_data();
1230 MSVCRT_unexpected_function previous = data->unexpected_handler;
1231 TRACE("(%p) returning %p\n",func,previous);
1232 data->unexpected_handler = func;
1233 return previous;
1236 /******************************************************************
1237 * _get_unexpected (MSVCRT.@)
1239 MSVCRT_unexpected_function CDECL MSVCRT__get_unexpected(void)
1241 thread_data_t *data = msvcrt_get_thread_data();
1242 TRACE("returning %p\n", data->unexpected_handler);
1243 return data->unexpected_handler;
1246 /******************************************************************
1247 * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@)
1249 MSVCRT__se_translator_function CDECL MSVCRT__set_se_translator(MSVCRT__se_translator_function func)
1251 thread_data_t *data = msvcrt_get_thread_data();
1252 MSVCRT__se_translator_function previous = data->se_translator;
1253 TRACE("(%p) returning %p\n",func,previous);
1254 data->se_translator = func;
1255 return previous;
1258 /******************************************************************
1259 * ?terminate@@YAXXZ (MSVCRT.@)
1261 * Default handler for an unhandled exception.
1263 * PARAMS
1264 * None.
1266 * RETURNS
1267 * This function does not return. Either control resumes from any
1268 * handler installed by calling set_terminate(), or (by default) abort()
1269 * is called.
1271 void CDECL MSVCRT_terminate(void)
1273 thread_data_t *data = msvcrt_get_thread_data();
1274 if (data->terminate_handler) data->terminate_handler();
1275 MSVCRT_abort();
1278 /******************************************************************
1279 * ?unexpected@@YAXXZ (MSVCRT.@)
1281 void CDECL MSVCRT_unexpected(void)
1283 thread_data_t *data = msvcrt_get_thread_data();
1284 if (data->unexpected_handler) data->unexpected_handler();
1285 MSVCRT_terminate();
1289 /******************************************************************
1290 * __RTtypeid (MSVCRT.@)
1292 * Retrieve the Run Time Type Information (RTTI) for a C++ object.
1294 * PARAMS
1295 * cppobj [I] C++ object to get type information for.
1297 * RETURNS
1298 * Success: A type_info object describing cppobj.
1299 * Failure: If the object to be cast has no RTTI, a __non_rtti_object
1300 * exception is thrown. If cppobj is NULL, a bad_typeid exception
1301 * is thrown. In either case, this function does not return.
1303 * NOTES
1304 * This function is usually called by compiler generated code as a result
1305 * of using one of the C++ dynamic cast statements.
1307 #ifndef __x86_64__
1308 const type_info* CDECL MSVCRT___RTtypeid(void *cppobj)
1310 const type_info *ret;
1312 if (!cppobj)
1314 bad_typeid e;
1315 MSVCRT_bad_typeid_ctor( &e, "Attempted a typeid of NULL pointer!" );
1316 _CxxThrowException( &e, &bad_typeid_exception_type );
1317 return NULL;
1320 __TRY
1322 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1323 ret = obj_locator->type_descriptor;
1325 __EXCEPT_PAGE_FAULT
1327 __non_rtti_object e;
1328 MSVCRT___non_rtti_object_ctor( &e, "Bad read pointer - no RTTI data!" );
1329 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1330 return NULL;
1332 __ENDTRY
1333 return ret;
1336 #else
1338 const type_info* CDECL MSVCRT___RTtypeid(void *cppobj)
1340 const type_info *ret;
1342 if (!cppobj)
1344 bad_typeid e;
1345 MSVCRT_bad_typeid_ctor( &e, "Attempted a typeid of NULL pointer!" );
1346 _CxxThrowException( &e, &bad_typeid_exception_type );
1347 return NULL;
1350 __TRY
1352 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1353 char *base;
1355 if(obj_locator->signature == 0)
1356 base = RtlPcToFileHeader((void*)obj_locator, (void**)&base);
1357 else
1358 base = (char*)obj_locator - obj_locator->object_locator;
1360 ret = (type_info*)(base + obj_locator->type_descriptor);
1362 __EXCEPT_PAGE_FAULT
1364 __non_rtti_object e;
1365 MSVCRT___non_rtti_object_ctor( &e, "Bad read pointer - no RTTI data!" );
1366 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1367 return NULL;
1369 __ENDTRY
1370 return ret;
1372 #endif
1374 /******************************************************************
1375 * __RTDynamicCast (MSVCRT.@)
1377 * Dynamically cast a C++ object to one of its base classes.
1379 * PARAMS
1380 * cppobj [I] Any C++ object to cast
1381 * unknown [I] Reserved, set to 0
1382 * src [I] type_info object describing cppobj
1383 * dst [I] type_info object describing the base class to cast to
1384 * do_throw [I] TRUE = throw an exception if the cast fails, FALSE = don't
1386 * RETURNS
1387 * Success: The address of cppobj, cast to the object described by dst.
1388 * Failure: NULL, If the object to be cast has no RTTI, or dst is not a
1389 * valid cast for cppobj. If do_throw is TRUE, a bad_cast exception
1390 * is thrown and this function does not return.
1392 * NOTES
1393 * This function is usually called by compiler generated code as a result
1394 * of using one of the C++ dynamic cast statements.
1396 #ifndef __x86_64__
1397 void* CDECL MSVCRT___RTDynamicCast(void *cppobj, int unknown,
1398 type_info *src, type_info *dst,
1399 int do_throw)
1401 void *ret;
1403 if (!cppobj) return NULL;
1405 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1406 cppobj, unknown, src, dbgstr_type_info(src), dst, dbgstr_type_info(dst), do_throw);
1408 /* To cast an object at runtime:
1409 * 1.Find out the true type of the object from the typeinfo at vtable[-1]
1410 * 2.Search for the destination type in the class hierarchy
1411 * 3.If destination type is found, return base object address + dest offset
1412 * Otherwise, fail the cast
1414 * FIXME: the unknown parameter doesn't seem to be used for anything
1416 __TRY
1418 int i;
1419 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1420 const rtti_object_hierarchy *obj_bases = obj_locator->type_hierarchy;
1421 const rtti_base_descriptor * const* base_desc = obj_bases->base_classes->bases;
1423 if (TRACE_ON(msvcrt)) dump_obj_locator(obj_locator);
1425 ret = NULL;
1426 for (i = 0; i < obj_bases->array_len; i++)
1428 const type_info *typ = base_desc[i]->type_descriptor;
1430 if (!strcmp(typ->mangled, dst->mangled))
1432 /* compute the correct this pointer for that base class */
1433 void *this_ptr = (char *)cppobj - obj_locator->base_class_offset;
1434 ret = get_this_pointer( &base_desc[i]->offsets, this_ptr );
1435 break;
1438 /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned
1439 * to a reference, since references cannot be NULL.
1441 if (!ret && do_throw)
1443 const char *msg = "Bad dynamic_cast!";
1444 bad_cast e;
1445 MSVCRT_bad_cast_ctor( &e, &msg );
1446 _CxxThrowException( &e, &bad_cast_exception_type );
1449 __EXCEPT_PAGE_FAULT
1451 __non_rtti_object e;
1452 MSVCRT___non_rtti_object_ctor( &e, "Access violation - no RTTI data!" );
1453 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1454 return NULL;
1456 __ENDTRY
1457 return ret;
1460 #else
1462 void* CDECL MSVCRT___RTDynamicCast(void *cppobj, int unknown,
1463 type_info *src, type_info *dst,
1464 int do_throw)
1466 void *ret;
1468 if (!cppobj) return NULL;
1470 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1471 cppobj, unknown, src, dbgstr_type_info(src), dst, dbgstr_type_info(dst), do_throw);
1473 __TRY
1475 int i;
1476 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1477 const rtti_object_hierarchy *obj_bases;
1478 const rtti_base_array *base_array;
1479 char *base;
1481 if (TRACE_ON(msvcrt)) dump_obj_locator(obj_locator);
1483 if(obj_locator->signature == 0)
1484 base = RtlPcToFileHeader((void*)obj_locator, (void**)&base);
1485 else
1486 base = (char*)obj_locator - obj_locator->object_locator;
1488 obj_bases = (const rtti_object_hierarchy*)(base + obj_locator->type_hierarchy);
1489 base_array = (const rtti_base_array*)(base + obj_bases->base_classes);
1491 ret = NULL;
1492 for (i = 0; i < obj_bases->array_len; i++)
1494 const rtti_base_descriptor *base_desc = (const rtti_base_descriptor*)(base + base_array->bases[i]);
1495 const type_info *typ = (const type_info*)(base + base_desc->type_descriptor);
1497 if (!strcmp(typ->mangled, dst->mangled))
1499 void *this_ptr = (char *)cppobj - obj_locator->base_class_offset;
1500 ret = get_this_pointer( &base_desc->offsets, this_ptr );
1501 break;
1504 if (!ret && do_throw)
1506 const char *msg = "Bad dynamic_cast!";
1507 bad_cast e;
1508 MSVCRT_bad_cast_ctor( &e, &msg );
1509 _CxxThrowException( &e, &bad_cast_exception_type );
1512 __EXCEPT_PAGE_FAULT
1514 __non_rtti_object e;
1515 MSVCRT___non_rtti_object_ctor( &e, "Access violation - no RTTI data!" );
1516 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1517 return NULL;
1519 __ENDTRY
1520 return ret;
1522 #endif
1525 /******************************************************************
1526 * __RTCastToVoid (MSVCRT.@)
1528 * Dynamically cast a C++ object to a void*.
1530 * PARAMS
1531 * cppobj [I] The C++ object to cast
1533 * RETURNS
1534 * Success: The base address of the object as a void*.
1535 * Failure: NULL, if cppobj is NULL or has no RTTI.
1537 * NOTES
1538 * This function is usually called by compiler generated code as a result
1539 * of using one of the C++ dynamic cast statements.
1541 void* CDECL MSVCRT___RTCastToVoid(void *cppobj)
1543 void *ret;
1545 if (!cppobj) return NULL;
1547 __TRY
1549 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1550 ret = (char *)cppobj - obj_locator->base_class_offset;
1552 __EXCEPT_PAGE_FAULT
1554 __non_rtti_object e;
1555 MSVCRT___non_rtti_object_ctor( &e, "Access violation - no RTTI data!" );
1556 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1557 return NULL;
1559 __ENDTRY
1560 return ret;
1564 /*********************************************************************
1565 * _CxxThrowException (MSVCRT.@)
1567 #ifndef __x86_64__
1568 void WINAPI _CxxThrowException( exception *object, const cxx_exception_type *type )
1570 ULONG_PTR args[3];
1572 args[0] = CXX_FRAME_MAGIC_VC6;
1573 args[1] = (ULONG_PTR)object;
1574 args[2] = (ULONG_PTR)type;
1575 RaiseException( CXX_EXCEPTION, EH_NONCONTINUABLE, 3, args );
1577 #else
1578 void WINAPI _CxxThrowException( exception *object, const cxx_exception_type *type )
1580 ULONG_PTR args[4];
1582 args[0] = CXX_FRAME_MAGIC_VC6;
1583 args[1] = (ULONG_PTR)object;
1584 args[2] = (ULONG_PTR)type;
1585 RtlPcToFileHeader( (void*)type, (void**)&args[3]);
1586 RaiseException( CXX_EXCEPTION, EH_NONCONTINUABLE, 4, args );
1588 #endif
1590 #if _MSVCR_VER >= 80
1592 /*********************************************************************
1593 * ?_is_exception_typeof@@YAHABVtype_info@@PAU_EXCEPTION_POINTERS@@@Z
1594 * ?_is_exception_typeof@@YAHAEBVtype_info@@PEAU_EXCEPTION_POINTERS@@@Z
1596 #ifndef __x86_64__
1597 int __cdecl _is_exception_typeof(const type_info *ti, EXCEPTION_POINTERS *ep)
1599 int ret = -1;
1601 TRACE("(%p %p)\n", ti, ep);
1603 __TRY
1605 EXCEPTION_RECORD *rec = ep->ExceptionRecord;
1607 if (rec->ExceptionCode==CXX_EXCEPTION && rec->NumberParameters==3 &&
1608 (rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC6 ||
1609 rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC7 ||
1610 rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC8))
1612 const cxx_type_info_table *tit = ((cxx_exception_type*)rec->ExceptionInformation[2])->type_info_table;
1613 int i;
1615 for (i=0; i<tit->count; i++) {
1616 if (ti==tit->info[i]->type_info || !strcmp(ti->mangled, tit->info[i]->type_info->mangled))
1618 ret = 1;
1619 break;
1623 if (i == tit->count)
1624 ret = 0;
1627 __EXCEPT_PAGE_FAULT
1628 __ENDTRY
1630 if(ret == -1)
1631 MSVCRT_terminate();
1632 return ret;
1634 #else
1635 int __cdecl _is_exception_typeof(const type_info *ti, EXCEPTION_POINTERS *ep)
1637 int ret = -1;
1639 TRACE("(%p %p)\n", ti, ep);
1641 __TRY
1643 EXCEPTION_RECORD *rec = ep->ExceptionRecord;
1645 if (rec->ExceptionCode==CXX_EXCEPTION && rec->NumberParameters==4 &&
1646 (rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC6 ||
1647 rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC7 ||
1648 rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC8))
1650 const cxx_exception_type *et = (cxx_exception_type*)rec->ExceptionInformation[2];
1651 const cxx_type_info_table *tit = (const cxx_type_info_table*)(rec->ExceptionInformation[3]+et->type_info_table);
1652 int i;
1654 for (i=0; i<tit->count; i++) {
1655 const cxx_type_info *cti = (const cxx_type_info*)(rec->ExceptionInformation[3]+tit->info[i]);
1656 const type_info *except_ti = (const type_info*)(rec->ExceptionInformation[3]+cti->type_info);
1657 if (ti==except_ti || !strcmp(ti->mangled, except_ti->mangled))
1659 ret = 1;
1660 break;
1664 if (i == tit->count)
1665 ret = 0;
1668 __EXCEPT_PAGE_FAULT
1669 __ENDTRY
1671 if(ret == -1)
1672 MSVCRT_terminate();
1673 return ret;
1675 #endif
1677 /*********************************************************************
1678 * __clean_type_info_names_internal (MSVCR80.@)
1680 void CDECL __clean_type_info_names_internal(void *p)
1682 FIXME("(%p) stub\n", p);
1685 /*********************************************************************
1686 * ?_name_internal_method@type_info@@QBEPBDPAU__type_info_node@@@Z (MSVCR100.@)
1688 DEFINE_THISCALL_WRAPPER(type_info_name_internal_method,8)
1689 const char * __thiscall type_info_name_internal_method(type_info * _this, struct __type_info_node *node)
1691 static int once;
1692 if (node && !once++) FIXME("type_info_node parameter ignored\n");
1694 return MSVCRT_type_info_name(_this);
1697 #endif /* _MSVCR_VER >= 80 */
1699 /* std::exception_ptr class helpers */
1700 typedef struct
1702 EXCEPTION_RECORD *rec;
1703 int *ref; /* not binary compatible with native msvcr100 */
1704 } exception_ptr;
1706 #if _MSVCR_VER >= 100
1708 /*********************************************************************
1709 * ?__ExceptionPtrCreate@@YAXPAX@Z
1710 * ?__ExceptionPtrCreate@@YAXPEAX@Z
1712 void __cdecl __ExceptionPtrCreate(exception_ptr *ep)
1714 TRACE("(%p)\n", ep);
1716 ep->rec = NULL;
1717 ep->ref = NULL;
1720 #ifdef __i386__
1721 extern void call_dtor(const cxx_exception_type *type, void *func, void *object);
1723 __ASM_GLOBAL_FUNC( call_dtor,
1724 "movl 12(%esp),%ecx\n\t"
1725 "call *8(%esp)\n\t"
1726 "ret" );
1727 #elif __x86_64__
1728 static inline void call_dtor(const cxx_exception_type *type, unsigned int dtor, void *object)
1730 char *base = RtlPcToFileHeader((void*)type, (void**)&base);
1731 void (__cdecl *func)(void*) = (void*)(base + dtor);
1732 func(object);
1734 #else
1735 #define call_dtor(type, func, object) ((void (__cdecl*)(void*))(func))(object)
1736 #endif
1738 /*********************************************************************
1739 * ?__ExceptionPtrDestroy@@YAXPAX@Z
1740 * ?__ExceptionPtrDestroy@@YAXPEAX@Z
1742 void __cdecl __ExceptionPtrDestroy(exception_ptr *ep)
1744 TRACE("(%p)\n", ep);
1746 if (!ep->rec)
1747 return;
1749 if (!InterlockedDecrement(ep->ref))
1751 if (ep->rec->ExceptionCode == CXX_EXCEPTION)
1753 const cxx_exception_type *type = (void*)ep->rec->ExceptionInformation[2];
1754 void *obj = (void*)ep->rec->ExceptionInformation[1];
1756 if (type && type->destructor) call_dtor(type, type->destructor, obj);
1757 HeapFree(GetProcessHeap(), 0, obj);
1760 HeapFree(GetProcessHeap(), 0, ep->rec);
1761 HeapFree(GetProcessHeap(), 0, ep->ref);
1765 /*********************************************************************
1766 * ?__ExceptionPtrCopy@@YAXPAXPBX@Z
1767 * ?__ExceptionPtrCopy@@YAXPEAXPEBX@Z
1769 void __cdecl __ExceptionPtrCopy(exception_ptr *ep, const exception_ptr *copy)
1771 TRACE("(%p %p)\n", ep, copy);
1773 /* don't destroy object stored in ep */
1774 *ep = *copy;
1775 if (ep->ref)
1776 InterlockedIncrement(copy->ref);
1779 /*********************************************************************
1780 * ?__ExceptionPtrAssign@@YAXPAXPBX@Z
1781 * ?__ExceptionPtrAssign@@YAXPEAXPEBX@Z
1783 void __cdecl __ExceptionPtrAssign(exception_ptr *ep, const exception_ptr *assign)
1785 TRACE("(%p %p)\n", ep, assign);
1787 /* don't destroy object stored in ep */
1788 if (ep->ref)
1789 InterlockedDecrement(ep->ref);
1791 *ep = *assign;
1792 if (ep->ref)
1793 InterlockedIncrement(ep->ref);
1796 #endif /* _MSVCR_VER >= 100 */
1798 /*********************************************************************
1799 * ?__ExceptionPtrRethrow@@YAXPBX@Z
1800 * ?__ExceptionPtrRethrow@@YAXPEBX@Z
1802 void __cdecl __ExceptionPtrRethrow(const exception_ptr *ep)
1804 TRACE("(%p)\n", ep);
1806 if (!ep->rec)
1808 static const char *exception_msg = "bad exception";
1809 exception e;
1811 MSVCRT_exception_ctor(&e, &exception_msg);
1812 _CxxThrowException(&e, &exception_exception_type);
1813 return;
1816 RaiseException(ep->rec->ExceptionCode, ep->rec->ExceptionFlags & (~EH_UNWINDING),
1817 ep->rec->NumberParameters, ep->rec->ExceptionInformation);
1820 #if _MSVCR_VER >= 100
1822 #ifdef __i386__
1823 extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase );
1824 #else
1825 static inline void call_copy_ctor( void *func, void *this, void *src, int has_vbase )
1827 TRACE( "calling copy ctor %p object %p src %p\n", func, this, src );
1828 if (has_vbase)
1829 ((void (__cdecl*)(void*, void*, BOOL))func)(this, src, 1);
1830 else
1831 ((void (__cdecl*)(void*, void*))func)(this, src);
1833 #endif
1835 /*********************************************************************
1836 * ?__ExceptionPtrCurrentException@@YAXPAX@Z
1837 * ?__ExceptionPtrCurrentException@@YAXPEAX@Z
1839 #ifndef __x86_64__
1840 void __cdecl __ExceptionPtrCurrentException(exception_ptr *ep)
1842 EXCEPTION_RECORD *rec = msvcrt_get_thread_data()->exc_record;
1844 TRACE("(%p)\n", ep);
1846 if (!rec)
1848 ep->rec = NULL;
1849 ep->ref = NULL;
1850 return;
1853 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1854 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1856 *ep->rec = *rec;
1857 *ep->ref = 1;
1859 if (ep->rec->ExceptionCode == CXX_EXCEPTION)
1861 const cxx_exception_type *et = (void*)ep->rec->ExceptionInformation[2];
1862 const cxx_type_info *ti;
1863 void **data, *obj;
1865 ti = et->type_info_table->info[0];
1866 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1868 obj = (void*)ep->rec->ExceptionInformation[1];
1869 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1871 memcpy(data, obj, ti->size);
1872 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1874 else if (ti->copy_ctor)
1876 call_copy_ctor(ti->copy_ctor, data, get_this_pointer(&ti->offsets, obj),
1877 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1879 else
1880 memcpy(data, get_this_pointer(&ti->offsets, obj), ti->size);
1881 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1883 return;
1885 #else
1886 void __cdecl __ExceptionPtrCurrentException(exception_ptr *ep)
1888 EXCEPTION_RECORD *rec = msvcrt_get_thread_data()->exc_record;
1890 TRACE("(%p)\n", ep);
1892 if (!rec)
1894 ep->rec = NULL;
1895 ep->ref = NULL;
1896 return;
1899 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1900 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1902 *ep->rec = *rec;
1903 *ep->ref = 1;
1905 if (ep->rec->ExceptionCode == CXX_EXCEPTION)
1907 const cxx_exception_type *et = (void*)ep->rec->ExceptionInformation[2];
1908 const cxx_type_info *ti;
1909 void **data, *obj;
1910 char *base = RtlPcToFileHeader((void*)et, (void**)&base);
1912 ti = (const cxx_type_info*)(base + ((const cxx_type_info_table*)(base + et->type_info_table))->info[0]);
1913 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1915 obj = (void*)ep->rec->ExceptionInformation[1];
1916 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1918 memcpy(data, obj, ti->size);
1919 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1921 else if (ti->copy_ctor)
1923 call_copy_ctor(base + ti->copy_ctor, data, get_this_pointer(&ti->offsets, obj),
1924 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1926 else
1927 memcpy(data, get_this_pointer(&ti->offsets, obj), ti->size);
1928 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1930 return;
1932 #endif
1934 #endif /* _MSVCR_VER >= 100 */
1936 #if _MSVCR_VER >= 110
1937 /*********************************************************************
1938 * ?__ExceptionPtrToBool@@YA_NPBX@Z
1939 * ?__ExceptionPtrToBool@@YA_NPEBX@Z
1941 MSVCRT_bool __cdecl __ExceptionPtrToBool(exception_ptr *ep)
1943 return !!ep->rec;
1945 #endif
1947 #if _MSVCR_VER >= 100
1949 /*********************************************************************
1950 * ?__ExceptionPtrCopyException@@YAXPAXPBX1@Z
1951 * ?__ExceptionPtrCopyException@@YAXPEAXPEBX1@Z
1953 #ifndef __x86_64__
1954 void __cdecl __ExceptionPtrCopyException(exception_ptr *ep,
1955 exception *object, const cxx_exception_type *type)
1957 const cxx_type_info *ti;
1958 void **data;
1960 __ExceptionPtrDestroy(ep);
1962 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1963 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1964 *ep->ref = 1;
1966 memset(ep->rec, 0, sizeof(EXCEPTION_RECORD));
1967 ep->rec->ExceptionCode = CXX_EXCEPTION;
1968 ep->rec->ExceptionFlags = EH_NONCONTINUABLE;
1969 ep->rec->NumberParameters = 3;
1970 ep->rec->ExceptionInformation[0] = CXX_FRAME_MAGIC_VC6;
1971 ep->rec->ExceptionInformation[2] = (ULONG_PTR)type;
1973 ti = type->type_info_table->info[0];
1974 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1975 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1977 memcpy(data, object, ti->size);
1978 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1980 else if (ti->copy_ctor)
1982 call_copy_ctor(ti->copy_ctor, data, get_this_pointer(&ti->offsets, object),
1983 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1985 else
1986 memcpy(data, get_this_pointer(&ti->offsets, object), ti->size);
1987 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1989 #else
1990 void __cdecl __ExceptionPtrCopyException(exception_ptr *ep,
1991 exception *object, const cxx_exception_type *type)
1993 const cxx_type_info *ti;
1994 void **data;
1995 char *base;
1997 RtlPcToFileHeader((void*)type, (void**)&base);
1998 __ExceptionPtrDestroy(ep);
2000 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
2001 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
2002 *ep->ref = 1;
2004 memset(ep->rec, 0, sizeof(EXCEPTION_RECORD));
2005 ep->rec->ExceptionCode = CXX_EXCEPTION;
2006 ep->rec->ExceptionFlags = EH_NONCONTINUABLE;
2007 ep->rec->NumberParameters = 4;
2008 ep->rec->ExceptionInformation[0] = CXX_FRAME_MAGIC_VC6;
2009 ep->rec->ExceptionInformation[2] = (ULONG_PTR)type;
2010 ep->rec->ExceptionInformation[3] = (ULONG_PTR)base;
2012 ti = (const cxx_type_info*)(base + ((const cxx_type_info_table*)(base + type->type_info_table))->info[0]);
2013 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
2014 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
2016 memcpy(data, object, ti->size);
2017 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
2019 else if (ti->copy_ctor)
2021 call_copy_ctor(base + ti->copy_ctor, data, get_this_pointer(&ti->offsets, object),
2022 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
2024 else
2025 memcpy(data, get_this_pointer(&ti->offsets, object), ti->size);
2026 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
2028 #endif
2030 MSVCRT_bool __cdecl __ExceptionPtrCompare(const exception_ptr *ep1, const exception_ptr *ep2)
2032 return ep1->rec == ep2->rec;
2035 #endif /* _MSVCR_VER >= 100 */
2037 #if _MSVCR_VER >= 80
2038 void* __cdecl __AdjustPointer(void *obj, const this_ptr_offsets *off)
2040 return get_this_pointer(off, obj);
2042 #endif
2044 #if _MSVCR_VER >= 140
2046 typedef struct
2048 char *name;
2049 char mangled[1];
2050 } type_info140;
2052 typedef struct
2054 SLIST_ENTRY entry;
2055 char name[1];
2056 } type_info_entry;
2058 static void* CDECL type_info_entry_malloc(MSVCRT_size_t size)
2060 type_info_entry *ret = MSVCRT_malloc(FIELD_OFFSET(type_info_entry, name) + size);
2061 return ret->name;
2064 static void CDECL type_info_entry_free(void *ptr)
2066 ptr = (char*)ptr - FIELD_OFFSET(type_info_entry, name);
2067 MSVCRT_free(ptr);
2070 /******************************************************************
2071 * __std_type_info_compare (UCRTBASE.@)
2073 int CDECL MSVCRT_type_info_compare(const type_info140 *l, const type_info140 *r)
2075 int ret;
2077 if (l == r) ret = 0;
2078 else ret = strcmp(l->mangled + 1, r->mangled + 1);
2079 TRACE("(%p %p) returning %d\n", l, r, ret);
2080 return ret;
2083 /******************************************************************
2084 * __std_type_info_name (UCRTBASE.@)
2086 const char* CDECL MSVCRT_type_info_name_list(type_info140 *ti, SLIST_HEADER *header)
2088 if (!ti->name)
2090 char* name = __unDName(0, ti->mangled + 1, 0,
2091 type_info_entry_malloc, type_info_entry_free, UNDNAME_NO_ARGUMENTS | UNDNAME_32_BIT_DECODE);
2092 if (name)
2094 unsigned int len = strlen(name);
2096 while (len && name[--len] == ' ')
2097 name[len] = '\0';
2099 if (InterlockedCompareExchangePointer((void**)&ti->name, name, NULL))
2101 type_info_entry_free(name);
2103 else
2105 type_info_entry *entry = (type_info_entry*)(name-FIELD_OFFSET(type_info_entry, name));
2106 InterlockedPushEntrySList(header, &entry->entry);
2110 TRACE("(%p) returning %s\n", ti, ti->name);
2111 return ti->name;
2114 /******************************************************************
2115 * __std_type_info_destroy_list (UCRTBASE.@)
2117 void CDECL MSVCRT_type_info_destroy_list(SLIST_HEADER *header)
2119 SLIST_ENTRY *cur, *next;
2121 TRACE("(%p)\n", header);
2123 for(cur = InterlockedFlushSList(header); cur; cur = next)
2125 next = cur->Next;
2126 MSVCRT_free(cur);
2130 /******************************************************************
2131 * __std_type_info_hash (UCRTBASE.@)
2133 MSVCRT_size_t CDECL MSVCRT_type_info_hash(const type_info140 *ti)
2135 MSVCRT_size_t hash, fnv_prime;
2136 const char *p;
2138 #ifdef _WIN64
2139 hash = 0xcbf29ce484222325;
2140 fnv_prime = 0x100000001b3;
2141 #else
2142 hash = 0x811c9dc5;
2143 fnv_prime = 0x1000193;
2144 #endif
2146 TRACE("(%p)->%s\n", ti, ti->mangled);
2148 for(p = ti->mangled+1; *p; p++) {
2149 hash ^= *p;
2150 hash *= fnv_prime;
2153 #ifdef _WIN64
2154 hash ^= hash >> 32;
2155 #endif
2157 return hash;
2160 #endif /* _MSVCR_VER >= 140 */
2162 #if _MSVCR_VER >= 100
2164 enum ConcRT_EventType
2166 CONCRT_EVENT_GENERIC,
2167 CONCRT_EVENT_START,
2168 CONCRT_EVENT_END,
2169 CONCRT_EVENT_BLOCK,
2170 CONCRT_EVENT_UNBLOCK,
2171 CONCRT_EVENT_YIELD,
2172 CONCRT_EVENT_ATTACH,
2173 CONCRT_EVENT_DETACH
2176 /* ?_Trace_ppl_function@Concurrency@@YAXABU_GUID@@EW4ConcRT_EventType@1@@Z */
2177 /* ?_Trace_ppl_function@Concurrency@@YAXAEBU_GUID@@EW4ConcRT_EventType@1@@Z */
2178 void __cdecl Concurrency__Trace_ppl_function(const GUID *guid, unsigned char level, enum ConcRT_EventType type)
2180 FIXME("(%s %u %i) stub\n", debugstr_guid(guid), level, type);
2183 #endif /* _MSVCR_VER >= 100 */