Index: libcfa/src/exception.c
===================================================================
--- libcfa/src/exception.c	(revision 44a88528ab92f767c947afc0734ebe29ab080f0d)
+++ libcfa/src/exception.c	(revision 2a3b019aa0163c7f5574a142e8a058af99a7fa71)
@@ -63,12 +63,7 @@
 // There can be a single global until multithreading occurs, then each stack
 // needs its own. It will have to be updated to handle that.
-struct exception_context_t * this_exception_context() {
+inline static struct exception_context_t * this_exception_context() {
 	return &shared_stack;
 }
-//#define SAVE_EXCEPTION_CONTEXT(to_name)
-//struct exception_context_t * to_name = this_exception_context();
-//exception * this_exception() {
-//    return this_exception_context()->current_exception;
-//}
 
 
@@ -76,15 +71,16 @@
 
 void __cfaabi_ehm__throw_resume(exception_t * except) {
+	struct exception_context_t * context = this_exception_context();
 
 	__cfaabi_dbg_print_safe("Throwing resumption exception\n");
 
-	struct __cfaabi_ehm__try_resume_node * original_head = shared_stack.current_resume;
+	struct __cfaabi_ehm__try_resume_node * original_head = context->current_resume;
 	struct __cfaabi_ehm__try_resume_node * current =
-		(original_head) ? original_head->next : shared_stack.top_resume;
+		(original_head) ? original_head->next : context->top_resume;
 
 	for ( ; current ; current = current->next) {
-		shared_stack.current_resume = current;
+		context->current_resume = current;
 		if (current->handler(except)) {
-			shared_stack.current_resume = original_head;
+			context->current_resume = original_head;
 			return;
 		}
@@ -92,5 +88,5 @@
 
 	__cfaabi_dbg_print_safe("Unhandled exception\n");
-	shared_stack.current_resume = original_head;
+	context->current_resume = original_head;
 
 	// Fall back to termination:
@@ -105,11 +101,13 @@
 void __cfaabi_ehm__try_resume_setup(struct __cfaabi_ehm__try_resume_node * node,
                         _Bool (*handler)(exception_t * except)) {
-	node->next = shared_stack.top_resume;
+	struct exception_context_t * context = this_exception_context();
+	node->next = context->top_resume;
 	node->handler = handler;
-	shared_stack.top_resume = node;
+	context->top_resume = node;
 }
 
 void __cfaabi_ehm__try_resume_cleanup(struct __cfaabi_ehm__try_resume_node * node) {
-	shared_stack.top_resume = node->next;
+	struct exception_context_t * context = this_exception_context();
+	context->top_resume = node->next;
 }
 
@@ -191,6 +189,6 @@
 		_Unwind_Exception_Class exceptionClass,
 		struct _Unwind_Exception * unwind_exception,
-		struct _Unwind_Context * context,
-		void * some_param) {
+		struct _Unwind_Context * unwind_context,
+		void * stop_param) {
 	if( actions & _UA_END_OF_STACK  ) exit(1);
 	if( actions & _UA_CLEANUP_PHASE ) return _URC_NO_REASON;
@@ -251,10 +249,10 @@
 		int version, _Unwind_Action actions, unsigned long long exceptionClass,
 		struct _Unwind_Exception* unwind_exception,
-		struct _Unwind_Context* context)
+		struct _Unwind_Context* unwind_context)
 {
 
 	//__cfaabi_dbg_print_safe("CFA: 0x%lx\n", _Unwind_GetCFA(context));
 	__cfaabi_dbg_print_safe("Personality function (%d, %x, %llu, %p, %p):",
-			version, actions, exceptionClass, unwind_exception, context);
+			version, actions, exceptionClass, unwind_exception, unwind_context);
 
 	// If we've reached the end of the stack then there is nothing much we can do...
@@ -274,5 +272,5 @@
 
 	// Get a pointer to the language specific data from which we will read what we need
-	const unsigned char * lsd = (const unsigned char*) _Unwind_GetLanguageSpecificData( context );
+	const unsigned char * lsd = (const unsigned char*) _Unwind_GetLanguageSpecificData( unwind_context );
 
 	if( !lsd ) {	//Nothing to do, keep unwinding
@@ -283,6 +281,8 @@
 	// Get the instuction pointer and a reading pointer into the exception table
 	lsda_header_info lsd_info;
-	const unsigned char * cur_ptr = parse_lsda_header(context, lsd, &lsd_info);
-	_Unwind_Ptr instruction_ptr = _Unwind_GetIP( context );
+	const unsigned char * cur_ptr = parse_lsda_header(unwind_context, lsd, &lsd_info);
+	_Unwind_Ptr instruction_ptr = _Unwind_GetIP(unwind_context);
+
+	struct exception_context_t * context = this_exception_context();
 
 	// Linearly search the table for stuff to do
@@ -321,5 +321,8 @@
 
 		// Something to do?
-		if( callsite_landing_pad ) {
+		if ( 0 == callsite_landing_pad ) {
+			// Nothing to do, move along
+			__cfaabi_dbg_print_safe(" no landing pad");
+		} else {
 			// Which phase are we in
 			if (actions & _UA_SEARCH_PHASE) {
@@ -348,14 +351,14 @@
 
 #					if defined( __x86_64 )
-					_Unwind_Word match_pos = _Unwind_GetCFA(context) + 8;
+					_Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 8;
 #					elif defined( __i386 )
-					_Unwind_Word match_pos = _Unwind_GetCFA(context) + 24;
+					_Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 24;
 #					endif
 					int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos;
 
-					int index = matcher(shared_stack.current_exception);
+					int index = matcher(context->current_exception);
 					_Unwind_Reason_Code ret = (0 == index)
 						? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
-					shared_stack.current_handler_index = index;
+					context->current_handler_index = index;
 
 					// Based on the return value, check if we matched the exception
@@ -382,10 +385,11 @@
 				// We need to run some clean-up or a handler
 				// These statment do the right thing but I don't know any specifics at all
-				_Unwind_SetGR( context, __builtin_eh_return_data_regno(0), (_Unwind_Ptr) unwind_exception );
-				_Unwind_SetGR( context, __builtin_eh_return_data_regno(1), 0 );
+				_Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(0),
+					(_Unwind_Ptr)unwind_exception );
+				_Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(1), 0 );
 
 				// I assume this sets the instruction pointer to the adress of the landing pad
 				// It doesn't actually set it, it only state the value that needs to be set once we return _URC_INSTALL_CONTEXT
-				_Unwind_SetIP( context, ((lsd_info.LPStart) + (callsite_landing_pad)) );
+				_Unwind_SetIP( unwind_context, ((lsd_info.LPStart) + (callsite_landing_pad)) );
 
 				__cfaabi_dbg_print_safe(" action\n");
@@ -395,7 +399,4 @@
 			}
 		}
-
-		// Nothing to do, move along
-		__cfaabi_dbg_print_safe(" no landing pad");
 	}
 	// No handling found
@@ -457,6 +458,7 @@
 
 	// Exception handler
-	catch_block( shared_stack.current_handler_index,
-	             shared_stack.current_exception );
+	// Note: Saving the exception context on the stack breaks termination exceptions.
+	catch_block( this_exception_context()->current_handler_index,
+	             this_exception_context()->current_exception );
 }
 
