[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
|
---|
[c960331] | 12 | // Last Modified On : Wed Oct 28 14:34:00 2020
|
---|
| 13 | // Update Count : 1
|
---|
[d119d613] | 14 | //
|
---|
| 15 |
|
---|
[c960331] | 16 | #define __cforall_thread__
|
---|
[d119d613] | 17 |
|
---|
| 18 | #include "exception.hfa"
|
---|
[c960331] | 19 |
|
---|
[d119d613] | 20 | #include "coroutine.hfa"
|
---|
| 21 |
|
---|
[e84ab3d] | 22 | extern struct thread$ * mainThread;
|
---|
[c960331] | 23 | extern "C" {
|
---|
| 24 | extern void __cfactx_thrd_leave();
|
---|
| 25 | }
|
---|
[d119d613] | 26 |
|
---|
| 27 | // Common pattern for all the stop functions, wait until the end then act.
|
---|
| 28 | #define STOP_AT_END_FUNCTION(NAME, ...) \
|
---|
| 29 | static _Unwind_Reason_Code NAME( \
|
---|
| 30 | int version, \
|
---|
| 31 | _Unwind_Action actions, \
|
---|
| 32 | _Unwind_Exception_Class exception_class, \
|
---|
| 33 | struct _Unwind_Exception * unwind_exception, \
|
---|
| 34 | struct _Unwind_Context * unwind_context, \
|
---|
| 35 | void * stop_param) { \
|
---|
| 36 | verify(actions & _UA_CLEANUP_PHASE); \
|
---|
| 37 | verify(actions & _UA_FORCE_UNWIND); \
|
---|
| 38 | verify(!(actions & _UA_SEARCH_PHASE)); \
|
---|
| 39 | verify(!(actions & _UA_HANDLER_FRAME)); \
|
---|
| 40 | if ( actions & _UA_END_OF_STACK ) { \
|
---|
| 41 | __VA_ARGS__ \
|
---|
| 42 | } else { \
|
---|
| 43 | return _URC_NO_REASON; \
|
---|
| 44 | } \
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | STOP_AT_END_FUNCTION(main_cancelstop,
|
---|
| 48 | abort();
|
---|
| 49 | )
|
---|
| 50 |
|
---|
| 51 | STOP_AT_END_FUNCTION(thread_cancelstop,
|
---|
[342be43] | 52 | __cfactx_thrd_leave();
|
---|
| 53 | __cabi_abort( "Resumed cancelled thread" );
|
---|
[d119d613] | 54 | )
|
---|
| 55 |
|
---|
| 56 | STOP_AT_END_FUNCTION(coroutine_cancelstop,
|
---|
[e84ab3d] | 57 | struct coroutine$ * src = (coroutine$ *)stop_param;
|
---|
| 58 | struct coroutine$ * dst = src->last;
|
---|
[1c01c58] | 59 |
|
---|
| 60 | $ctx_switch( src, dst );
|
---|
[d119d613] | 61 | abort();
|
---|
| 62 | )
|
---|
| 63 |
|
---|
| 64 | extern "C" {
|
---|
| 65 |
|
---|
[c18bf9e] | 66 | struct exception_context_t * this_exception_context(void) libcfa_public {
|
---|
[d119d613] | 67 | return &__get_stack( active_coroutine() )->exception_context;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[c18bf9e] | 70 | _Unwind_Reason_Code __cfaehm_cancellation_unwind( struct _Unwind_Exception * unwind_exception ) libcfa_public {
|
---|
[d119d613] | 71 | _Unwind_Stop_Fn stop_func;
|
---|
| 72 | void * stop_param;
|
---|
| 73 |
|
---|
[e84ab3d] | 74 | struct thread$ * this_thread = active_thread();
|
---|
[d119d613] | 75 | if ( &this_thread->self_cor != this_thread->curr_cor ) {
|
---|
[e84ab3d] | 76 | struct coroutine$ * cor = this_thread->curr_cor;
|
---|
[d119d613] | 77 | cor->cancellation = unwind_exception;
|
---|
| 78 |
|
---|
| 79 | stop_func = coroutine_cancelstop;
|
---|
| 80 | stop_param = cor;
|
---|
| 81 | } else if ( mainThread == this_thread ) {
|
---|
| 82 | stop_func = main_cancelstop;
|
---|
| 83 | stop_param = (void *)0x22;
|
---|
| 84 | } else {
|
---|
[ab8c6a6] | 85 | this_thread->self_cor.cancellation = unwind_exception;
|
---|
| 86 |
|
---|
[d119d613] | 87 | stop_func = thread_cancelstop;
|
---|
| 88 | stop_param = this_thread;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | return _Unwind_ForcedUnwind( unwind_exception, stop_func, stop_param );
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | }
|
---|