CPP Exception Support

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
nilres
Posts: 6
Joined: Sun Nov 08, 2015 1:20 pm

CPP Exception Support

Post by nilres »

Hi Guys,

I working on CPP exception support in my Kernel since a couple of weeks. I was able to write an Stack Unwinder based on the dwarf information in the eh_debug section. Now I'm working on the ABI specific parts for the actual exception support.

My current code is able to find the landingpad of the exception and return to that position. I have a basic implementation of __cxa_allocate_exception that deals with my memory management, __cxa_throw calls the _Unwind_RaiseException routine that searches for the landing pad in the search phase and then in the second phase actually installs the found context.
This is the point where I'm a little bit stuck. If my catch is defined as catch(...) (so no type information just catch everything) this works fine. As soon as I try to catch a specific exception (catch(int a)) it gets more complicated. My understanding is that __cxa_begin_catch returns a void* pointer to the memory where __cxa_allocate_exception has reserved memory. If I just hard code specific address I can catch the exception with the actual exception information.
What I don't understand is how I can pass the input parameter to __cxa_begin_catch. I digged through the gcc code and found the __builtin_eh_return function which I use to install the new Instruction Pointer and Stack Pointer. Which works as __cxa_begin_catch is called and as soon as I return from that function I'm in the correct landingpad.
Does anyone has any insight on where __cxa_begin_catch gets his parameter? I already tried pushing it onto the stack before calling __builtin_eh_return but that gcc build in function seems to pop this.

Thanks for your help. This is a very specific topic where not much information exist around the web.
Post Reply