C++ Exception Support: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(Intro to rolling your own C++ exception handling)
(Update with GXX personality function)
Line 1: Line 1:
If the g++ that targets your operating system follows the [http://www.codesourcery.com/public/cxx-abi/abi-eh.html Itanium C++ ABI], you can follow this article and add C++ exception support to your kernel.
If the g++ that targets your operating system follows the [http://www.codesourcery.com/public/cxx-abi/abi-eh.html Itanium C++ ABI] (GCC does so for almost all architectures), you can follow this article and add C++ exception support to your kernel.


=Introduction=
=Introduction=
Line 27: Line 27:


=Rolling your own=
=Rolling your own=
(NOTE: This is not yet complete, and hasn't been independently tested)
If you're adverse to including external code in your OS (or just want the challenge), you should be able to write your own C++ library, which handles the dispatching and allocation of exceptions (stack backtracing is handed by libgcc, which you should already be including with your build). If you choose this route, make sure to run _init upon loading each module (library or executable) to properly register the exception handling frames with the unwind code.
If you're adverse to including external code in your OS (or just want the challenge), you should be able to write your own C++ library, which handles the dispatching and allocation of exceptions (stack backtracing is handed by libgcc, which you should already be including with your build). If you choose this route, make sure to run _init upon loading each module (library or executable) to properly register the exception handling frames with the unwind code.


The functions you'll need to implement all start with `__cxa_` and are documented in the Itanium C++ ABI (which is also used for x86 by GCC)
The functions you'll need to implement all start with `__cxa_` and are documented in the Itanium C++ ABI (which is also used for x86 by GCC)
You will also need to implement `__gxx_personality_v0` (which according to the clang docs, is the de-facto standard for C++), the structures used by this function to know what to do are documented in [http://mentorembedded.github.io/cxx-abi/exceptions.pdf this] PDF.


=Function stubs=
=Function stubs=
Line 117: Line 119:


* The standard header '''<exception>''', declaring several support functions.
* The standard header '''<exception>''', declaring several support functions.

* http://llvm.org/docs/ExceptionHandling.html (How LLVM/Clang handles C++ exceptions, references the C++ABI and the following document)
* http://mentorembedded.github.io/cxx-abi/exceptions.pdf (A document by HP on C++ exception handling)


[[Category:C++]]
[[Category:C++]]