Changes in libcfa/src/exception.c [8ad5752:979df46]
- File:
-
- 1 edited
-
libcfa/src/exception.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/exception.c
r8ad5752 r979df46 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T hr May 21 12:18:00 202013 // Update Count : 2012 // Last Modified On : Tue Apr 14 12:01:00 2020 13 // Update Count : 18 14 14 // 15 15 … … 80 80 } 81 81 82 void __cfaehm_throw_resume(exception_t * except , void (*defaultHandler)(exception_t *)) {82 void __cfaehm_throw_resume(exception_t * except) { 83 83 struct exception_context_t * context = this_exception_context(); 84 84 … … 96 96 } 97 97 98 // No handler found, fall back to the default operation.99 98 __cfadbg_print_safe(exception, "Unhandled exception\n"); 100 defaultHandler(except); 99 100 // Fall back to termination: 101 __cfaehm_throw_terminate(except); 102 // TODO: Default handler for resumption. 101 103 } 102 104 … … 237 239 } 238 240 239 static void __cfaehm_cleanup_default( exception_t ** except ) {240 __cfaehm_delete_exception( *except );241 *except = NULL;242 }243 244 241 // The exception that is being thrown must already be stored. 245 static void __cfaehm_begin_unwind(void(*defaultHandler)(exception_t *)) { 246 struct exception_context_t * context = this_exception_context(); 247 struct _Unwind_Exception * storage = &this_exception_storage; 248 if ( NULL == context->current_exception ) { 242 static __attribute__((noreturn)) void __cfaehm_begin_unwind(void) { 243 if ( ! this_exception_context()->current_exception ) { 249 244 printf("UNWIND ERROR missing exception in begin unwind\n"); 250 245 abort(); … … 252 247 253 248 // Call stdlibc to raise the exception 254 __cfadbg_print_safe(exception, "Begin unwinding (storage &p, context %p)\n", storage, context); 255 _Unwind_Reason_Code ret = _Unwind_RaiseException( storage ); 249 _Unwind_Reason_Code ret = _Unwind_RaiseException( &this_exception_storage ); 256 250 257 251 // If we reach here it means something happened. For resumption to work we need to find a way … … 262 256 // the whole stack. 263 257 258 // No handler found, go to the default operation. 259 // Currently this will always be a cancellation. 260 if ( ret == _URC_END_OF_STACK ) { 261 __cfadbg_print_safe(exception, "Uncaught exception %p\n", &this_exception_storage); 262 263 __cfaehm_cancel_stack(this_exception_context()->current_exception); 264 } 265 264 266 // We did not simply reach the end of the stack without finding a handler. This is an error. 265 if ( ret != _URC_END_OF_STACK ) { 266 printf("UNWIND ERROR %d after raise exception\n", ret); 267 abort(); 268 } 269 270 // No handler found, go to the default operation. 271 __cfadbg_print_safe(exception, "Uncaught exception %p\n", storage); 272 273 __attribute__((cleanup(__cfaehm_cleanup_default))) 274 exception_t * exception = context->current_exception; 275 defaultHandler( exception ); 276 } 277 278 void __cfaehm_throw_terminate( exception_t * val, void (*defaultHandler)(exception_t *) ) { 267 printf("UNWIND ERROR %d after raise exception\n", ret); 268 abort(); 269 } 270 271 void __cfaehm_throw_terminate( exception_t * val ) { 279 272 __cfadbg_print_safe(exception, "Throwing termination exception\n"); 280 273 281 274 __cfaehm_allocate_exception( val ); 282 __cfaehm_begin_unwind( defaultHandler ); 283 } 284 285 static __attribute__((noreturn)) void __cfaehm_rethrow_adapter( exception_t * except ) { 286 // TODO: Print some error message. 287 (void)except; 288 abort(); 275 __cfaehm_begin_unwind(); 289 276 } 290 277 … … 292 279 __cfadbg_print_safe(exception, "Rethrowing termination exception\n"); 293 280 294 __cfaehm_begin_unwind( __cfaehm_rethrow_adapter ); 295 abort(); 281 __cfaehm_begin_unwind(); 296 282 } 297 283
Note:
See TracChangeset
for help on using the changeset viewer.