1 | /*
|
---|
2 | * msvcrt.dll C++ objects
|
---|
3 | *
|
---|
4 | * Copyright 2000 Jon Griffiths
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2.1 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "msvcrt.h"
|
---|
22 | #include "msvcrt/eh.h"
|
---|
23 | #include "msvcrt/stdlib.h"
|
---|
24 | #include <string.h>
|
---|
25 | #include "wine/debug.h"
|
---|
26 |
|
---|
27 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
---|
28 |
|
---|
29 | typedef void (*v_table_ptr)();
|
---|
30 |
|
---|
31 | static v_table_ptr exception_vtable[2];
|
---|
32 | static v_table_ptr bad_typeid_vtable[3];
|
---|
33 | static v_table_ptr __non_rtti_object_vtable[3];
|
---|
34 | static v_table_ptr bad_cast_vtable[3];
|
---|
35 | static v_table_ptr type_info_vtable[1];
|
---|
36 |
|
---|
37 | typedef struct __exception
|
---|
38 | {
|
---|
39 | v_table_ptr *vtable;
|
---|
40 | const char *name;
|
---|
41 | int do_free; /* FIXME: take string copy with char* ctor? */
|
---|
42 | } exception;
|
---|
43 |
|
---|
44 | typedef struct __bad_typeid
|
---|
45 | {
|
---|
46 | exception base;
|
---|
47 | } bad_typeid;
|
---|
48 |
|
---|
49 | typedef struct ____non_rtti_object
|
---|
50 | {
|
---|
51 | bad_typeid base;
|
---|
52 | } __non_rtti_object;
|
---|
53 |
|
---|
54 | typedef struct __bad_cast
|
---|
55 | {
|
---|
56 | exception base;
|
---|
57 | } bad_cast;
|
---|
58 |
|
---|
59 | typedef struct __type_info
|
---|
60 | {
|
---|
61 | v_table_ptr *vtable;
|
---|
62 | void *data;
|
---|
63 | char name[1];
|
---|
64 | } type_info;
|
---|
65 |
|
---|
66 | typedef struct _rtti_base_descriptor
|
---|
67 | {
|
---|
68 | type_info *type_descriptor;
|
---|
69 | int num_base_classes;
|
---|
70 | int base_class_offset;
|
---|
71 | unsigned int flags;
|
---|
72 | } rtti_base_descriptor;
|
---|
73 |
|
---|
74 | typedef struct _rtti_base_array
|
---|
75 | {
|
---|
76 | rtti_base_descriptor *bases[1]; /* First element is the class itself */
|
---|
77 | } rtti_base_array;
|
---|
78 |
|
---|
79 | typedef struct _rtti_object_hierachy
|
---|
80 | {
|
---|
81 | int unknown1;
|
---|
82 | int unknown2;
|
---|
83 | int array_len; /* Size of the array pointed to by 'base_classes' */
|
---|
84 | rtti_base_array *base_classes;
|
---|
85 | } rtti_object_hierachy;
|
---|
86 |
|
---|
87 | typedef struct _rtti_object_locator
|
---|
88 | {
|
---|
89 | int unknown1;
|
---|
90 | int base_class_offset;
|
---|
91 | unsigned int flags;
|
---|
92 | type_info *type_descriptor;
|
---|
93 | rtti_object_hierachy *type_hierachy;
|
---|
94 | } rtti_object_locator;
|
---|
95 |
|
---|
96 | /******************************************************************
|
---|
97 | * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
|
---|
98 | */
|
---|
99 | void MSVCRT_exception_ctor(exception * _this, const char ** name)
|
---|
100 | {
|
---|
101 | TRACE("MSVCRT: exception_ctor (%p %s)\n",_this,*name);
|
---|
102 | _this->vtable = exception_vtable;
|
---|
103 | _this->name = *name;
|
---|
104 | TRACE("name = %s\n",_this->name);
|
---|
105 | _this->do_free = 0; /* FIXME */
|
---|
106 | }
|
---|
107 |
|
---|
108 | /******************************************************************
|
---|
109 | * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
|
---|
110 | */
|
---|
111 | void MSVCRT_exception_copy_ctor(exception * _this, const exception * rhs)
|
---|
112 | {
|
---|
113 | TRACE("MSVCRT: exception_copy_ctor (%p %p)\n",_this,rhs);
|
---|
114 | if (_this != rhs)
|
---|
115 | memcpy (_this, rhs, sizeof (*_this));
|
---|
116 | TRACE("name = %s\n",_this->name);
|
---|
117 | }
|
---|
118 |
|
---|
119 | /******************************************************************
|
---|
120 | * ??0exception@@QAE@XZ (MSVCRT.@)
|
---|
121 | */
|
---|
122 | void MSVCRT_exception_default_ctor(exception * _this)
|
---|
123 | {
|
---|
124 | TRACE("MSVCRT: exception_default_ctor (%p)\n",_this);
|
---|
125 | _this->vtable = exception_vtable;
|
---|
126 | _this->name = "";
|
---|
127 | _this->do_free = 0; /* FIXME */
|
---|
128 | }
|
---|
129 |
|
---|
130 | /******************************************************************
|
---|
131 | * ??1exception@@UAE@XZ (MSVCRT.@)
|
---|
132 | */
|
---|
133 | void MSVCRT_exception_dtor(exception * _this)
|
---|
134 | {
|
---|
135 | TRACE("MSVCRT: exception_dtor(%p)\n",_this);
|
---|
136 | }
|
---|
137 |
|
---|
138 | /******************************************************************
|
---|
139 | * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
|
---|
140 | */
|
---|
141 | exception * MSVCRT_exception_opequals(exception * _this, const exception * rhs)
|
---|
142 | {
|
---|
143 | TRACE("(%p %p)\n",_this,rhs);
|
---|
144 | memcpy (_this, rhs, sizeof (*_this));
|
---|
145 | TRACE("name = %s\n",_this->name);
|
---|
146 | return _this;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /******************************************************************
|
---|
150 | * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
|
---|
151 | */
|
---|
152 | void * MSVCRT_exception__unknown_E(exception * _this, unsigned int arg1)
|
---|
153 | {
|
---|
154 | TRACE("(%p %d)\n",_this,arg1);
|
---|
155 | _purecall();
|
---|
156 | return NULL;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /******************************************************************
|
---|
160 | * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
|
---|
161 | */
|
---|
162 | void * MSVCRT_exception__unknown_G(exception * _this, unsigned int arg1)
|
---|
163 | {
|
---|
164 | TRACE("(%p %d)\n",_this,arg1);
|
---|
165 | _purecall();
|
---|
166 | return NULL;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /******************************************************************
|
---|
170 | * ?what@exception@@UBEPBDXZ (MSVCRT.@)
|
---|
171 | */
|
---|
172 | const char * MSVCRT_what_exception(exception * _this)
|
---|
173 | {
|
---|
174 | TRACE("(%p) returning %s\n",_this,_this->name);
|
---|
175 | return _this->name;
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | /******************************************************************
|
---|
180 | * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
|
---|
181 | */
|
---|
182 | terminate_function MSVCRT_set_terminate(terminate_function func)
|
---|
183 | {
|
---|
184 | MSVCRT_thread_data *data = msvcrt_get_thread_data();
|
---|
185 | terminate_function previous = data->terminate_handler;
|
---|
186 | TRACE("(%p) returning %p\n",func,previous);
|
---|
187 | data->terminate_handler = func;
|
---|
188 | return previous;
|
---|
189 | }
|
---|
190 |
|
---|
191 | /******************************************************************
|
---|
192 | * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
|
---|
193 | */
|
---|
194 | unexpected_function MSVCRT_set_unexpected(unexpected_function func)
|
---|
195 | {
|
---|
196 | MSVCRT_thread_data *data = msvcrt_get_thread_data();
|
---|
197 | unexpected_function previous = data->unexpected_handler;
|
---|
198 | TRACE("(%p) returning %p\n",func,previous);
|
---|
199 | data->unexpected_handler = func;
|
---|
200 | return previous;
|
---|
201 | }
|
---|
202 |
|
---|
203 | /******************************************************************
|
---|
204 | * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@)
|
---|
205 | */
|
---|
206 | _se_translator_function MSVCRT__set_se_translator(_se_translator_function func)
|
---|
207 | {
|
---|
208 | MSVCRT_thread_data *data = msvcrt_get_thread_data();
|
---|
209 | _se_translator_function previous = data->se_translator;
|
---|
210 | TRACE("(%p) returning %p\n",func,previous);
|
---|
211 | data->se_translator = func;
|
---|
212 | return previous;
|
---|
213 | }
|
---|
214 |
|
---|
215 | /******************************************************************
|
---|
216 | * ?terminate@@YAXXZ (MSVCRT.@)
|
---|
217 | */
|
---|
218 | void MSVCRT_terminate(void)
|
---|
219 | {
|
---|
220 | MSVCRT_thread_data *data = msvcrt_get_thread_data();
|
---|
221 | if (data->terminate_handler) data->terminate_handler();
|
---|
222 | MSVCRT_abort();
|
---|
223 | }
|
---|
224 |
|
---|
225 | /******************************************************************
|
---|
226 | * ?unexpected@@YAXXZ (MSVCRT.@)
|
---|
227 | */
|
---|
228 | void MSVCRT_unexpected(void)
|
---|
229 | {
|
---|
230 | MSVCRT_thread_data *data = msvcrt_get_thread_data();
|
---|
231 | if (data->unexpected_handler) data->unexpected_handler();
|
---|
232 | MSVCRT_terminate();
|
---|
233 | }
|
---|
234 |
|
---|
235 |
|
---|
236 | /******************************************************************
|
---|
237 | * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
|
---|
238 | */
|
---|
239 | void MSVCRT_bad_typeid_copy_ctor(bad_typeid * _this, const bad_typeid * rhs)
|
---|
240 | {
|
---|
241 | TRACE("(%p %p)\n",_this,rhs);
|
---|
242 | MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
|
---|
243 | }
|
---|
244 |
|
---|
245 | /******************************************************************
|
---|
246 | * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
|
---|
247 | */
|
---|
248 | void MSVCRT_bad_typeid_ctor(bad_typeid * _this, const char * name)
|
---|
249 | {
|
---|
250 | TRACE("(%p %s)\n",_this,name);
|
---|
251 | MSVCRT_exception_ctor(&_this->base, &name);
|
---|
252 | _this->base.vtable = bad_typeid_vtable;
|
---|
253 | }
|
---|
254 |
|
---|
255 | /******************************************************************
|
---|
256 | * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
|
---|
257 | */
|
---|
258 | void MSVCRT_bad_typeid_dtor(bad_typeid * _this)
|
---|
259 | {
|
---|
260 | TRACE("(%p)\n",_this);
|
---|
261 | MSVCRT_exception_dtor(&_this->base);
|
---|
262 | }
|
---|
263 |
|
---|
264 | /******************************************************************
|
---|
265 | * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
|
---|
266 | */
|
---|
267 | bad_typeid * MSVCRT_bad_typeid_opequals(bad_typeid * _this, const bad_typeid * rhs)
|
---|
268 | {
|
---|
269 | TRACE("(%p %p)\n",_this,rhs);
|
---|
270 | MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
|
---|
271 | return _this;
|
---|
272 | }
|
---|
273 |
|
---|
274 | /******************************************************************
|
---|
275 | * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
|
---|
276 | */
|
---|
277 | void MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object * _this,
|
---|
278 | const __non_rtti_object * rhs)
|
---|
279 | {
|
---|
280 | TRACE("(%p %p)\n",_this,rhs);
|
---|
281 | MSVCRT_bad_typeid_copy_ctor(&_this->base,&rhs->base);
|
---|
282 | }
|
---|
283 |
|
---|
284 | /******************************************************************
|
---|
285 | * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
|
---|
286 | */
|
---|
287 | void MSVCRT___non_rtti_object_ctor(__non_rtti_object * _this,
|
---|
288 | const char * name)
|
---|
289 | {
|
---|
290 | TRACE("(%p %s)\n",_this,name);
|
---|
291 | MSVCRT_bad_typeid_ctor(&_this->base,name);
|
---|
292 | _this->base.base.vtable = __non_rtti_object_vtable;
|
---|
293 | }
|
---|
294 |
|
---|
295 | /******************************************************************
|
---|
296 | * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
|
---|
297 | */
|
---|
298 | void MSVCRT___non_rtti_object_dtor(__non_rtti_object * _this)
|
---|
299 | {
|
---|
300 | TRACE("(%p)\n",_this);
|
---|
301 | MSVCRT_bad_typeid_dtor(&_this->base);
|
---|
302 | }
|
---|
303 |
|
---|
304 | /******************************************************************
|
---|
305 | * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
|
---|
306 | */
|
---|
307 | __non_rtti_object * MSVCRT___non_rtti_object_opequals(__non_rtti_object * _this,
|
---|
308 | const __non_rtti_object *rhs)
|
---|
309 | {
|
---|
310 | TRACE("(%p %p)\n",_this,rhs);
|
---|
311 | memcpy (_this, rhs, sizeof (*_this));
|
---|
312 | TRACE("name = %s\n",_this->base.base.name);
|
---|
313 | return _this;
|
---|
314 | }
|
---|
315 |
|
---|
316 | /******************************************************************
|
---|
317 | * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
|
---|
318 | */
|
---|
319 | void * MSVCRT___non_rtti_object__unknown_E(__non_rtti_object * _this, unsigned int arg1)
|
---|
320 | {
|
---|
321 | TRACE("(%p %d)\n",_this,arg1);
|
---|
322 | _purecall();
|
---|
323 | return NULL;
|
---|
324 | }
|
---|
325 |
|
---|
326 | /******************************************************************
|
---|
327 | * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
|
---|
328 | */
|
---|
329 | void * MSVCRT___non_rtti_object__unknown_G(__non_rtti_object * _this, unsigned int arg1)
|
---|
330 | {
|
---|
331 | TRACE("(%p %d)\n",_this,arg1);
|
---|
332 | _purecall();
|
---|
333 | return NULL;
|
---|
334 | }
|
---|
335 |
|
---|
336 | /******************************************************************
|
---|
337 | * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
|
---|
338 | */
|
---|
339 | void MSVCRT_bad_cast_ctor(bad_cast * _this, const char ** name)
|
---|
340 | {
|
---|
341 | TRACE("(%p %s)\n",_this,*name);
|
---|
342 | MSVCRT_exception_ctor(&_this->base, name);
|
---|
343 | _this->base.vtable = bad_cast_vtable;
|
---|
344 | }
|
---|
345 |
|
---|
346 | /******************************************************************
|
---|
347 | * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
|
---|
348 | */
|
---|
349 | void MSVCRT_bad_cast_copy_ctor(bad_cast * _this, const bad_cast * rhs)
|
---|
350 | {
|
---|
351 | TRACE("(%p %p)\n",_this,rhs);
|
---|
352 | MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
|
---|
353 | }
|
---|
354 |
|
---|
355 | /******************************************************************
|
---|
356 | * ??1bad_cast@@UAE@XZ (MSVCRT.@)
|
---|
357 | */
|
---|
358 | void MSVCRT_bad_cast_dtor(bad_cast * _this)
|
---|
359 | {
|
---|
360 | TRACE("(%p)\n",_this);
|
---|
361 | MSVCRT_exception_dtor(&_this->base);
|
---|
362 | }
|
---|
363 |
|
---|
364 | /******************************************************************
|
---|
365 | * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
|
---|
366 | */
|
---|
367 | bad_cast * MSVCRT_bad_cast_opequals(bad_cast * _this, const bad_cast * rhs)
|
---|
368 | {
|
---|
369 | TRACE("(%p %p)\n",_this,rhs);
|
---|
370 | MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
|
---|
371 | return _this;
|
---|
372 | }
|
---|
373 |
|
---|
374 | /******************************************************************
|
---|
375 | * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
|
---|
376 | */
|
---|
377 | int __stdcall MSVCRT_type_info_opequals_equals(type_info * _this, const type_info * rhs)
|
---|
378 | {
|
---|
379 | TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
|
---|
380 | return _this->name == rhs->name;
|
---|
381 | }
|
---|
382 |
|
---|
383 | /******************************************************************
|
---|
384 | * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
|
---|
385 | */
|
---|
386 | int __stdcall MSVCRT_type_info_opnot_equals(type_info * _this, const type_info * rhs)
|
---|
387 | {
|
---|
388 | TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
|
---|
389 | return _this->name != rhs->name;
|
---|
390 | }
|
---|
391 |
|
---|
392 | /******************************************************************
|
---|
393 | * ??1type_info@@UAE@XZ (MSVCRT.@)
|
---|
394 | */
|
---|
395 | void MSVCRT_type_info_dtor(type_info * _this)
|
---|
396 | {
|
---|
397 | TRACE("(%p)\n",_this);
|
---|
398 | if (_this->data)
|
---|
399 | MSVCRT_free(_this->data);
|
---|
400 | }
|
---|
401 |
|
---|
402 | /******************************************************************
|
---|
403 | * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
|
---|
404 | */
|
---|
405 | const char * __stdcall MSVCRT_type_info_name(type_info * _this)
|
---|
406 | {
|
---|
407 | TRACE("(%p) returning %s\n",_this,_this->name);
|
---|
408 | return _this->name;
|
---|
409 | }
|
---|
410 |
|
---|
411 | /******************************************************************
|
---|
412 | * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
|
---|
413 | */
|
---|
414 | const char * __stdcall MSVCRT_type_info_raw_name(type_info * _this)
|
---|
415 | {
|
---|
416 | TRACE("(%p) returning %s\n",_this,_this->name);
|
---|
417 | return _this->name;
|
---|
418 | }
|
---|
419 |
|
---|
420 |
|
---|
421 | /******************************************************************
|
---|
422 | * __RTtypeid (MSVCRT.@)
|
---|
423 | */
|
---|
424 | type_info* MSVCRT___RTtypeid(type_info *cppobj)
|
---|
425 | {
|
---|
426 | /* Note: cppobj _isn't_ a type_info, we use that struct for its vtable ptr */
|
---|
427 | TRACE("(%p)\n",cppobj);
|
---|
428 |
|
---|
429 | if (!IsBadReadPtr(cppobj, sizeof(void *)) &&
|
---|
430 | !IsBadReadPtr(cppobj->vtable - 1,sizeof(void *)) &&
|
---|
431 | !IsBadReadPtr((void*)cppobj->vtable[-1], sizeof(rtti_object_locator)))
|
---|
432 | {
|
---|
433 | rtti_object_locator *obj_locator = (rtti_object_locator *)cppobj->vtable[-1];
|
---|
434 | return obj_locator->type_descriptor;
|
---|
435 | }
|
---|
436 | /* FIXME: throw a C++ exception */
|
---|
437 | FIXME("Should throw(bad_typeid). Creating NULL reference, expect crash!\n");
|
---|
438 | return NULL;
|
---|
439 | }
|
---|
440 |
|
---|
441 | /******************************************************************
|
---|
442 | * __RTDynamicCast (MSVCRT.@)
|
---|
443 | */
|
---|
444 | void* MSVCRT___RTDynamicCast(type_info *cppobj, int unknown,
|
---|
445 | type_info *src, type_info *dst,
|
---|
446 | int do_throw)
|
---|
447 | {
|
---|
448 | /* Note: cppobj _isn't_ a type_info, we use that struct for its vtable ptr */
|
---|
449 | TRACE("(%p,%d,%p,%p,%d)\n",cppobj, unknown, src, dst, do_throw);
|
---|
450 |
|
---|
451 | if (unknown)
|
---|
452 | FIXME("Unknown prameter is non-zero: please report\n");
|
---|
453 |
|
---|
454 | /* To cast an object at runtime:
|
---|
455 | * 1.Find out the true type of the object from the typeinfo at vtable[-1]
|
---|
456 | * 2.Search for the destination type in the class heirachy
|
---|
457 | * 3.If destination type is found, return base object address + dest offset
|
---|
458 | * Otherwise, fail the cast
|
---|
459 | */
|
---|
460 | if (!IsBadReadPtr(cppobj, sizeof(void *)) &&
|
---|
461 | !IsBadReadPtr(cppobj->vtable - 1,sizeof(void *)) &&
|
---|
462 | !IsBadReadPtr((void*)cppobj->vtable[-1], sizeof(rtti_object_locator)))
|
---|
463 | {
|
---|
464 | int count = 0;
|
---|
465 | rtti_object_locator *obj_locator = (rtti_object_locator *)cppobj->vtable[-1];
|
---|
466 | rtti_object_hierachy *obj_bases = obj_locator->type_hierachy;
|
---|
467 | rtti_base_descriptor **base_desc = obj_bases->base_classes->bases;
|
---|
468 | int src_offset = obj_locator->base_class_offset, dst_offset = -1;
|
---|
469 |
|
---|
470 | while (count < obj_bases->array_len)
|
---|
471 | {
|
---|
472 | type_info *typ = (*base_desc)->type_descriptor;
|
---|
473 |
|
---|
474 | if (!strcmp(typ->name, dst->name))
|
---|
475 | {
|
---|
476 | dst_offset = (*base_desc)->base_class_offset;
|
---|
477 | break;
|
---|
478 | }
|
---|
479 | base_desc++;
|
---|
480 | count++;
|
---|
481 | }
|
---|
482 | if (dst_offset >= 0)
|
---|
483 | return (void*)((unsigned long)cppobj - src_offset + dst_offset);
|
---|
484 | }
|
---|
485 |
|
---|
486 | /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned
|
---|
487 | * to a reference, since references cannot be NULL.
|
---|
488 | */
|
---|
489 | if (do_throw)
|
---|
490 | FIXME("Should throw(bad_cast). Creating NULL reference, expect crash!\n");
|
---|
491 | return NULL;
|
---|
492 | }
|
---|
493 |
|
---|
494 |
|
---|
495 | /******************************************************************
|
---|
496 | * __RTCastToVoid (MSVCRT.@)
|
---|
497 | */
|
---|
498 | void* MSVCRT___RTCastToVoid(type_info *cppobj)
|
---|
499 | {
|
---|
500 | /* Note: cppobj _isn't_ a type_info, we use that struct for its vtable ptr */
|
---|
501 | TRACE("MSVCRT: ___RTCastToVoid (%p)\n",cppobj);
|
---|
502 |
|
---|
503 | /* Casts to void* simply cast to the base object */
|
---|
504 | if (!IsBadReadPtr(cppobj, sizeof(void *)) &&
|
---|
505 | !IsBadReadPtr(cppobj->vtable - 1,sizeof(void *)) &&
|
---|
506 | !IsBadReadPtr((void*)cppobj->vtable[-1], sizeof(rtti_object_locator)))
|
---|
507 | {
|
---|
508 | rtti_object_locator *obj_locator = (rtti_object_locator *)cppobj->vtable[-1];
|
---|
509 | int src_offset = obj_locator->base_class_offset;
|
---|
510 |
|
---|
511 | return (void*)((unsigned long)cppobj - src_offset);
|
---|
512 | }
|
---|
513 | return NULL;
|
---|
514 | }
|
---|
515 |
|
---|
516 |
|
---|
517 | /* INTERNAL: Set up vtables
|
---|
518 | * FIXME:should be static, cope with versions?
|
---|
519 | */
|
---|
520 | void msvcrt_init_vtables(void)
|
---|
521 | {
|
---|
522 | exception_vtable[0] = MSVCRT_exception_dtor;
|
---|
523 | exception_vtable[1] = (void*)MSVCRT_what_exception;
|
---|
524 |
|
---|
525 | bad_typeid_vtable[0] = MSVCRT_bad_typeid_dtor;
|
---|
526 | bad_typeid_vtable[1] = exception_vtable[1];
|
---|
527 | bad_typeid_vtable[2] = _purecall; /* FIXME */
|
---|
528 |
|
---|
529 | __non_rtti_object_vtable[0] = MSVCRT___non_rtti_object_dtor;
|
---|
530 | __non_rtti_object_vtable[1] = bad_typeid_vtable[1];
|
---|
531 | __non_rtti_object_vtable[2] = bad_typeid_vtable[2];
|
---|
532 |
|
---|
533 | bad_cast_vtable[0] = MSVCRT_bad_cast_dtor;
|
---|
534 | bad_cast_vtable[1] = exception_vtable[1];
|
---|
535 | bad_cast_vtable[2] = _purecall; /* FIXME */
|
---|
536 |
|
---|
537 | type_info_vtable[0] = MSVCRT_type_info_dtor;
|
---|
538 |
|
---|
539 | }
|
---|