wow64: Add thunks for the I/O completion syscalls.
[wine.git] / dlls / msvcrt / cpp.c
blobffb91175a8ff2c25ad8a0164fd0495b158f0c785
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 <stdarg.h>
23 #include <stdbool.h>
25 #include "windef.h"
26 #include "winternl.h"
27 #include "wine/exception.h"
28 #include "wine/debug.h"
29 #include "msvcrt.h"
30 #include "cppexcept.h"
31 #include "mtdll.h"
32 #include "cxx.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
36 struct __type_info_node
38 void *memPtr;
39 struct __type_info_node* next;
42 typedef exception bad_cast;
43 typedef exception bad_typeid;
44 typedef exception __non_rtti_object;
46 extern const vtable_ptr exception_vtable;
47 extern const vtable_ptr bad_typeid_vtable;
48 extern const vtable_ptr bad_cast_vtable;
49 extern const vtable_ptr __non_rtti_object_vtable;
50 extern const vtable_ptr type_info_vtable;
52 /* get the vtable pointer for a C++ object */
53 static inline const vtable_ptr *get_vtable( void *obj )
55 return *(const vtable_ptr **)obj;
58 static inline const rtti_object_locator *get_obj_locator( void *cppobj )
60 const vtable_ptr *vtable = get_vtable( cppobj );
61 return (const rtti_object_locator *)vtable[-1];
64 #ifndef __x86_64__
65 static void dump_obj_locator( const rtti_object_locator *ptr )
67 int i;
68 const rtti_object_hierarchy *h = ptr->type_hierarchy;
70 TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n",
71 ptr, ptr->signature, ptr->base_class_offset, ptr->flags,
72 ptr->type_descriptor, dbgstr_type_info(ptr->type_descriptor), ptr->type_hierarchy );
73 TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n",
74 h->signature, h->attributes, h->array_len, h->base_classes );
75 for (i = 0; i < h->array_len; i++)
77 TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n",
78 h->base_classes->bases[i],
79 h->base_classes->bases[i]->num_base_classes,
80 h->base_classes->bases[i]->offsets.this_offset,
81 h->base_classes->bases[i]->offsets.vbase_descr,
82 h->base_classes->bases[i]->offsets.vbase_offset,
83 h->base_classes->bases[i]->attributes,
84 h->base_classes->bases[i]->type_descriptor,
85 dbgstr_type_info(h->base_classes->bases[i]->type_descriptor) );
89 #else
91 static void dump_obj_locator( const rtti_object_locator *ptr )
93 int i;
94 char *base = ptr->signature == 0 ? RtlPcToFileHeader((void*)ptr, (void**)&base) : (char*)ptr - ptr->object_locator;
95 const rtti_object_hierarchy *h = (const rtti_object_hierarchy*)(base + ptr->type_hierarchy);
96 const type_info *type_descriptor = (const type_info*)(base + ptr->type_descriptor);
98 TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n",
99 ptr, ptr->signature, ptr->base_class_offset, ptr->flags,
100 type_descriptor, dbgstr_type_info(type_descriptor), h );
101 TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n",
102 h->signature, h->attributes, h->array_len, base + h->base_classes );
103 for (i = 0; i < h->array_len; i++)
105 const rtti_base_descriptor *bases = (rtti_base_descriptor*)(base +
106 ((const rtti_base_array*)(base + h->base_classes))->bases[i]);
108 TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n",
109 bases,
110 bases->num_base_classes,
111 bases->offsets.this_offset,
112 bases->offsets.vbase_descr,
113 bases->offsets.vbase_offset,
114 bases->attributes,
115 base + bases->type_descriptor,
116 dbgstr_type_info((const type_info*)(base + bases->type_descriptor)) );
119 #endif
121 /* Internal common ctor for exception */
122 static void EXCEPTION_ctor(exception *_this, const char** name)
124 _this->vtable = &exception_vtable;
125 if (*name)
127 unsigned int name_len = strlen(*name) + 1;
128 _this->name = malloc(name_len);
129 memcpy(_this->name, *name, name_len);
130 _this->do_free = TRUE;
132 else
134 _this->name = NULL;
135 _this->do_free = FALSE;
139 /******************************************************************
140 * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
142 DEFINE_THISCALL_WRAPPER(exception_ctor,8)
143 exception * __thiscall exception_ctor(exception * _this, const char ** name)
145 TRACE("(%p,%s)\n", _this, *name);
146 EXCEPTION_ctor(_this, name);
147 return _this;
150 /******************************************************************
151 * ??0exception@@QAE@ABQBDH@Z (MSVCRT.@)
153 DEFINE_THISCALL_WRAPPER(exception_ctor_noalloc,12)
154 exception * __thiscall exception_ctor_noalloc(exception * _this, char ** name, int noalloc)
156 TRACE("(%p,%s)\n", _this, *name);
157 _this->vtable = &exception_vtable;
158 _this->name = *name;
159 _this->do_free = FALSE;
160 return _this;
163 /******************************************************************
164 * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
166 DEFINE_THISCALL_WRAPPER(exception_copy_ctor,8)
167 exception * __thiscall exception_copy_ctor(exception * _this, const exception * rhs)
169 TRACE("(%p,%p)\n", _this, rhs);
171 if (!rhs->do_free)
173 _this->vtable = &exception_vtable;
174 _this->name = rhs->name;
175 _this->do_free = FALSE;
177 else
178 EXCEPTION_ctor(_this, (const char**)&rhs->name);
179 TRACE("name = %s\n", _this->name);
180 return _this;
183 /******************************************************************
184 * ??0exception@@QAE@XZ (MSVCRT.@)
186 DEFINE_THISCALL_WRAPPER(exception_default_ctor,4)
187 exception * __thiscall exception_default_ctor(exception * _this)
189 static const char* empty = NULL;
191 TRACE("(%p)\n", _this);
192 EXCEPTION_ctor(_this, &empty);
193 return _this;
196 /******************************************************************
197 * ??1exception@@UAE@XZ (MSVCRT.@)
199 DEFINE_THISCALL_WRAPPER(exception_dtor,4)
200 void __thiscall exception_dtor(exception * _this)
202 TRACE("(%p)\n", _this);
203 _this->vtable = &exception_vtable;
204 if (_this->do_free) free(_this->name);
207 /******************************************************************
208 * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
210 DEFINE_THISCALL_WRAPPER(exception_opequals,8)
211 exception * __thiscall exception_opequals(exception * _this, const exception * rhs)
213 TRACE("(%p %p)\n", _this, rhs);
214 if (_this != rhs)
216 exception_dtor(_this);
217 exception_copy_ctor(_this, rhs);
219 TRACE("name = %s\n", _this->name);
220 return _this;
223 /******************************************************************
224 * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
226 DEFINE_THISCALL_WRAPPER(exception_vector_dtor,8)
227 void * __thiscall exception_vector_dtor(exception * _this, unsigned int flags)
229 TRACE("(%p %x)\n", _this, flags);
230 if (flags & 2)
232 /* we have an array, with the number of elements stored before the first object */
233 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
235 for (i = *ptr - 1; i >= 0; i--) exception_dtor(_this + i);
236 operator_delete(ptr);
238 else
240 exception_dtor(_this);
241 if (flags & 1) operator_delete(_this);
243 return _this;
246 /******************************************************************
247 * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
249 DEFINE_THISCALL_WRAPPER(exception_scalar_dtor,8)
250 void * __thiscall exception_scalar_dtor(exception * _this, unsigned int flags)
252 TRACE("(%p %x)\n", _this, flags);
253 exception_dtor(_this);
254 if (flags & 1) operator_delete(_this);
255 return _this;
258 /******************************************************************
259 * ?what@exception@@UBEPBDXZ (MSVCRT.@)
261 DEFINE_THISCALL_WRAPPER(what_exception,4)
262 const char * __thiscall what_exception(exception * _this)
264 TRACE("(%p) returning %s\n", _this, _this->name);
265 return _this->name ? _this->name : "Unknown exception";
268 /******************************************************************
269 * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
271 DEFINE_THISCALL_WRAPPER(bad_typeid_copy_ctor,8)
272 bad_typeid * __thiscall bad_typeid_copy_ctor(bad_typeid * _this, const bad_typeid * rhs)
274 TRACE("(%p %p)\n", _this, rhs);
275 exception_copy_ctor(_this, rhs);
276 _this->vtable = &bad_typeid_vtable;
277 return _this;
280 /******************************************************************
281 * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
283 DEFINE_THISCALL_WRAPPER(bad_typeid_ctor,8)
284 bad_typeid * __thiscall bad_typeid_ctor(bad_typeid * _this, const char * name)
286 TRACE("(%p %s)\n", _this, name);
287 EXCEPTION_ctor(_this, &name);
288 _this->vtable = &bad_typeid_vtable;
289 return _this;
292 /******************************************************************
293 * ??_Fbad_typeid@@QAEXXZ (MSVCRT.@)
295 DEFINE_THISCALL_WRAPPER(bad_typeid_default_ctor,4)
296 bad_typeid * __thiscall bad_typeid_default_ctor(bad_typeid * _this)
298 return bad_typeid_ctor( _this, "bad typeid" );
301 /******************************************************************
302 * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
304 DEFINE_THISCALL_WRAPPER(bad_typeid_dtor,4)
305 void __thiscall bad_typeid_dtor(bad_typeid * _this)
307 TRACE("(%p)\n", _this);
308 exception_dtor(_this);
311 /******************************************************************
312 * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
314 DEFINE_THISCALL_WRAPPER(bad_typeid_opequals,8)
315 bad_typeid * __thiscall bad_typeid_opequals(bad_typeid * _this, const bad_typeid * rhs)
317 TRACE("(%p %p)\n", _this, rhs);
318 exception_opequals(_this, rhs);
319 return _this;
322 /******************************************************************
323 * ??_Ebad_typeid@@UAEPAXI@Z (MSVCRT.@)
325 DEFINE_THISCALL_WRAPPER(bad_typeid_vector_dtor,8)
326 void * __thiscall bad_typeid_vector_dtor(bad_typeid * _this, unsigned int flags)
328 TRACE("(%p %x)\n", _this, flags);
329 if (flags & 2)
331 /* we have an array, with the number of elements stored before the first object */
332 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
334 for (i = *ptr - 1; i >= 0; i--) bad_typeid_dtor(_this + i);
335 operator_delete(ptr);
337 else
339 bad_typeid_dtor(_this);
340 if (flags & 1) operator_delete(_this);
342 return _this;
345 /******************************************************************
346 * ??_Gbad_typeid@@UAEPAXI@Z (MSVCRT.@)
348 DEFINE_THISCALL_WRAPPER(bad_typeid_scalar_dtor,8)
349 void * __thiscall bad_typeid_scalar_dtor(bad_typeid * _this, unsigned int flags)
351 TRACE("(%p %x)\n", _this, flags);
352 bad_typeid_dtor(_this);
353 if (flags & 1) operator_delete(_this);
354 return _this;
357 /******************************************************************
358 * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
360 DEFINE_THISCALL_WRAPPER(__non_rtti_object_copy_ctor,8)
361 __non_rtti_object * __thiscall __non_rtti_object_copy_ctor(__non_rtti_object * _this,
362 const __non_rtti_object * rhs)
364 TRACE("(%p %p)\n", _this, rhs);
365 bad_typeid_copy_ctor(_this, rhs);
366 _this->vtable = &__non_rtti_object_vtable;
367 return _this;
370 /******************************************************************
371 * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
373 DEFINE_THISCALL_WRAPPER(__non_rtti_object_ctor,8)
374 __non_rtti_object * __thiscall __non_rtti_object_ctor(__non_rtti_object * _this,
375 const char * name)
377 TRACE("(%p %s)\n", _this, name);
378 EXCEPTION_ctor(_this, &name);
379 _this->vtable = &__non_rtti_object_vtable;
380 return _this;
383 /******************************************************************
384 * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
386 DEFINE_THISCALL_WRAPPER(__non_rtti_object_dtor,4)
387 void __thiscall __non_rtti_object_dtor(__non_rtti_object * _this)
389 TRACE("(%p)\n", _this);
390 bad_typeid_dtor(_this);
393 /******************************************************************
394 * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
396 DEFINE_THISCALL_WRAPPER(__non_rtti_object_opequals,8)
397 __non_rtti_object * __thiscall __non_rtti_object_opequals(__non_rtti_object * _this,
398 const __non_rtti_object *rhs)
400 TRACE("(%p %p)\n", _this, rhs);
401 bad_typeid_opequals(_this, rhs);
402 return _this;
405 /******************************************************************
406 * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
408 DEFINE_THISCALL_WRAPPER(__non_rtti_object_vector_dtor,8)
409 void * __thiscall __non_rtti_object_vector_dtor(__non_rtti_object * _this, unsigned int flags)
411 TRACE("(%p %x)\n", _this, flags);
412 if (flags & 2)
414 /* we have an array, with the number of elements stored before the first object */
415 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
417 for (i = *ptr - 1; i >= 0; i--) __non_rtti_object_dtor(_this + i);
418 operator_delete(ptr);
420 else
422 __non_rtti_object_dtor(_this);
423 if (flags & 1) operator_delete(_this);
425 return _this;
428 /******************************************************************
429 * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
431 DEFINE_THISCALL_WRAPPER(__non_rtti_object_scalar_dtor,8)
432 void * __thiscall __non_rtti_object_scalar_dtor(__non_rtti_object * _this, unsigned int flags)
434 TRACE("(%p %x)\n", _this, flags);
435 __non_rtti_object_dtor(_this);
436 if (flags & 1) operator_delete(_this);
437 return _this;
440 /******************************************************************
441 * ??0bad_cast@@AAE@PBQBD@Z (MSVCRT.@)
442 * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
444 DEFINE_THISCALL_WRAPPER(bad_cast_ctor,8)
445 bad_cast * __thiscall bad_cast_ctor(bad_cast * _this, const char ** name)
447 TRACE("(%p %s)\n", _this, *name);
448 EXCEPTION_ctor(_this, name);
449 _this->vtable = &bad_cast_vtable;
450 return _this;
453 /******************************************************************
454 * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
456 DEFINE_THISCALL_WRAPPER(bad_cast_copy_ctor,8)
457 bad_cast * __thiscall bad_cast_copy_ctor(bad_cast * _this, const bad_cast * rhs)
459 TRACE("(%p %p)\n", _this, rhs);
460 exception_copy_ctor(_this, rhs);
461 _this->vtable = &bad_cast_vtable;
462 return _this;
465 /******************************************************************
466 * ??0bad_cast@@QAE@PBD@Z (MSVCRT.@)
468 DEFINE_THISCALL_WRAPPER(bad_cast_ctor_charptr,8)
469 bad_cast * __thiscall bad_cast_ctor_charptr(bad_cast * _this, const char * name)
471 TRACE("(%p %s)\n", _this, name);
472 EXCEPTION_ctor(_this, &name);
473 _this->vtable = &bad_cast_vtable;
474 return _this;
477 /******************************************************************
478 * ??_Fbad_cast@@QAEXXZ (MSVCRT.@)
480 DEFINE_THISCALL_WRAPPER(bad_cast_default_ctor,4)
481 bad_cast * __thiscall bad_cast_default_ctor(bad_cast * _this)
483 return bad_cast_ctor_charptr( _this, "bad cast" );
486 /******************************************************************
487 * ??1bad_cast@@UAE@XZ (MSVCRT.@)
489 DEFINE_THISCALL_WRAPPER(bad_cast_dtor,4)
490 void __thiscall bad_cast_dtor(bad_cast * _this)
492 TRACE("(%p)\n", _this);
493 exception_dtor(_this);
496 /******************************************************************
497 * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
499 DEFINE_THISCALL_WRAPPER(bad_cast_opequals,8)
500 bad_cast * __thiscall bad_cast_opequals(bad_cast * _this, const bad_cast * rhs)
502 TRACE("(%p %p)\n", _this, rhs);
503 exception_opequals(_this, rhs);
504 return _this;
507 /******************************************************************
508 * ??_Ebad_cast@@UAEPAXI@Z (MSVCRT.@)
510 DEFINE_THISCALL_WRAPPER(bad_cast_vector_dtor,8)
511 void * __thiscall bad_cast_vector_dtor(bad_cast * _this, unsigned int flags)
513 TRACE("(%p %x)\n", _this, flags);
514 if (flags & 2)
516 /* we have an array, with the number of elements stored before the first object */
517 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
519 for (i = *ptr - 1; i >= 0; i--) bad_cast_dtor(_this + i);
520 operator_delete(ptr);
522 else
524 bad_cast_dtor(_this);
525 if (flags & 1) operator_delete(_this);
527 return _this;
530 /******************************************************************
531 * ??_Gbad_cast@@UAEPAXI@Z (MSVCRT.@)
533 DEFINE_THISCALL_WRAPPER(bad_cast_scalar_dtor,8)
534 void * __thiscall bad_cast_scalar_dtor(bad_cast * _this, unsigned int flags)
536 TRACE("(%p %x)\n", _this, flags);
537 bad_cast_dtor(_this);
538 if (flags & 1) operator_delete(_this);
539 return _this;
542 /******************************************************************
543 * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
545 DEFINE_THISCALL_WRAPPER(type_info_opequals_equals,8)
546 int __thiscall type_info_opequals_equals(type_info * _this, const type_info * rhs)
548 int ret = !strcmp(_this->mangled + 1, rhs->mangled + 1);
549 TRACE("(%p %p) returning %d\n", _this, rhs, ret);
550 return ret;
553 /******************************************************************
554 * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
556 DEFINE_THISCALL_WRAPPER(type_info_opnot_equals,8)
557 int __thiscall type_info_opnot_equals(type_info * _this, const type_info * rhs)
559 int ret = !!strcmp(_this->mangled + 1, rhs->mangled + 1);
560 TRACE("(%p %p) returning %d\n", _this, rhs, ret);
561 return ret;
564 /******************************************************************
565 * ?before@type_info@@QBEHABV1@@Z (MSVCRT.@)
567 DEFINE_THISCALL_WRAPPER(type_info_before,8)
568 int __thiscall type_info_before(type_info * _this, const type_info * rhs)
570 int ret = strcmp(_this->mangled + 1, rhs->mangled + 1) < 0;
571 TRACE("(%p %p) returning %d\n", _this, rhs, ret);
572 return ret;
575 /******************************************************************
576 * ??1type_info@@UAE@XZ (MSVCRT.@)
578 DEFINE_THISCALL_WRAPPER(type_info_dtor,4)
579 void __thiscall type_info_dtor(type_info * _this)
581 TRACE("(%p)\n", _this);
582 free(_this->name);
585 /******************************************************************
586 * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
588 DEFINE_THISCALL_WRAPPER(type_info_name,4)
589 const char * __thiscall type_info_name(type_info * _this)
591 if (!_this->name)
593 /* Create and set the demangled name */
594 /* Note: mangled name in type_info struct always starts with a '.', while
595 * it isn't valid for mangled name.
596 * Is this '.' really part of the mangled name, or has it some other meaning ?
598 char* name = __unDName(0, _this->mangled + 1, 0,
599 malloc, free, UNDNAME_NO_ARGUMENTS | UNDNAME_32_BIT_DECODE);
600 if (name)
602 unsigned int len = strlen(name);
604 /* It seems _unDName may leave blanks at the end of the demangled name */
605 while (len && name[--len] == ' ')
606 name[len] = '\0';
608 if (InterlockedCompareExchangePointer((void**)&_this->name, name, NULL))
610 /* Another thread set this member since we checked above - use it */
611 free(name);
615 TRACE("(%p) returning %s\n", _this, _this->name);
616 return _this->name;
619 /******************************************************************
620 * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
622 DEFINE_THISCALL_WRAPPER(type_info_raw_name,4)
623 const char * __thiscall type_info_raw_name(type_info * _this)
625 TRACE("(%p) returning %s\n", _this, _this->mangled);
626 return _this->mangled;
629 /* Unexported */
630 DEFINE_THISCALL_WRAPPER(type_info_vector_dtor,8)
631 void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags)
633 TRACE("(%p %x)\n", _this, flags);
634 if (flags & 2)
636 /* we have an array, with the number of elements stored before the first object */
637 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
639 for (i = *ptr - 1; i >= 0; i--) type_info_dtor(_this + i);
640 operator_delete(ptr);
642 else
644 type_info_dtor(_this);
645 if (flags & 1) operator_delete(_this);
647 return _this;
650 #if _MSVCR_VER >= 80
652 typedef exception bad_alloc;
653 extern const vtable_ptr bad_alloc_vtable;
655 static void bad_alloc_ctor(bad_alloc *this, const char **name)
657 exception_ctor(this, name);
658 this->vtable = &bad_alloc_vtable;
661 /* bad_alloc class implementation */
662 DEFINE_THISCALL_WRAPPER(bad_alloc_copy_ctor,8)
663 bad_alloc * __thiscall bad_alloc_copy_ctor(bad_alloc * _this, const bad_alloc * rhs)
665 TRACE("(%p %p)\n", _this, rhs);
666 exception_copy_ctor(_this, rhs);
667 _this->vtable = &bad_alloc_vtable;
668 return _this;
671 DEFINE_THISCALL_WRAPPER(bad_alloc_dtor,4)
672 void __thiscall bad_alloc_dtor(bad_alloc * _this)
674 TRACE("(%p)\n", _this);
675 exception_dtor(_this);
678 #endif /* _MSVCR_VER >= 80 */
680 #if _MSVCR_VER >= 100
682 typedef struct {
683 exception e;
684 HRESULT hr;
685 } scheduler_resource_allocation_error;
686 extern const vtable_ptr scheduler_resource_allocation_error_vtable;
688 /* ??0scheduler_resource_allocation_error@Concurrency@@QAE@PBDJ@Z */
689 /* ??0scheduler_resource_allocation_error@Concurrency@@QEAA@PEBDJ@Z */
690 DEFINE_THISCALL_WRAPPER(scheduler_resource_allocation_error_ctor_name, 12)
691 scheduler_resource_allocation_error* __thiscall scheduler_resource_allocation_error_ctor_name(
692 scheduler_resource_allocation_error *this, const char *name, HRESULT hr)
694 TRACE("(%p %s %x)\n", this, wine_dbgstr_a(name), hr);
695 exception_ctor(&this->e, &name);
696 this->e.vtable = &scheduler_resource_allocation_error_vtable;
697 this->hr = hr;
698 return this;
701 /* ??0scheduler_resource_allocation_error@Concurrency@@QAE@J@Z */
702 /* ??0scheduler_resource_allocation_error@Concurrency@@QEAA@J@Z */
703 DEFINE_THISCALL_WRAPPER(scheduler_resource_allocation_error_ctor, 8)
704 scheduler_resource_allocation_error* __thiscall scheduler_resource_allocation_error_ctor(
705 scheduler_resource_allocation_error *this, HRESULT hr)
707 return scheduler_resource_allocation_error_ctor_name(this, NULL, hr);
710 DEFINE_THISCALL_WRAPPER(scheduler_resource_allocation_error_copy_ctor,8)
711 scheduler_resource_allocation_error* __thiscall scheduler_resource_allocation_error_copy_ctor(
712 scheduler_resource_allocation_error *this,
713 const scheduler_resource_allocation_error *rhs)
715 TRACE("(%p,%p)\n", this, rhs);
717 if (!rhs->e.do_free)
718 memcpy(this, rhs, sizeof(*this));
719 else
720 scheduler_resource_allocation_error_ctor_name(this, rhs->e.name, rhs->hr);
721 return this;
724 /* ?get_error_code@scheduler_resource_allocation_error@Concurrency@@QBEJXZ */
725 /* ?get_error_code@scheduler_resource_allocation_error@Concurrency@@QEBAJXZ */
726 DEFINE_THISCALL_WRAPPER(scheduler_resource_allocation_error_get_error_code, 4)
727 HRESULT __thiscall scheduler_resource_allocation_error_get_error_code(
728 const scheduler_resource_allocation_error *this)
730 TRACE("(%p)\n", this);
731 return this->hr;
734 DEFINE_THISCALL_WRAPPER(scheduler_resource_allocation_error_dtor,4)
735 void __thiscall scheduler_resource_allocation_error_dtor(
736 scheduler_resource_allocation_error * this)
738 TRACE("(%p)\n", this);
739 exception_dtor(&this->e);
742 typedef exception improper_lock;
743 extern const vtable_ptr improper_lock_vtable;
745 /* ??0improper_lock@Concurrency@@QAE@PBD@Z */
746 /* ??0improper_lock@Concurrency@@QEAA@PEBD@Z */
747 DEFINE_THISCALL_WRAPPER(improper_lock_ctor_str, 8)
748 improper_lock* __thiscall improper_lock_ctor_str(improper_lock *this, const char *str)
750 TRACE("(%p %p)\n", this, str);
751 exception_ctor(this, &str);
752 this->vtable = &improper_lock_vtable;
753 return this;
756 /* ??0improper_lock@Concurrency@@QAE@XZ */
757 /* ??0improper_lock@Concurrency@@QEAA@XZ */
758 DEFINE_THISCALL_WRAPPER(improper_lock_ctor, 4)
759 improper_lock* __thiscall improper_lock_ctor(improper_lock *this)
761 return improper_lock_ctor_str(this, NULL);
764 DEFINE_THISCALL_WRAPPER(improper_lock_copy_ctor,8)
765 improper_lock * __thiscall improper_lock_copy_ctor(improper_lock * _this, const improper_lock * rhs)
767 TRACE("(%p %p)\n", _this, rhs);
768 exception_copy_ctor(_this, rhs);
769 _this->vtable = &improper_lock_vtable;
770 return _this;
773 DEFINE_THISCALL_WRAPPER(improper_lock_dtor,4)
774 void __thiscall improper_lock_dtor(improper_lock * _this)
776 TRACE("(%p)\n", _this);
777 exception_dtor(_this);
780 typedef exception invalid_scheduler_policy_key;
781 extern const vtable_ptr invalid_scheduler_policy_key_vtable;
783 /* ??0invalid_scheduler_policy_key@Concurrency@@QAE@PBD@Z */
784 /* ??0invalid_scheduler_policy_key@Concurrency@@QEAA@PEBD@Z */
785 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_key_ctor_str, 8)
786 invalid_scheduler_policy_key* __thiscall invalid_scheduler_policy_key_ctor_str(
787 invalid_scheduler_policy_key *this, const char *str)
789 TRACE("(%p %p)\n", this, str);
790 exception_ctor(this, &str);
791 this->vtable = &invalid_scheduler_policy_key_vtable;
792 return this;
795 /* ??0invalid_scheduler_policy_key@Concurrency@@QAE@XZ */
796 /* ??0invalid_scheduler_policy_key@Concurrency@@QEAA@XZ */
797 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_key_ctor, 4)
798 invalid_scheduler_policy_key* __thiscall invalid_scheduler_policy_key_ctor(
799 invalid_scheduler_policy_key *this)
801 return invalid_scheduler_policy_key_ctor_str(this, NULL);
804 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_key_copy_ctor,8)
805 invalid_scheduler_policy_key * __thiscall invalid_scheduler_policy_key_copy_ctor(
806 invalid_scheduler_policy_key * _this, const invalid_scheduler_policy_key * rhs)
808 TRACE("(%p %p)\n", _this, rhs);
809 exception_copy_ctor(_this, rhs);
810 _this->vtable = &invalid_scheduler_policy_key_vtable;
811 return _this;
814 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_key_dtor,4)
815 void __thiscall invalid_scheduler_policy_key_dtor(
816 invalid_scheduler_policy_key * _this)
818 TRACE("(%p)\n", _this);
819 exception_dtor(_this);
822 typedef exception invalid_scheduler_policy_value;
823 extern const vtable_ptr invalid_scheduler_policy_value_vtable;
825 /* ??0invalid_scheduler_policy_value@Concurrency@@QAE@PBD@Z */
826 /* ??0invalid_scheduler_policy_value@Concurrency@@QEAA@PEBD@Z */
827 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_value_ctor_str, 8)
828 invalid_scheduler_policy_value* __thiscall invalid_scheduler_policy_value_ctor_str(
829 invalid_scheduler_policy_value *this, const char *str)
831 TRACE("(%p %p)\n", this, str);
832 exception_ctor(this, &str);
833 this->vtable = &invalid_scheduler_policy_value_vtable;
834 return this;
837 /* ??0invalid_scheduler_policy_value@Concurrency@@QAE@XZ */
838 /* ??0invalid_scheduler_policy_value@Concurrency@@QEAA@XZ */
839 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_value_ctor, 4)
840 invalid_scheduler_policy_value* __thiscall invalid_scheduler_policy_value_ctor(
841 invalid_scheduler_policy_value *this)
843 return invalid_scheduler_policy_value_ctor_str(this, NULL);
846 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_value_copy_ctor,8)
847 invalid_scheduler_policy_value * __thiscall invalid_scheduler_policy_value_copy_ctor(
848 invalid_scheduler_policy_value * _this, const invalid_scheduler_policy_value * rhs)
850 TRACE("(%p %p)\n", _this, rhs);
851 exception_copy_ctor(_this, rhs);
852 _this->vtable = &invalid_scheduler_policy_value_vtable;
853 return _this;
856 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_value_dtor,4)
857 void __thiscall invalid_scheduler_policy_value_dtor(
858 invalid_scheduler_policy_value * _this)
860 TRACE("(%p)\n", _this);
861 exception_dtor(_this);
864 typedef exception invalid_scheduler_policy_thread_specification;
865 extern const vtable_ptr invalid_scheduler_policy_thread_specification_vtable;
867 /* ??0invalid_scheduler_policy_thread_specification@Concurrency@@QAE@PBD@Z */
868 /* ??0invalid_scheduler_policy_thread_specification@Concurrency@@QEAA@PEBD@Z */
869 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_thread_specification_ctor_str, 8)
870 invalid_scheduler_policy_thread_specification* __thiscall invalid_scheduler_policy_thread_specification_ctor_str(
871 invalid_scheduler_policy_thread_specification *this, const char *str)
873 TRACE("(%p %p)\n", this, str);
874 exception_ctor(this, &str);
875 this->vtable = &invalid_scheduler_policy_thread_specification_vtable;
876 return this;
879 /* ??0invalid_scheduler_policy_thread_specification@Concurrency@@QAE@XZ */
880 /* ??0invalid_scheduler_policy_thread_specification@Concurrency@@QEAA@XZ */
881 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_thread_specification_ctor, 4)
882 invalid_scheduler_policy_thread_specification* __thiscall invalid_scheduler_policy_thread_specification_ctor(
883 invalid_scheduler_policy_thread_specification *this)
885 return invalid_scheduler_policy_thread_specification_ctor_str(this, NULL);
888 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_thread_specification_copy_ctor,8)
889 invalid_scheduler_policy_thread_specification * __thiscall invalid_scheduler_policy_thread_specification_copy_ctor(
890 invalid_scheduler_policy_thread_specification * _this, const invalid_scheduler_policy_thread_specification * rhs)
892 TRACE("(%p %p)\n", _this, rhs);
893 exception_copy_ctor(_this, rhs);
894 _this->vtable = &invalid_scheduler_policy_thread_specification_vtable;
895 return _this;
898 DEFINE_THISCALL_WRAPPER(invalid_scheduler_policy_thread_specification_dtor,4)
899 void __thiscall invalid_scheduler_policy_thread_specification_dtor(
900 invalid_scheduler_policy_thread_specification * _this)
902 TRACE("(%p)\n", _this);
903 exception_dtor(_this);
906 typedef exception improper_scheduler_attach;
907 extern const vtable_ptr improper_scheduler_attach_vtable;
909 /* ??0improper_scheduler_attach@Concurrency@@QAE@PBD@Z */
910 /* ??0improper_scheduler_attach@Concurrency@@QEAA@PEBD@Z */
911 DEFINE_THISCALL_WRAPPER(improper_scheduler_attach_ctor_str, 8)
912 improper_scheduler_attach* __thiscall improper_scheduler_attach_ctor_str(
913 improper_scheduler_attach *this, const char *str)
915 TRACE("(%p %p)\n", this, str);
916 exception_ctor(this, &str);
917 this->vtable = &improper_scheduler_attach_vtable;
918 return this;
921 /* ??0improper_scheduler_attach@Concurrency@@QAE@XZ */
922 /* ??0improper_scheduler_attach@Concurrency@@QEAA@XZ */
923 DEFINE_THISCALL_WRAPPER(improper_scheduler_attach_ctor, 4)
924 improper_scheduler_attach* __thiscall improper_scheduler_attach_ctor(
925 improper_scheduler_attach *this)
927 return improper_scheduler_attach_ctor_str(this, NULL);
930 DEFINE_THISCALL_WRAPPER(improper_scheduler_attach_copy_ctor,8)
931 improper_scheduler_attach * __thiscall improper_scheduler_attach_copy_ctor(
932 improper_scheduler_attach * _this, const improper_scheduler_attach * rhs)
934 TRACE("(%p %p)\n", _this, rhs);
935 exception_copy_ctor(_this, rhs);
936 _this->vtable = &improper_scheduler_attach_vtable;
937 return _this;
940 DEFINE_THISCALL_WRAPPER(improper_scheduler_attach_dtor,4)
941 void __thiscall improper_scheduler_attach_dtor(
942 improper_scheduler_attach * _this)
944 TRACE("(%p)\n", _this);
945 exception_dtor(_this);
948 typedef exception improper_scheduler_detach;
949 extern const vtable_ptr improper_scheduler_detach_vtable;
951 /* ??0improper_scheduler_detach@Concurrency@@QAE@PBD@Z */
952 /* ??0improper_scheduler_detach@Concurrency@@QEAA@PEBD@Z */
953 DEFINE_THISCALL_WRAPPER(improper_scheduler_detach_ctor_str, 8)
954 improper_scheduler_detach* __thiscall improper_scheduler_detach_ctor_str(
955 improper_scheduler_detach *this, const char *str)
957 TRACE("(%p %p)\n", this, str);
958 exception_ctor(this, &str);
959 this->vtable = &improper_scheduler_detach_vtable;
960 return this;
963 /* ??0improper_scheduler_detach@Concurrency@@QAE@XZ */
964 /* ??0improper_scheduler_detach@Concurrency@@QEAA@XZ */
965 DEFINE_THISCALL_WRAPPER(improper_scheduler_detach_ctor, 4)
966 improper_scheduler_detach* __thiscall improper_scheduler_detach_ctor(
967 improper_scheduler_detach *this)
969 return improper_scheduler_detach_ctor_str(this, NULL);
972 DEFINE_THISCALL_WRAPPER(improper_scheduler_detach_copy_ctor,8)
973 improper_scheduler_detach * __thiscall improper_scheduler_detach_copy_ctor(
974 improper_scheduler_detach * _this, const improper_scheduler_detach * rhs)
976 TRACE("(%p %p)\n", _this, rhs);
977 exception_copy_ctor(_this, rhs);
978 _this->vtable = &improper_scheduler_detach_vtable;
979 return _this;
982 DEFINE_THISCALL_WRAPPER(improper_scheduler_detach_dtor,4)
983 void __thiscall improper_scheduler_detach_dtor(
984 improper_scheduler_detach * _this)
986 TRACE("(%p)\n", _this);
987 exception_dtor(_this);
990 #endif /* _MSVCR_VER >= 100 */
992 __ASM_BLOCK_BEGIN(vtables)
994 __ASM_VTABLE(type_info,
995 VTABLE_ADD_FUNC(type_info_vector_dtor));
996 __ASM_VTABLE(exception,
997 VTABLE_ADD_FUNC(exception_vector_dtor)
998 VTABLE_ADD_FUNC(what_exception));
999 #if _MSVCR_VER >= 80
1000 __ASM_VTABLE(exception_old,
1001 VTABLE_ADD_FUNC(exception_vector_dtor)
1002 VTABLE_ADD_FUNC(what_exception));
1003 __ASM_VTABLE(bad_alloc,
1004 VTABLE_ADD_FUNC(exception_vector_dtor)
1005 VTABLE_ADD_FUNC(what_exception));
1006 #endif
1007 __ASM_VTABLE(bad_typeid,
1008 VTABLE_ADD_FUNC(bad_typeid_vector_dtor)
1009 VTABLE_ADD_FUNC(what_exception));
1010 __ASM_VTABLE(bad_cast,
1011 VTABLE_ADD_FUNC(bad_cast_vector_dtor)
1012 VTABLE_ADD_FUNC(what_exception));
1013 __ASM_VTABLE(__non_rtti_object,
1014 VTABLE_ADD_FUNC(__non_rtti_object_vector_dtor)
1015 VTABLE_ADD_FUNC(what_exception));
1016 #if _MSVCR_VER >= 100
1017 __ASM_VTABLE(scheduler_resource_allocation_error,
1018 VTABLE_ADD_FUNC(exception_vector_dtor)
1019 VTABLE_ADD_FUNC(what_exception));
1020 __ASM_VTABLE(improper_lock,
1021 VTABLE_ADD_FUNC(exception_vector_dtor)
1022 VTABLE_ADD_FUNC(what_exception));
1023 __ASM_VTABLE(invalid_scheduler_policy_key,
1024 VTABLE_ADD_FUNC(exception_vector_dtor)
1025 VTABLE_ADD_FUNC(what_exception));
1026 __ASM_VTABLE(invalid_scheduler_policy_value,
1027 VTABLE_ADD_FUNC(exception_vector_dtor)
1028 VTABLE_ADD_FUNC(what_exception));
1029 __ASM_VTABLE(invalid_scheduler_policy_thread_specification,
1030 VTABLE_ADD_FUNC(exception_vector_dtor)
1031 VTABLE_ADD_FUNC(what_exception));
1032 __ASM_VTABLE(improper_scheduler_attach,
1033 VTABLE_ADD_FUNC(exception_vector_dtor)
1034 VTABLE_ADD_FUNC(what_exception));
1035 __ASM_VTABLE(improper_scheduler_detach,
1036 VTABLE_ADD_FUNC(exception_vector_dtor)
1037 VTABLE_ADD_FUNC(what_exception));
1038 #endif
1040 __ASM_BLOCK_END
1042 DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" )
1043 #if _MSVCR_VER >= 80
1044 DEFINE_RTTI_DATA0( exception, 0, ".?AVexception@std@@" )
1045 DEFINE_RTTI_DATA0( exception_old, 0, ".?AVexception@@" )
1046 DEFINE_RTTI_DATA1( bad_typeid, 0, &exception_rtti_base_descriptor, ".?AVbad_typeid@std@@" )
1047 DEFINE_RTTI_DATA1( bad_cast, 0, &exception_rtti_base_descriptor, ".?AVbad_cast@std@@" )
1048 DEFINE_RTTI_DATA2( __non_rtti_object, 0, &bad_typeid_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AV__non_rtti_object@std@@" )
1049 DEFINE_RTTI_DATA1( bad_alloc, 0, &exception_rtti_base_descriptor, ".?AVbad_alloc@std@@" )
1050 #else
1051 DEFINE_RTTI_DATA0( exception, 0, ".?AVexception@@" )
1052 DEFINE_RTTI_DATA1( bad_typeid, 0, &exception_rtti_base_descriptor, ".?AVbad_typeid@@" )
1053 DEFINE_RTTI_DATA1( bad_cast, 0, &exception_rtti_base_descriptor, ".?AVbad_cast@@" )
1054 DEFINE_RTTI_DATA2( __non_rtti_object, 0, &bad_typeid_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AV__non_rtti_object@@" )
1055 #endif
1056 #if _MSVCR_VER >= 100
1057 DEFINE_RTTI_DATA1(scheduler_resource_allocation_error, 0, &exception_rtti_base_descriptor,
1058 ".?AVscheduler_resource_allocation_error@Concurrency@@")
1059 DEFINE_RTTI_DATA1(improper_lock, 0, &exception_rtti_base_descriptor, ".?AVimproper_lock@Concurrency@@" )
1060 DEFINE_RTTI_DATA1(invalid_scheduler_policy_key, 0, &exception_rtti_base_descriptor,
1061 ".?AVinvalid_scheduler_policy_key@Concurrency@@" )
1062 DEFINE_RTTI_DATA1(invalid_scheduler_policy_value, 0, &exception_rtti_base_descriptor,
1063 ".?AVinvalid_scheduler_policy_value@Concurrency@@" )
1064 DEFINE_RTTI_DATA1(invalid_scheduler_policy_thread_specification, 0, &exception_rtti_base_descriptor,
1065 ".?AVinvalid_scheduler_policy_thread_specification@Concurrency@@" )
1066 DEFINE_RTTI_DATA1(improper_scheduler_attach, 0, &exception_rtti_base_descriptor,
1067 ".?AVimproper_scheduler_attach@Concurrency@@" )
1068 DEFINE_RTTI_DATA1(improper_scheduler_detach, 0, &exception_rtti_base_descriptor,
1069 ".?AVimproper_scheduler_detach@Concurrency@@" )
1070 #endif
1072 DEFINE_EXCEPTION_TYPE_INFO( exception, 0, NULL, NULL )
1073 DEFINE_EXCEPTION_TYPE_INFO( bad_typeid, 1, &exception_cxx_type_info, NULL )
1074 DEFINE_EXCEPTION_TYPE_INFO( bad_cast, 1, &exception_cxx_type_info, NULL )
1075 DEFINE_EXCEPTION_TYPE_INFO( __non_rtti_object, 2, &bad_typeid_cxx_type_info, &exception_cxx_type_info )
1076 #if _MSVCR_VER >= 80
1077 DEFINE_EXCEPTION_TYPE_INFO( bad_alloc, 1, &exception_cxx_type_info, NULL )
1078 #endif
1079 #if _MSVCR_VER >= 100
1080 DEFINE_EXCEPTION_TYPE_INFO(scheduler_resource_allocation_error, 1, &exception_cxx_type_info, NULL)
1081 DEFINE_EXCEPTION_TYPE_INFO(improper_lock, 1, &exception_cxx_type_info, NULL)
1082 DEFINE_EXCEPTION_TYPE_INFO(invalid_scheduler_policy_key, 1, &exception_cxx_type_info, NULL)
1083 DEFINE_EXCEPTION_TYPE_INFO(invalid_scheduler_policy_value, 1, &exception_cxx_type_info, NULL)
1084 DEFINE_EXCEPTION_TYPE_INFO(invalid_scheduler_policy_thread_specification, 1, &exception_cxx_type_info, NULL)
1085 DEFINE_EXCEPTION_TYPE_INFO(improper_scheduler_attach, 1, &exception_cxx_type_info, NULL)
1086 DEFINE_EXCEPTION_TYPE_INFO(improper_scheduler_detach, 1, &exception_cxx_type_info, NULL)
1087 #endif
1089 void msvcrt_init_exception(void *base)
1091 #ifdef __x86_64__
1092 init_type_info_rtti(base);
1093 init_exception_rtti(base);
1094 #if _MSVCR_VER >= 80
1095 init_exception_old_rtti(base);
1096 init_bad_alloc_rtti(base);
1097 #endif
1098 init_bad_typeid_rtti(base);
1099 init_bad_cast_rtti(base);
1100 init___non_rtti_object_rtti(base);
1101 #if _MSVCR_VER >= 100
1102 init_scheduler_resource_allocation_error_rtti(base);
1103 init_improper_lock_rtti(base);
1104 init_invalid_scheduler_policy_key_rtti(base);
1105 init_invalid_scheduler_policy_value_rtti(base);
1106 init_invalid_scheduler_policy_thread_specification_rtti(base);
1107 init_improper_scheduler_attach_rtti(base);
1108 init_improper_scheduler_detach_rtti(base);
1109 #endif
1111 init_exception_cxx(base);
1112 init_bad_typeid_cxx(base);
1113 init_bad_cast_cxx(base);
1114 init___non_rtti_object_cxx(base);
1115 #if _MSVCR_VER >= 80
1116 init_bad_alloc_cxx(base);
1117 #endif
1118 #if _MSVCR_VER >= 100
1119 init_scheduler_resource_allocation_error_cxx(base);
1120 init_improper_lock_cxx(base);
1121 init_invalid_scheduler_policy_key_cxx(base);
1122 init_invalid_scheduler_policy_value_cxx(base);
1123 init_invalid_scheduler_policy_thread_specification_cxx(base);
1124 init_improper_scheduler_attach_cxx(base);
1125 init_improper_scheduler_detach_cxx(base);
1126 #endif
1127 #endif
1130 #if _MSVCR_VER >= 80
1131 void throw_exception(exception_type et, HRESULT hr, const char *str)
1133 switch(et) {
1134 case EXCEPTION_BAD_ALLOC: {
1135 bad_alloc e;
1136 bad_alloc_ctor(&e, &str);
1137 _CxxThrowException(&e, &bad_alloc_exception_type);
1139 #if _MSVCR_VER >= 100
1140 case EXCEPTION_SCHEDULER_RESOURCE_ALLOCATION_ERROR: {
1141 scheduler_resource_allocation_error e;
1142 scheduler_resource_allocation_error_ctor_name(&e, str, hr);
1143 _CxxThrowException(&e.e, &scheduler_resource_allocation_error_exception_type);
1145 case EXCEPTION_IMPROPER_LOCK: {
1146 improper_lock e;
1147 improper_lock_ctor_str(&e, str);
1148 _CxxThrowException(&e, &improper_lock_exception_type);
1150 case EXCEPTION_INVALID_SCHEDULER_POLICY_KEY: {
1151 invalid_scheduler_policy_key e;
1152 invalid_scheduler_policy_key_ctor_str(&e, str);
1153 _CxxThrowException(&e, &invalid_scheduler_policy_key_exception_type);
1155 case EXCEPTION_INVALID_SCHEDULER_POLICY_VALUE: {
1156 invalid_scheduler_policy_value e;
1157 invalid_scheduler_policy_value_ctor_str(&e, str);
1158 _CxxThrowException(&e, &invalid_scheduler_policy_value_exception_type);
1160 case EXCEPTION_INVALID_SCHEDULER_POLICY_THREAD_SPECIFICATION: {
1161 invalid_scheduler_policy_thread_specification e;
1162 invalid_scheduler_policy_thread_specification_ctor_str(&e, str);
1163 _CxxThrowException(&e, &invalid_scheduler_policy_thread_specification_exception_type);
1165 case EXCEPTION_IMPROPER_SCHEDULER_ATTACH: {
1166 improper_scheduler_attach e;
1167 improper_scheduler_attach_ctor_str(&e, str);
1168 _CxxThrowException(&e, &improper_scheduler_attach_exception_type);
1170 case EXCEPTION_IMPROPER_SCHEDULER_DETACH: {
1171 improper_scheduler_detach e;
1172 improper_scheduler_detach_ctor_str(&e, str);
1173 _CxxThrowException(&e, &improper_scheduler_detach_exception_type);
1175 #endif
1178 #endif
1180 /******************************************************************
1181 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
1183 * Install a handler to be called when terminate() is called.
1185 * PARAMS
1186 * func [I] Handler function to install
1188 * RETURNS
1189 * The previously installed handler function, if any.
1191 terminate_function CDECL set_terminate(terminate_function func)
1193 thread_data_t *data = msvcrt_get_thread_data();
1194 terminate_function previous = data->terminate_handler;
1195 TRACE("(%p) returning %p\n",func,previous);
1196 data->terminate_handler = func;
1197 return previous;
1200 /******************************************************************
1201 * _get_terminate (MSVCRT.@)
1203 terminate_function CDECL _get_terminate(void)
1205 thread_data_t *data = msvcrt_get_thread_data();
1206 TRACE("returning %p\n", data->terminate_handler);
1207 return data->terminate_handler;
1210 /******************************************************************
1211 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
1213 * Install a handler to be called when unexpected() is called.
1215 * PARAMS
1216 * func [I] Handler function to install
1218 * RETURNS
1219 * The previously installed handler function, if any.
1221 unexpected_function CDECL set_unexpected(unexpected_function func)
1223 thread_data_t *data = msvcrt_get_thread_data();
1224 unexpected_function previous = data->unexpected_handler;
1225 TRACE("(%p) returning %p\n",func,previous);
1226 data->unexpected_handler = func;
1227 return previous;
1230 /******************************************************************
1231 * _get_unexpected (MSVCRT.@)
1233 unexpected_function CDECL _get_unexpected(void)
1235 thread_data_t *data = msvcrt_get_thread_data();
1236 TRACE("returning %p\n", data->unexpected_handler);
1237 return data->unexpected_handler;
1240 /******************************************************************
1241 * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@)
1243 _se_translator_function CDECL _set_se_translator(_se_translator_function func)
1245 thread_data_t *data = msvcrt_get_thread_data();
1246 _se_translator_function previous = data->se_translator;
1247 TRACE("(%p) returning %p\n",func,previous);
1248 data->se_translator = func;
1249 return previous;
1252 /******************************************************************
1253 * ?terminate@@YAXXZ (MSVCRT.@)
1255 * Default handler for an unhandled exception.
1257 * PARAMS
1258 * None.
1260 * RETURNS
1261 * This function does not return. Either control resumes from any
1262 * handler installed by calling set_terminate(), or (by default) abort()
1263 * is called.
1265 void CDECL terminate(void)
1267 thread_data_t *data = msvcrt_get_thread_data();
1268 if (data->terminate_handler) data->terminate_handler();
1269 abort();
1272 /******************************************************************
1273 * ?unexpected@@YAXXZ (MSVCRT.@)
1275 void CDECL unexpected(void)
1277 thread_data_t *data = msvcrt_get_thread_data();
1278 if (data->unexpected_handler) data->unexpected_handler();
1279 terminate();
1283 /******************************************************************
1284 * __RTtypeid (MSVCRT.@)
1286 * Retrieve the Run Time Type Information (RTTI) for a C++ object.
1288 * PARAMS
1289 * cppobj [I] C++ object to get type information for.
1291 * RETURNS
1292 * Success: A type_info object describing cppobj.
1293 * Failure: If the object to be cast has no RTTI, a __non_rtti_object
1294 * exception is thrown. If cppobj is NULL, a bad_typeid exception
1295 * is thrown. In either case, this function does not return.
1297 * NOTES
1298 * This function is usually called by compiler generated code as a result
1299 * of using one of the C++ dynamic cast statements.
1301 #ifndef __x86_64__
1302 const type_info* CDECL __RTtypeid(void *cppobj)
1304 const type_info *ret;
1306 if (!cppobj)
1308 bad_typeid e;
1309 bad_typeid_ctor( &e, "Attempted a typeid of NULL pointer!" );
1310 _CxxThrowException( &e, &bad_typeid_exception_type );
1311 return NULL;
1314 __TRY
1316 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1317 ret = obj_locator->type_descriptor;
1319 __EXCEPT_PAGE_FAULT
1321 __non_rtti_object e;
1322 __non_rtti_object_ctor( &e, "Bad read pointer - no RTTI data!" );
1323 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1324 return NULL;
1326 __ENDTRY
1327 return ret;
1330 #else
1332 const type_info* CDECL __RTtypeid(void *cppobj)
1334 const type_info *ret;
1336 if (!cppobj)
1338 bad_typeid e;
1339 bad_typeid_ctor( &e, "Attempted a typeid of NULL pointer!" );
1340 _CxxThrowException( &e, &bad_typeid_exception_type );
1341 return NULL;
1344 __TRY
1346 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1347 char *base;
1349 if(obj_locator->signature == 0)
1350 base = RtlPcToFileHeader((void*)obj_locator, (void**)&base);
1351 else
1352 base = (char*)obj_locator - obj_locator->object_locator;
1354 ret = (type_info*)(base + obj_locator->type_descriptor);
1356 __EXCEPT_PAGE_FAULT
1358 __non_rtti_object e;
1359 __non_rtti_object_ctor( &e, "Bad read pointer - no RTTI data!" );
1360 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1361 return NULL;
1363 __ENDTRY
1364 return ret;
1366 #endif
1368 /******************************************************************
1369 * __RTDynamicCast (MSVCRT.@)
1371 * Dynamically cast a C++ object to one of its base classes.
1373 * PARAMS
1374 * cppobj [I] Any C++ object to cast
1375 * unknown [I] Reserved, set to 0
1376 * src [I] type_info object describing cppobj
1377 * dst [I] type_info object describing the base class to cast to
1378 * do_throw [I] TRUE = throw an exception if the cast fails, FALSE = don't
1380 * RETURNS
1381 * Success: The address of cppobj, cast to the object described by dst.
1382 * Failure: NULL, If the object to be cast has no RTTI, or dst is not a
1383 * valid cast for cppobj. If do_throw is TRUE, a bad_cast exception
1384 * is thrown and this function does not return.
1386 * NOTES
1387 * This function is usually called by compiler generated code as a result
1388 * of using one of the C++ dynamic cast statements.
1390 #ifndef __x86_64__
1391 void* CDECL __RTDynamicCast(void *cppobj, int unknown,
1392 type_info *src, type_info *dst,
1393 int do_throw)
1395 void *ret;
1397 if (!cppobj) return NULL;
1399 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1400 cppobj, unknown, src, dbgstr_type_info(src), dst, dbgstr_type_info(dst), do_throw);
1402 /* To cast an object at runtime:
1403 * 1.Find out the true type of the object from the typeinfo at vtable[-1]
1404 * 2.Search for the destination type in the class hierarchy
1405 * 3.If destination type is found, return base object address + dest offset
1406 * Otherwise, fail the cast
1408 * FIXME: the unknown parameter doesn't seem to be used for anything
1410 __TRY
1412 int i;
1413 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1414 const rtti_object_hierarchy *obj_bases = obj_locator->type_hierarchy;
1415 const rtti_base_descriptor * const* base_desc = obj_bases->base_classes->bases;
1417 if (TRACE_ON(msvcrt)) dump_obj_locator(obj_locator);
1419 ret = NULL;
1420 for (i = 0; i < obj_bases->array_len; i++)
1422 const type_info *typ = base_desc[i]->type_descriptor;
1424 if (!strcmp(typ->mangled, dst->mangled))
1426 /* compute the correct this pointer for that base class */
1427 void *this_ptr = (char *)cppobj - obj_locator->base_class_offset;
1428 ret = get_this_pointer( &base_desc[i]->offsets, this_ptr );
1429 break;
1432 /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned
1433 * to a reference, since references cannot be NULL.
1435 if (!ret && do_throw)
1437 const char *msg = "Bad dynamic_cast!";
1438 bad_cast e;
1439 bad_cast_ctor( &e, &msg );
1440 _CxxThrowException( &e, &bad_cast_exception_type );
1443 __EXCEPT_PAGE_FAULT
1445 __non_rtti_object e;
1446 __non_rtti_object_ctor( &e, "Access violation - no RTTI data!" );
1447 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1448 return NULL;
1450 __ENDTRY
1451 return ret;
1454 #else
1456 void* CDECL __RTDynamicCast(void *cppobj, int unknown,
1457 type_info *src, type_info *dst,
1458 int do_throw)
1460 void *ret;
1462 if (!cppobj) return NULL;
1464 TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n",
1465 cppobj, unknown, src, dbgstr_type_info(src), dst, dbgstr_type_info(dst), do_throw);
1467 __TRY
1469 int i;
1470 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1471 const rtti_object_hierarchy *obj_bases;
1472 const rtti_base_array *base_array;
1473 char *base;
1475 if (TRACE_ON(msvcrt)) dump_obj_locator(obj_locator);
1477 if(obj_locator->signature == 0)
1478 base = RtlPcToFileHeader((void*)obj_locator, (void**)&base);
1479 else
1480 base = (char*)obj_locator - obj_locator->object_locator;
1482 obj_bases = (const rtti_object_hierarchy*)(base + obj_locator->type_hierarchy);
1483 base_array = (const rtti_base_array*)(base + obj_bases->base_classes);
1485 ret = NULL;
1486 for (i = 0; i < obj_bases->array_len; i++)
1488 const rtti_base_descriptor *base_desc = (const rtti_base_descriptor*)(base + base_array->bases[i]);
1489 const type_info *typ = (const type_info*)(base + base_desc->type_descriptor);
1491 if (!strcmp(typ->mangled, dst->mangled))
1493 void *this_ptr = (char *)cppobj - obj_locator->base_class_offset;
1494 ret = get_this_pointer( &base_desc->offsets, this_ptr );
1495 break;
1498 if (!ret && do_throw)
1500 const char *msg = "Bad dynamic_cast!";
1501 bad_cast e;
1502 bad_cast_ctor( &e, &msg );
1503 _CxxThrowException( &e, &bad_cast_exception_type );
1506 __EXCEPT_PAGE_FAULT
1508 __non_rtti_object e;
1509 __non_rtti_object_ctor( &e, "Access violation - no RTTI data!" );
1510 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1511 return NULL;
1513 __ENDTRY
1514 return ret;
1516 #endif
1519 /******************************************************************
1520 * __RTCastToVoid (MSVCRT.@)
1522 * Dynamically cast a C++ object to a void*.
1524 * PARAMS
1525 * cppobj [I] The C++ object to cast
1527 * RETURNS
1528 * Success: The base address of the object as a void*.
1529 * Failure: NULL, if cppobj is NULL or has no RTTI.
1531 * NOTES
1532 * This function is usually called by compiler generated code as a result
1533 * of using one of the C++ dynamic cast statements.
1535 void* CDECL __RTCastToVoid(void *cppobj)
1537 void *ret;
1539 if (!cppobj) return NULL;
1541 __TRY
1543 const rtti_object_locator *obj_locator = get_obj_locator( cppobj );
1544 ret = (char *)cppobj - obj_locator->base_class_offset;
1546 __EXCEPT_PAGE_FAULT
1548 __non_rtti_object e;
1549 __non_rtti_object_ctor( &e, "Access violation - no RTTI data!" );
1550 _CxxThrowException( &e, &__non_rtti_object_exception_type );
1551 return NULL;
1553 __ENDTRY
1554 return ret;
1558 /*********************************************************************
1559 * _CxxThrowException (MSVCRT.@)
1561 #ifndef __x86_64__
1562 void WINAPI _CxxThrowException( exception *object, const cxx_exception_type *type )
1564 ULONG_PTR args[3];
1566 args[0] = CXX_FRAME_MAGIC_VC6;
1567 args[1] = (ULONG_PTR)object;
1568 args[2] = (ULONG_PTR)type;
1569 RaiseException( CXX_EXCEPTION, EH_NONCONTINUABLE, 3, args );
1571 #else
1572 void WINAPI _CxxThrowException( exception *object, const cxx_exception_type *type )
1574 ULONG_PTR args[4];
1576 args[0] = CXX_FRAME_MAGIC_VC6;
1577 args[1] = (ULONG_PTR)object;
1578 args[2] = (ULONG_PTR)type;
1579 RtlPcToFileHeader( (void*)type, (void**)&args[3]);
1580 RaiseException( CXX_EXCEPTION, EH_NONCONTINUABLE, 4, args );
1582 #endif
1584 #if _MSVCR_VER >= 80
1586 /*********************************************************************
1587 * ?_is_exception_typeof@@YAHABVtype_info@@PAU_EXCEPTION_POINTERS@@@Z
1588 * ?_is_exception_typeof@@YAHAEBVtype_info@@PEAU_EXCEPTION_POINTERS@@@Z
1590 #ifndef __x86_64__
1591 int __cdecl _is_exception_typeof(const type_info *ti, EXCEPTION_POINTERS *ep)
1593 int ret = -1;
1595 TRACE("(%p %p)\n", ti, ep);
1597 __TRY
1599 EXCEPTION_RECORD *rec = ep->ExceptionRecord;
1601 if (rec->ExceptionCode==CXX_EXCEPTION && rec->NumberParameters==3 &&
1602 (rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC6 ||
1603 rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC7 ||
1604 rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC8))
1606 const cxx_type_info_table *tit = ((cxx_exception_type*)rec->ExceptionInformation[2])->type_info_table;
1607 int i;
1609 for (i=0; i<tit->count; i++) {
1610 if (ti==tit->info[i]->type_info || !strcmp(ti->mangled, tit->info[i]->type_info->mangled))
1612 ret = 1;
1613 break;
1617 if (i == tit->count)
1618 ret = 0;
1621 __EXCEPT_PAGE_FAULT
1622 __ENDTRY
1624 if(ret == -1)
1625 terminate();
1626 return ret;
1628 #else
1629 int __cdecl _is_exception_typeof(const type_info *ti, EXCEPTION_POINTERS *ep)
1631 int ret = -1;
1633 TRACE("(%p %p)\n", ti, ep);
1635 __TRY
1637 EXCEPTION_RECORD *rec = ep->ExceptionRecord;
1639 if (rec->ExceptionCode==CXX_EXCEPTION && rec->NumberParameters==4 &&
1640 (rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC6 ||
1641 rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC7 ||
1642 rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC8))
1644 const cxx_exception_type *et = (cxx_exception_type*)rec->ExceptionInformation[2];
1645 const cxx_type_info_table *tit = (const cxx_type_info_table*)(rec->ExceptionInformation[3]+et->type_info_table);
1646 int i;
1648 for (i=0; i<tit->count; i++) {
1649 const cxx_type_info *cti = (const cxx_type_info*)(rec->ExceptionInformation[3]+tit->info[i]);
1650 const type_info *except_ti = (const type_info*)(rec->ExceptionInformation[3]+cti->type_info);
1651 if (ti==except_ti || !strcmp(ti->mangled, except_ti->mangled))
1653 ret = 1;
1654 break;
1658 if (i == tit->count)
1659 ret = 0;
1662 __EXCEPT_PAGE_FAULT
1663 __ENDTRY
1665 if(ret == -1)
1666 terminate();
1667 return ret;
1669 #endif
1671 /*********************************************************************
1672 * __clean_type_info_names_internal (MSVCR80.@)
1674 void CDECL __clean_type_info_names_internal(void *p)
1676 FIXME("(%p) stub\n", p);
1679 /*********************************************************************
1680 * ?_name_internal_method@type_info@@QBEPBDPAU__type_info_node@@@Z (MSVCR100.@)
1682 DEFINE_THISCALL_WRAPPER(type_info_name_internal_method,8)
1683 const char * __thiscall type_info_name_internal_method(type_info * _this, struct __type_info_node *node)
1685 static int once;
1686 if (node && !once++) FIXME("type_info_node parameter ignored\n");
1688 return type_info_name(_this);
1691 #endif /* _MSVCR_VER >= 80 */
1693 /* std::exception_ptr class helpers */
1694 typedef struct
1696 EXCEPTION_RECORD *rec;
1697 int *ref; /* not binary compatible with native msvcr100 */
1698 } exception_ptr;
1700 #if _MSVCR_VER >= 100
1702 /*********************************************************************
1703 * ?__ExceptionPtrCreate@@YAXPAX@Z
1704 * ?__ExceptionPtrCreate@@YAXPEAX@Z
1706 void __cdecl __ExceptionPtrCreate(exception_ptr *ep)
1708 TRACE("(%p)\n", ep);
1710 ep->rec = NULL;
1711 ep->ref = NULL;
1714 #ifdef __ASM_USE_THISCALL_WRAPPER
1715 extern void call_dtor(const cxx_exception_type *type, void *func, void *object);
1717 __ASM_GLOBAL_FUNC( call_dtor,
1718 "movl 12(%esp),%ecx\n\t"
1719 "call *8(%esp)\n\t"
1720 "ret" );
1721 #elif __x86_64__
1722 static inline void call_dtor(const cxx_exception_type *type, unsigned int dtor, void *object)
1724 char *base = RtlPcToFileHeader((void*)type, (void**)&base);
1725 void (__cdecl *func)(void*) = (void*)(base + dtor);
1726 func(object);
1728 #else
1729 #define call_dtor(type, func, object) ((void (__thiscall*)(void*))(func))(object)
1730 #endif
1732 /*********************************************************************
1733 * ?__ExceptionPtrDestroy@@YAXPAX@Z
1734 * ?__ExceptionPtrDestroy@@YAXPEAX@Z
1736 void __cdecl __ExceptionPtrDestroy(exception_ptr *ep)
1738 TRACE("(%p)\n", ep);
1740 if (!ep->rec)
1741 return;
1743 if (!InterlockedDecrement(ep->ref))
1745 if (ep->rec->ExceptionCode == CXX_EXCEPTION)
1747 const cxx_exception_type *type = (void*)ep->rec->ExceptionInformation[2];
1748 void *obj = (void*)ep->rec->ExceptionInformation[1];
1750 if (type && type->destructor) call_dtor(type, type->destructor, obj);
1751 HeapFree(GetProcessHeap(), 0, obj);
1754 HeapFree(GetProcessHeap(), 0, ep->rec);
1755 HeapFree(GetProcessHeap(), 0, ep->ref);
1759 /*********************************************************************
1760 * ?__ExceptionPtrCopy@@YAXPAXPBX@Z
1761 * ?__ExceptionPtrCopy@@YAXPEAXPEBX@Z
1763 void __cdecl __ExceptionPtrCopy(exception_ptr *ep, const exception_ptr *copy)
1765 TRACE("(%p %p)\n", ep, copy);
1767 /* don't destroy object stored in ep */
1768 *ep = *copy;
1769 if (ep->ref)
1770 InterlockedIncrement(copy->ref);
1773 /*********************************************************************
1774 * ?__ExceptionPtrAssign@@YAXPAXPBX@Z
1775 * ?__ExceptionPtrAssign@@YAXPEAXPEBX@Z
1777 void __cdecl __ExceptionPtrAssign(exception_ptr *ep, const exception_ptr *assign)
1779 TRACE("(%p %p)\n", ep, assign);
1781 /* don't destroy object stored in ep */
1782 if (ep->ref)
1783 InterlockedDecrement(ep->ref);
1785 *ep = *assign;
1786 if (ep->ref)
1787 InterlockedIncrement(ep->ref);
1790 #endif /* _MSVCR_VER >= 100 */
1792 /*********************************************************************
1793 * ?__ExceptionPtrRethrow@@YAXPBX@Z
1794 * ?__ExceptionPtrRethrow@@YAXPEBX@Z
1796 void __cdecl __ExceptionPtrRethrow(const exception_ptr *ep)
1798 TRACE("(%p)\n", ep);
1800 if (!ep->rec)
1802 static const char *exception_msg = "bad exception";
1803 exception e;
1805 exception_ctor(&e, &exception_msg);
1806 _CxxThrowException(&e, &exception_exception_type);
1807 return;
1810 RaiseException(ep->rec->ExceptionCode, ep->rec->ExceptionFlags & (~EH_UNWINDING),
1811 ep->rec->NumberParameters, ep->rec->ExceptionInformation);
1814 #if _MSVCR_VER >= 100
1816 #ifdef __i386__
1817 extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase );
1818 #else
1819 static inline void call_copy_ctor( void *func, void *this, void *src, int has_vbase )
1821 TRACE( "calling copy ctor %p object %p src %p\n", func, this, src );
1822 if (has_vbase)
1823 ((void (__cdecl*)(void*, void*, BOOL))func)(this, src, 1);
1824 else
1825 ((void (__cdecl*)(void*, void*))func)(this, src);
1827 #endif
1829 /*********************************************************************
1830 * ?__ExceptionPtrCurrentException@@YAXPAX@Z
1831 * ?__ExceptionPtrCurrentException@@YAXPEAX@Z
1833 #ifndef __x86_64__
1834 void __cdecl __ExceptionPtrCurrentException(exception_ptr *ep)
1836 EXCEPTION_RECORD *rec = msvcrt_get_thread_data()->exc_record;
1838 TRACE("(%p)\n", ep);
1840 if (!rec)
1842 ep->rec = NULL;
1843 ep->ref = NULL;
1844 return;
1847 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1848 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1850 *ep->rec = *rec;
1851 *ep->ref = 1;
1853 if (ep->rec->ExceptionCode == CXX_EXCEPTION)
1855 const cxx_exception_type *et = (void*)ep->rec->ExceptionInformation[2];
1856 const cxx_type_info *ti;
1857 void **data, *obj;
1859 ti = et->type_info_table->info[0];
1860 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1862 obj = (void*)ep->rec->ExceptionInformation[1];
1863 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1865 memcpy(data, obj, ti->size);
1866 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1868 else if (ti->copy_ctor)
1870 call_copy_ctor(ti->copy_ctor, data, get_this_pointer(&ti->offsets, obj),
1871 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1873 else
1874 memcpy(data, get_this_pointer(&ti->offsets, obj), ti->size);
1875 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1877 return;
1879 #else
1880 void __cdecl __ExceptionPtrCurrentException(exception_ptr *ep)
1882 EXCEPTION_RECORD *rec = msvcrt_get_thread_data()->exc_record;
1884 TRACE("(%p)\n", ep);
1886 if (!rec)
1888 ep->rec = NULL;
1889 ep->ref = NULL;
1890 return;
1893 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1894 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1896 *ep->rec = *rec;
1897 *ep->ref = 1;
1899 if (ep->rec->ExceptionCode == CXX_EXCEPTION)
1901 const cxx_exception_type *et = (void*)ep->rec->ExceptionInformation[2];
1902 const cxx_type_info *ti;
1903 void **data, *obj;
1904 char *base = RtlPcToFileHeader((void*)et, (void**)&base);
1906 ti = (const cxx_type_info*)(base + ((const cxx_type_info_table*)(base + et->type_info_table))->info[0]);
1907 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1909 obj = (void*)ep->rec->ExceptionInformation[1];
1910 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1912 memcpy(data, obj, ti->size);
1913 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1915 else if (ti->copy_ctor)
1917 call_copy_ctor(base + ti->copy_ctor, data, get_this_pointer(&ti->offsets, obj),
1918 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1920 else
1921 memcpy(data, get_this_pointer(&ti->offsets, obj), ti->size);
1922 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1924 return;
1926 #endif
1928 #endif /* _MSVCR_VER >= 100 */
1930 #if _MSVCR_VER >= 110
1931 /*********************************************************************
1932 * ?__ExceptionPtrToBool@@YA_NPBX@Z
1933 * ?__ExceptionPtrToBool@@YA_NPEBX@Z
1935 bool __cdecl __ExceptionPtrToBool(exception_ptr *ep)
1937 return !!ep->rec;
1939 #endif
1941 #if _MSVCR_VER >= 100
1943 /*********************************************************************
1944 * ?__ExceptionPtrCopyException@@YAXPAXPBX1@Z
1945 * ?__ExceptionPtrCopyException@@YAXPEAXPEBX1@Z
1947 #ifndef __x86_64__
1948 void __cdecl __ExceptionPtrCopyException(exception_ptr *ep,
1949 exception *object, const cxx_exception_type *type)
1951 const cxx_type_info *ti;
1952 void **data;
1954 __ExceptionPtrDestroy(ep);
1956 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1957 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1958 *ep->ref = 1;
1960 memset(ep->rec, 0, sizeof(EXCEPTION_RECORD));
1961 ep->rec->ExceptionCode = CXX_EXCEPTION;
1962 ep->rec->ExceptionFlags = EH_NONCONTINUABLE;
1963 ep->rec->NumberParameters = 3;
1964 ep->rec->ExceptionInformation[0] = CXX_FRAME_MAGIC_VC6;
1965 ep->rec->ExceptionInformation[2] = (ULONG_PTR)type;
1967 ti = type->type_info_table->info[0];
1968 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
1969 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
1971 memcpy(data, object, ti->size);
1972 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
1974 else if (ti->copy_ctor)
1976 call_copy_ctor(ti->copy_ctor, data, get_this_pointer(&ti->offsets, object),
1977 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
1979 else
1980 memcpy(data, get_this_pointer(&ti->offsets, object), ti->size);
1981 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
1983 #else
1984 void __cdecl __ExceptionPtrCopyException(exception_ptr *ep,
1985 exception *object, const cxx_exception_type *type)
1987 const cxx_type_info *ti;
1988 void **data;
1989 char *base;
1991 RtlPcToFileHeader((void*)type, (void**)&base);
1992 __ExceptionPtrDestroy(ep);
1994 ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
1995 ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int));
1996 *ep->ref = 1;
1998 memset(ep->rec, 0, sizeof(EXCEPTION_RECORD));
1999 ep->rec->ExceptionCode = CXX_EXCEPTION;
2000 ep->rec->ExceptionFlags = EH_NONCONTINUABLE;
2001 ep->rec->NumberParameters = 4;
2002 ep->rec->ExceptionInformation[0] = CXX_FRAME_MAGIC_VC6;
2003 ep->rec->ExceptionInformation[2] = (ULONG_PTR)type;
2004 ep->rec->ExceptionInformation[3] = (ULONG_PTR)base;
2006 ti = (const cxx_type_info*)(base + ((const cxx_type_info_table*)(base + type->type_info_table))->info[0]);
2007 data = HeapAlloc(GetProcessHeap(), 0, ti->size);
2008 if (ti->flags & CLASS_IS_SIMPLE_TYPE)
2010 memcpy(data, object, ti->size);
2011 if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data);
2013 else if (ti->copy_ctor)
2015 call_copy_ctor(base + ti->copy_ctor, data, get_this_pointer(&ti->offsets, object),
2016 ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS);
2018 else
2019 memcpy(data, get_this_pointer(&ti->offsets, object), ti->size);
2020 ep->rec->ExceptionInformation[1] = (ULONG_PTR)data;
2022 #endif
2024 bool __cdecl __ExceptionPtrCompare(const exception_ptr *ep1, const exception_ptr *ep2)
2026 return ep1->rec == ep2->rec;
2029 #endif /* _MSVCR_VER >= 100 */
2031 #if _MSVCR_VER >= 80
2032 void* __cdecl __AdjustPointer(void *obj, const this_ptr_offsets *off)
2034 return get_this_pointer(off, obj);
2036 #endif
2038 #if _MSVCR_VER >= 140
2040 typedef struct
2042 char *name;
2043 char mangled[1];
2044 } type_info140;
2046 typedef struct
2048 SLIST_ENTRY entry;
2049 char name[1];
2050 } type_info_entry;
2052 static void* CDECL type_info_entry_malloc(size_t size)
2054 type_info_entry *ret = malloc(FIELD_OFFSET(type_info_entry, name) + size);
2055 return ret->name;
2058 static void CDECL type_info_entry_free(void *ptr)
2060 ptr = (char*)ptr - FIELD_OFFSET(type_info_entry, name);
2061 free(ptr);
2064 /******************************************************************
2065 * __std_type_info_compare (UCRTBASE.@)
2067 int CDECL __std_type_info_compare(const type_info140 *l, const type_info140 *r)
2069 int ret;
2071 if (l == r) ret = 0;
2072 else ret = strcmp(l->mangled + 1, r->mangled + 1);
2073 TRACE("(%p %p) returning %d\n", l, r, ret);
2074 return ret;
2077 /******************************************************************
2078 * __std_type_info_name (UCRTBASE.@)
2080 const char* CDECL __std_type_info_name(type_info140 *ti, SLIST_HEADER *header)
2082 if (!ti->name)
2084 char* name = __unDName(0, ti->mangled + 1, 0,
2085 type_info_entry_malloc, type_info_entry_free, UNDNAME_NO_ARGUMENTS | UNDNAME_32_BIT_DECODE);
2086 if (name)
2088 unsigned int len = strlen(name);
2090 while (len && name[--len] == ' ')
2091 name[len] = '\0';
2093 if (InterlockedCompareExchangePointer((void**)&ti->name, name, NULL))
2095 type_info_entry_free(name);
2097 else
2099 type_info_entry *entry = (type_info_entry*)(name-FIELD_OFFSET(type_info_entry, name));
2100 InterlockedPushEntrySList(header, &entry->entry);
2104 TRACE("(%p) returning %s\n", ti, ti->name);
2105 return ti->name;
2108 /******************************************************************
2109 * __std_type_info_destroy_list (UCRTBASE.@)
2111 void CDECL __std_type_info_destroy_list(SLIST_HEADER *header)
2113 SLIST_ENTRY *cur, *next;
2115 TRACE("(%p)\n", header);
2117 for(cur = InterlockedFlushSList(header); cur; cur = next)
2119 next = cur->Next;
2120 free(cur);
2124 /******************************************************************
2125 * __std_type_info_hash (UCRTBASE.@)
2127 size_t CDECL __std_type_info_hash(const type_info140 *ti)
2129 size_t hash, fnv_prime;
2130 const char *p;
2132 #ifdef _WIN64
2133 hash = 0xcbf29ce484222325;
2134 fnv_prime = 0x100000001b3;
2135 #else
2136 hash = 0x811c9dc5;
2137 fnv_prime = 0x1000193;
2138 #endif
2140 TRACE("(%p)->%s\n", ti, ti->mangled);
2142 for(p = ti->mangled+1; *p; p++) {
2143 hash ^= *p;
2144 hash *= fnv_prime;
2147 #ifdef _WIN64
2148 hash ^= hash >> 32;
2149 #endif
2151 return hash;
2154 #endif /* _MSVCR_VER >= 140 */
2156 #if _MSVCR_VER >= 100
2158 enum ConcRT_EventType
2160 CONCRT_EVENT_GENERIC,
2161 CONCRT_EVENT_START,
2162 CONCRT_EVENT_END,
2163 CONCRT_EVENT_BLOCK,
2164 CONCRT_EVENT_UNBLOCK,
2165 CONCRT_EVENT_YIELD,
2166 CONCRT_EVENT_ATTACH,
2167 CONCRT_EVENT_DETACH
2170 /* ?_Trace_ppl_function@Concurrency@@YAXABU_GUID@@EW4ConcRT_EventType@1@@Z */
2171 /* ?_Trace_ppl_function@Concurrency@@YAXAEBU_GUID@@EW4ConcRT_EventType@1@@Z */
2172 void __cdecl Concurrency__Trace_ppl_function(const GUID *guid, unsigned char level, enum ConcRT_EventType type)
2174 FIXME("(%s %u %i) stub\n", debugstr_guid(guid), level, type);
2177 #endif /* _MSVCR_VER >= 100 */