| [d119d613] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
|  | 7 | // exception.cfa -- Exceptions in a concurrent environment. | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // Author           : Andrew Beach | 
|---|
|  | 10 | // Created On       : Mon Aug 17 10:41:00 2020 | 
|---|
|  | 11 | // Last Modified By : Andrew Beach | 
|---|
|  | 12 | // Last Modified On : Tue Aug 25 14:41:00 2020 | 
|---|
|  | 13 | // Update Count     : 0 | 
|---|
|  | 14 | // | 
|---|
|  | 15 |  | 
|---|
|  | 16 | extern "C" { | 
|---|
|  | 17 | // use this define to make unwind.h play nice, definitely a hack | 
|---|
|  | 18 | #define HIDE_EXPORTS | 
|---|
|  | 19 | #include <unwind.h> | 
|---|
|  | 20 | #undef HIDE_EXPORTS | 
|---|
|  | 21 | } | 
|---|
|  | 22 |  | 
|---|
|  | 23 | #include "invoke.h" | 
|---|
|  | 24 | #include "exception.hfa" | 
|---|
|  | 25 | #include "coroutine.hfa" | 
|---|
|  | 26 |  | 
|---|
|  | 27 | extern struct $thread * mainThread; | 
|---|
|  | 28 |  | 
|---|
|  | 29 | // Common pattern for all the stop functions, wait until the end then act. | 
|---|
|  | 30 | #define STOP_AT_END_FUNCTION(NAME, ...) \ | 
|---|
|  | 31 | static _Unwind_Reason_Code NAME( \ | 
|---|
|  | 32 | int version, \ | 
|---|
|  | 33 | _Unwind_Action actions, \ | 
|---|
|  | 34 | _Unwind_Exception_Class exception_class, \ | 
|---|
|  | 35 | struct _Unwind_Exception * unwind_exception, \ | 
|---|
|  | 36 | struct _Unwind_Context * unwind_context, \ | 
|---|
|  | 37 | void * stop_param) { \ | 
|---|
|  | 38 | verify(actions & _UA_CLEANUP_PHASE); \ | 
|---|
|  | 39 | verify(actions & _UA_FORCE_UNWIND); \ | 
|---|
|  | 40 | verify(!(actions & _UA_SEARCH_PHASE)); \ | 
|---|
|  | 41 | verify(!(actions & _UA_HANDLER_FRAME)); \ | 
|---|
|  | 42 | if ( actions & _UA_END_OF_STACK ) { \ | 
|---|
|  | 43 | __VA_ARGS__ \ | 
|---|
|  | 44 | } else { \ | 
|---|
|  | 45 | return _URC_NO_REASON; \ | 
|---|
|  | 46 | } \ | 
|---|
|  | 47 | } | 
|---|
|  | 48 |  | 
|---|
|  | 49 | STOP_AT_END_FUNCTION(main_cancelstop, | 
|---|
|  | 50 | abort(); | 
|---|
|  | 51 | ) | 
|---|
|  | 52 |  | 
|---|
|  | 53 | STOP_AT_END_FUNCTION(thread_cancelstop, | 
|---|
|  | 54 | // TODO: Instead pass information to the joiner. | 
|---|
|  | 55 | abort(); | 
|---|
|  | 56 | ) | 
|---|
|  | 57 |  | 
|---|
|  | 58 | STOP_AT_END_FUNCTION(coroutine_cancelstop, | 
|---|
|  | 59 | // TODO: Instead pass information to the last resumer. | 
|---|
|  | 60 | abort(); | 
|---|
|  | 61 | ) | 
|---|
|  | 62 |  | 
|---|
|  | 63 | extern "C" { | 
|---|
|  | 64 |  | 
|---|
|  | 65 | struct exception_context_t * this_exception_context(void) { | 
|---|
|  | 66 | return &__get_stack( active_coroutine() )->exception_context; | 
|---|
|  | 67 | } | 
|---|
|  | 68 |  | 
|---|
|  | 69 | _Unwind_Reason_Code __cfaehm_cancellation_unwind( struct _Unwind_Exception * unwind_exception ) { | 
|---|
|  | 70 | _Unwind_Stop_Fn stop_func; | 
|---|
|  | 71 | void * stop_param; | 
|---|
|  | 72 |  | 
|---|
|  | 73 | struct $thread * this_thread = TL_GET( this_thread ); | 
|---|
|  | 74 | if ( &this_thread->self_cor != this_thread->curr_cor ) { | 
|---|
|  | 75 | struct $coroutine * cor = this_thread->curr_cor; | 
|---|
|  | 76 | cor->cancellation = unwind_exception; | 
|---|
|  | 77 |  | 
|---|
|  | 78 | stop_func = coroutine_cancelstop; | 
|---|
|  | 79 | stop_param = cor; | 
|---|
|  | 80 | } else if ( mainThread == this_thread ) { | 
|---|
|  | 81 | stop_func = main_cancelstop; | 
|---|
|  | 82 | stop_param = (void *)0x22; | 
|---|
|  | 83 | } else { | 
|---|
|  | 84 | stop_func = thread_cancelstop; | 
|---|
|  | 85 | stop_param = this_thread; | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 | return _Unwind_ForcedUnwind( unwind_exception, stop_func, stop_param ); | 
|---|
|  | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | } | 
|---|