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 | struct $coroutine * src = ($coroutine *)stop_param;
|
---|
60 | struct $coroutine * dst = src->last;
|
---|
61 |
|
---|
62 | $ctx_switch( src, dst );
|
---|
63 | abort();
|
---|
64 | )
|
---|
65 |
|
---|
66 | extern "C" {
|
---|
67 |
|
---|
68 | struct exception_context_t * this_exception_context(void) {
|
---|
69 | return &__get_stack( active_coroutine() )->exception_context;
|
---|
70 | }
|
---|
71 |
|
---|
72 | _Unwind_Reason_Code __cfaehm_cancellation_unwind( struct _Unwind_Exception * unwind_exception ) {
|
---|
73 | _Unwind_Stop_Fn stop_func;
|
---|
74 | void * stop_param;
|
---|
75 |
|
---|
76 | struct $thread * this_thread = TL_GET( this_thread );
|
---|
77 | if ( &this_thread->self_cor != this_thread->curr_cor ) {
|
---|
78 | struct $coroutine * cor = this_thread->curr_cor;
|
---|
79 | cor->cancellation = unwind_exception;
|
---|
80 |
|
---|
81 | stop_func = coroutine_cancelstop;
|
---|
82 | stop_param = cor;
|
---|
83 | } else if ( mainThread == this_thread ) {
|
---|
84 | stop_func = main_cancelstop;
|
---|
85 | stop_param = (void *)0x22;
|
---|
86 | } else {
|
---|
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 | }
|
---|