On 06/14/16 19:01, Iván Matellanes wrote:
ostream_vbase_dtor can be used to destroy object that has virtual base in any position pointer by vbtable. ostream_get_ios computes it using object's vbtable. You can easily see it by overwriting ostream->vbtable with garbage, the application will crash then on Windows.
On the other hand ostream_dtor is a virtual function that assumes "this" is at fixed offset from "base" that is passed to it. It's done this way because it has no access to vbtable. It's why you need to use ostream_to_ios in this case. There's no real need to call ostream_dtor here because it's an empty function (I don't know if it should be called here or if ostream_vbase_dtor should only destroy the vbase).
Thanks, Piotr
On 14/06/16 19:59, Piotr Caban wrote:
It crashes when ostream->vbtable is garbage, but otherwise, it seems to ignore the value and destroy the ios object at a fixed position anyway (see attached file). I think this is reasonable since ostream_vbase_dtor will only be used to destroy ostream objects, i.e., not objects of subclasses, right? This doesn't explain why we get a crash when ostream->vbtable = NULL though.
True, the function call is a no-op. I was following the style in msvcp90 to be coherent, but I can remove this call if you feel it makes more sense.
Cheers, Iván
On 06/14/16 23:42, Iván Matellanes wrote:
Yes, you're right. I've done some more testing and it turns out `vbase destructors` are not using vbtable.
This doesn't explain why we get a crash when ostream->vbtable = NULL though.
The crash is caused by destructor. It turns out the destructor is always updating virtual functions table. The vbtable is used to compute virtual functions table location. E.g. class a destructor does something like this: void thiscall a_dtor(base *b) { a *this = base_to_a(base); b = a_get_base(a); b->vtable = &MSVCP_a_vtable; //do the object destruction ... } The virtual function table is updated in all destructors (even if virtual inheritance is not used). As long as we're not calling virtual functions in destructors there's probably no need to do it in wine.
Thanks, Piotr