Exception Handling ABI for the ARM Architecture
Exception Handling ABI for the ARM Architecture
Exception Handling ABI for the ARM Architecture
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Exception</strong> handling <strong>ABI</strong> <strong>for</strong> <strong>the</strong> <strong>ARM</strong> architecture<br />
12 APPENDIX B: EXAMPLE C++ LANGUAGE IMPLEMENTATION<br />
This section is <strong>for</strong> illustration only and <strong>the</strong> actual <strong>ARM</strong> implementation may deviate without notice from <strong>the</strong> details<br />
presented here.<br />
12.1 <strong>Exception</strong> Control Object<br />
At <strong>the</strong> time of writing, <strong>the</strong> following structure is used by <strong>the</strong> <strong>ARM</strong> C++ implementation.<br />
struct __cxa_exception {<br />
const std::type_info *exceptionType; // RTTI object describing <strong>the</strong> type of <strong>the</strong> exception<br />
void (*exceptionDestructor)(void *); // Destructor <strong>for</strong> <strong>the</strong> exception object (may be NULL)<br />
unexpected_handler unexpectedHandler; // Handler in <strong>for</strong>ce after evaluating throw expr<br />
terminate_handler terminateHandler; // Handler in <strong>for</strong>ce after evaluating throw expr<br />
__cxa_exception *nextCaught<strong>Exception</strong>; // Chain of "currently caught" c++ exception objects<br />
uint32_t handlerCount;<br />
// Count of how many handlers this EO is "caught" in<br />
__cxa_exception *nextPropagating<strong>Exception</strong>; // Chain of objects saved over cleanup<br />
uint32_t propagationCount;<br />
// Count of live propagations(throws) of this EO<br />
_Unwind_Control_Block ucb;<br />
// Forces alignment of next item to 8-byte boundary<br />
};<br />
A complete C++ exception object consists of a __cxa_exception followed by <strong>the</strong> C++ exception object (EO) itself.<br />
Type __cxa_exception includes <strong>the</strong> LEO members required <strong>for</strong> housekeeping by <strong>the</strong> C++ implementation, and <strong>the</strong><br />
unwinding control block (UCB—see §7.2).<br />
12.2 Per-thread global memory<br />
The __cxa_eh_globals structure records <strong>the</strong> per-thread handlers set by std::set_terminate() and<br />
std::set_unexpected(), and contains o<strong>the</strong>r fields needed by <strong>the</strong> implementation.<br />
typedef void (*handler)(void);<br />
typedef void (*terminate_handler)(void);<br />
typedef void (*unexpected_handler)(void);<br />
struct __cxa_eh_globals {<br />
uint32_t uncaught<strong>Exception</strong>s;<br />
// counter<br />
unexpected_handler unexpectedHandler; // per-thread handler<br />
terminate_handler terminateHandler; // per-thread handler<br />
bool implementation_ever_called_terminate; // true if it ever did<br />
handler call_hook;<br />
// transient field <strong>for</strong> terminate/unexpected call hook<br />
__cxa_exception *caught<strong>Exception</strong>s;<br />
// chain of "caught" exceptions<br />
__cxa_exception *propagating<strong>Exception</strong>s; // chain of "propagating"(in cleanup) exceptions<br />
void *emergency_buffer;<br />
// <strong>for</strong> when rest of heap full<br />
};<br />
__cxa_eh_globals contains <strong>the</strong> following fields:<br />
<br />
<br />
<br />
<br />
uncaught<strong>Exception</strong>s is a count of C++ exceptions which are active but not in <strong>the</strong> caught state (in <strong>the</strong> technical<br />
meaning of <strong>the</strong> C++ Standard).<br />
UnexpectedHandler and terminateHandler are <strong>the</strong> current (per-thread) handlers set by std::set_unexpected()<br />
and std::set_terminate() respectively.<br />
implementation_ever_called_terminate is true if <strong>the</strong> unwind mechanism ever called terminate(). We believe<br />
this is required <strong>for</strong> correct implementation of std::uncaught_exception(). See §11 <strong>for</strong> a lengthy discussion).<br />
call_hook is set by <strong>the</strong> implementation to <strong>the</strong> handler it wants std::terminate() or std::unexpected() to call.<br />
<strong>ARM</strong> IHI 0038A Copyright © 2002-2005, 2007 <strong>ARM</strong> Limited. All rights reserved. Page 48 of 50