- Timestamp:
- May 21, 2020, 5:06:35 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 0e4df2e, 7119daa
- Parents:
- 6f121b8 (diff), 66ba544 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- libcfa/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/exception.c
r6f121b8 r99fea48 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T ue Apr 14 12:01:00 202013 // Update Count : 1812 // Last Modified On : Thr May 21 12:18:00 2020 13 // Update Count : 20 14 14 // 15 15 … … 80 80 } 81 81 82 void __cfaehm_throw_resume(exception_t * except ) {82 void __cfaehm_throw_resume(exception_t * except, void (*defaultHandler)(exception_t *)) { 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. 98 99 __cfadbg_print_safe(exception, "Unhandled exception\n"); 99 100 // Fall back to termination: 101 __cfaehm_throw_terminate(except); 102 // TODO: Default handler for resumption. 100 defaultHandler(except); 103 101 } 104 102 … … 239 237 } 240 238 239 static void __cfaehm_cleanup_default( exception_t ** except ) { 240 __cfaehm_delete_exception( *except ); 241 *except = NULL; 242 } 243 241 244 // The exception that is being thrown must already be stored. 242 static __attribute__((noreturn)) void __cfaehm_begin_unwind(void) { 243 if ( ! this_exception_context()->current_exception ) { 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 ) { 244 249 printf("UNWIND ERROR missing exception in begin unwind\n"); 245 250 abort(); … … 247 252 248 253 // Call stdlibc to raise the exception 249 _Unwind_Reason_Code ret = _Unwind_RaiseException( &this_exception_storage ); 254 __cfadbg_print_safe(exception, "Begin unwinding (storage &p, context %p)\n", storage, context); 255 _Unwind_Reason_Code ret = _Unwind_RaiseException( storage ); 250 256 251 257 // If we reach here it means something happened. For resumption to work we need to find a way … … 256 262 // the whole stack. 257 263 264 // 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 258 270 // 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 266 // We did not simply reach the end of the stack without finding a handler. This is an error. 267 printf("UNWIND ERROR %d after raise exception\n", ret); 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 *) ) { 279 __cfadbg_print_safe(exception, "Throwing termination exception\n"); 280 281 __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; 268 288 abort(); 269 }270 271 void __cfaehm_throw_terminate( exception_t * val ) {272 __cfadbg_print_safe(exception, "Throwing termination exception\n");273 274 __cfaehm_allocate_exception( val );275 __cfaehm_begin_unwind();276 289 } 277 290 … … 279 292 __cfadbg_print_safe(exception, "Rethrowing termination exception\n"); 280 293 281 __cfaehm_begin_unwind(); 294 __cfaehm_begin_unwind( __cfaehm_rethrow_adapter ); 295 abort(); 282 296 } 283 297 -
libcfa/src/exception.h
r6f121b8 r99fea48 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Mar 27 10:16:00 202013 // Update Count : 912 // Last Modified On : Tue May 19 14:17:00 2020 13 // Update Count : 10 14 14 // 15 15 … … 41 41 42 42 // Used in throw statement translation. 43 void __cfaehm_throw_terminate(exception_t * except ) __attribute__((noreturn));43 void __cfaehm_throw_terminate(exception_t * except, void (*)(exception_t *)); 44 44 void __cfaehm_rethrow_terminate() __attribute__((noreturn)); 45 void __cfaehm_throw_resume(exception_t * except );45 void __cfaehm_throw_resume(exception_t * except, void (*)(exception_t *)); 46 46 47 47 // Function catches termination exceptions. … … 72 72 #ifdef __cforall 73 73 } 74 75 // Not all the built-ins can be expressed in C. These can't be 76 // implemented in the .c file either so they all have to be inline. 77 78 trait is_exception(dtype T) { 79 /* The first field must be a pointer to a virtual table. 80 * That virtual table must be a decendent of the base exception virtual tab$ 81 */ 82 void mark_exception(T *); 83 // This is never used and should be a no-op. 84 }; 85 86 trait is_termination_exception(dtype T | is_exception(T)) { 87 void defaultTerminationHandler(T &); 88 }; 89 90 trait is_resumption_exception(dtype T | is_exception(T)) { 91 void defaultResumptionHandler(T &); 92 }; 93 94 forall(dtype T | is_termination_exception(T)) 95 static inline void $throw(T & except) { 96 __cfaehm_throw_terminate( 97 (exception_t *)&except, 98 (void(*)(exception_t *))defaultTerminationHandler 99 ); 100 } 101 102 forall(dtype T | is_resumption_exception(T)) 103 static inline void $throwResume(T & except) { 104 __cfaehm_throw_resume( 105 (exception_t *)&except, 106 (void(*)(exception_t *))defaultResumptionHandler 107 ); 108 } 109 110 forall(dtype T | is_exception(T)) 111 static inline void cancel_stack(T & except) __attribute__((noreturn)) { 112 __cfaehm_cancel_stack( (exception_t *)&except ); 113 } 114 115 forall(dtype T | is_exception(T)) 116 static inline void defaultTerminationHandler(T & except) { 117 return cancel_stack( except ); 118 } 119 120 forall(dtype T | is_exception(T)) 121 static inline void defaultResumptionHandler(T & except) { 122 throw except; 123 } 124 74 125 #endif -
libcfa/src/exception.hfa
r6f121b8 r99fea48 10 10 // Created On : Thu Apr 7 10:25:00 2020 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Apr 13 15:42:00 202013 // Update Count : 112 // Last Modified On : Tue May 19 14:17:00 2020 13 // Update Count : 2 14 14 // 15 16 trait is_exception(dtype T) {17 // The trait system can't describe the actual constrants.18 // Unused, should always be a no-op.19 void mark_exception(T *);20 };21 22 forall(dtype T | is_exception(T))23 inline void cancel_stack(T & except) __attribute__((noreturn)) {24 __cfaehm_cancel_stack( (exception_t *)&except );25 }26 15 27 16 // Everything below this line should be considered a patch while the exception
Note:
See TracChangeset
for help on using the changeset viewer.