Changeset 933f32f for libcfa/src/concurrency/invoke.c
- Timestamp:
- May 24, 2019, 10:19:41 AM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d908563
- Parents:
- 6a9d4b4 (diff), 292642a (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/invoke.c
r6a9d4b4 r933f32f 28 28 29 29 extern void __suspend_internal(void); 30 extern void __leave_coroutine( void);31 extern void __finish_creation( void);30 extern void __leave_coroutine( struct coroutine_desc * ); 31 extern void __finish_creation( struct thread_desc * ); 32 32 extern void __leave_thread_monitor( struct thread_desc * this ); 33 33 extern void disable_interrupts(); … … 47 47 cor->state = Active; 48 48 49 enable_interrupts( __cfaabi_dbg_ctx );50 51 49 main( this ); 52 50 53 51 //Final suspend, should never return 54 __leave_coroutine( );52 __leave_coroutine( cor ); 55 53 __cabi_abort( "Resumed dead coroutine" ); 56 54 } … … 62 60 __attribute((__unused__)) struct _Unwind_Exception * unwind_exception, 63 61 __attribute((__unused__)) struct _Unwind_Context * context, 64 __attribute((__unused__))void * param62 void * param 65 63 ) { 66 64 if( actions & _UA_END_OF_STACK ) { 67 65 // We finished unwinding the coroutine, 68 66 // leave it 69 __leave_coroutine( );67 __leave_coroutine( param ); 70 68 __cabi_abort( "Resumed dead coroutine" ); 71 69 } … … 75 73 } 76 74 77 void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage ) __attribute__ ((__noreturn__));78 void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage ) {79 _Unwind_Reason_Code ret = _Unwind_ForcedUnwind( storage, _CtxCoroutine_UnwindStop, NULL);75 void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc * cor) __attribute__ ((__noreturn__)); 76 void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc * cor) { 77 _Unwind_Reason_Code ret = _Unwind_ForcedUnwind( storage, _CtxCoroutine_UnwindStop, cor ); 80 78 printf("UNWIND ERROR %d after force unwind\n", ret); 81 79 abort(); … … 88 86 void *this 89 87 ) { 88 // Fetch the thread handle from the user defined thread structure 89 struct thread_desc* thrd = get_thread( this ); 90 90 91 // First suspend, once the thread arrives here, 91 92 // the function pointer to main can be invalidated without risk 92 __finish_creation(); 93 94 // Fetch the thread handle from the user defined thread structure 95 struct thread_desc* thrd = get_thread( this ); 96 thrd->self_cor.last = NULL; 93 __finish_creation( thrd ); 97 94 98 95 // Officially start the thread by enabling preemption … … 120 117 void (*invoke)(void *) 121 118 ) { 122 struct coStack_t* stack = &get_coroutine( this )->stack; 119 struct coroutine_desc * cor = get_coroutine( this ); 120 struct __stack_t * stack = cor->stack.storage; 123 121 124 122 #if defined( __i386 ) 125 123 126 124 struct FakeStack { 127 void *fixedRegisters[3]; // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant) 128 uint32_t mxcr; // SSE Status and Control bits (control bits are preserved across function calls) 129 uint16_t fcw; // X97 FPU control word (preserved across function calls) 125 void *fixedRegisters[3]; // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant) 130 126 void *rturn; // where to go on return from uSwitch 131 void *dummyReturn; 132 void *argument[3]; 133 void *padding; 127 void *dummyReturn; // fake return compiler would have pushed on call to uInvoke 128 void *argument[3]; // for 16-byte ABI, 16-byte alignment starts here 129 void *padding; // padding to force 16-byte alignment, as "base" is 16-byte aligned 134 130 }; 135 131 136 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );137 ((struct machine_context_t *)stack->context)->FP = NULL; // terminate stack with NULL fp132 cor->context.SP = (char *)stack->base - sizeof( struct FakeStack ); 133 cor->context.FP = NULL; // terminate stack with NULL fp 138 134 139 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;140 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this; // argument to invoke 141 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;142 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520143 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7135 struct FakeStack *fs = (struct FakeStack *)cor->context.SP; 136 137 fs->dummyReturn = NULL; 138 fs->argument[0] = this; // argument to invoke 139 fs->rturn = invoke; 144 140 145 141 #elif defined( __x86_64 ) … … 147 143 struct FakeStack { 148 144 void *fixedRegisters[5]; // fixed registers rbx, r12, r13, r14, r15 149 uint32_t mxcr; // SSE Status and Control bits (control bits are preserved across function calls)150 uint16_t fcw; // X97 FPU control word (preserved across function calls)151 145 void *rturn; // where to go on return from uSwitch 152 146 void *dummyReturn; // NULL return address to provide proper alignment 153 147 }; 154 148 155 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );156 ((struct machine_context_t *)stack->context)->FP = NULL; // terminate stack with NULL fp149 cor->context.SP = (char *)stack->base - sizeof( struct FakeStack ); 150 cor->context.FP = NULL; // terminate stack with NULL fp 157 151 158 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;159 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = CtxInvokeStub; 160 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this;161 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke;162 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520163 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7152 struct FakeStack *fs = (struct FakeStack *)cor->context.SP; 153 154 fs->dummyReturn = NULL; 155 fs->rturn = CtxInvokeStub; 156 fs->fixedRegisters[0] = this; 157 fs->fixedRegisters[1] = invoke; 164 158 165 159 #elif defined( __ARM_ARCH ) … … 171 165 }; 172 166 173 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );174 ((struct machine_context_t *)stack->context)->FP = NULL;167 cor->context.SP = (char *)stack->base - sizeof( struct FakeStack ); 168 cor->context.FP = NULL; 175 169 176 struct FakeStack *fs = (struct FakeStack *) ((struct machine_context_t *)stack->context)->SP;170 struct FakeStack *fs = (struct FakeStack *)cor->context.SP; 177 171 178 172 fs->intRegs[8] = CtxInvokeStub;
Note:
See TracChangeset
for help on using the changeset viewer.