Re: [cxx-abi-dev] ABI modification for exception propagation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cxx-abi-dev] ABI modification for exception propagation



David Vandevoorde wrote:

Note that it doesn't have to copy the thrown object: It can essentially return a smartptr<__cxa_exception> (which is what std::exception_ptr would be) for the top exception. The constructor for this smart pointer must behave a bit like __cxa_rethrow() in that it must avoid having __cxa_end_catch destroy the exception. Instead, that destruction must now be handled by the destructor of smartptr<__cxa_exception> (when the reference count goes to zero).
I have tried that. It doesn't work. Yes, I can make an exception_ptr that refers to an existing __cxa_exception, but I can't rethrow it. That would mean allowing a single __cxa_exception to be in multiple throws at once, and _Unwind_Exception cannot handle that. Also, __cxa_exception cannot handle having been caught by several threads at once. It would mess up the nextException chain. I HAVE to duplicate the __cxa_exception, and as long as the __cxa_exception and the exception object are in the same memory block, that means copying the exception object too.

You can read my rationale in the thread at the libstdc++ mailing list.
http://gcc.gnu.org/ml/libstdc++/2008-05/msg00079.html


Although, thinking about it some more, there might be a way. There could be essentially two kinds of __cxa_exception. One looks like the old one, with an added reference count. The other holds a pointer to the first kind instead. All exception_ptrs refer to the primary __cxa_exception, but on rethrow they allocate a secondary that also refers to the first.

This might work. But *only* if all modules link to the support library dynamically, of course. If any of them links statically, it would keep the old implementation, which would wreak havoc.

I'll look into implementing that.

Sebastian