Ignore:
Timestamp:
May 24, 2019, 10:19:41 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/invoke.c

    r6a9d4b4 r933f32f  
    2828
    2929extern void __suspend_internal(void);
    30 extern void __leave_coroutine(void);
    31 extern void __finish_creation(void);
     30extern void __leave_coroutine( struct coroutine_desc * );
     31extern void __finish_creation( struct thread_desc * );
    3232extern void __leave_thread_monitor( struct thread_desc * this );
    3333extern void disable_interrupts();
     
    4747        cor->state = Active;
    4848
    49         enable_interrupts( __cfaabi_dbg_ctx );
    50 
    5149        main( this );
    5250
    5351        //Final suspend, should never return
    54         __leave_coroutine();
     52        __leave_coroutine( cor );
    5553        __cabi_abort( "Resumed dead coroutine" );
    5654}
     
    6260        __attribute((__unused__)) struct _Unwind_Exception * unwind_exception,
    6361        __attribute((__unused__)) struct _Unwind_Context * context,
    64         __attribute((__unused__)) void * param
     62        void * param
    6563) {
    6664        if( actions & _UA_END_OF_STACK  ) {
    6765                // We finished unwinding the coroutine,
    6866                // leave it
    69                 __leave_coroutine();
     67                __leave_coroutine( param );
    7068                __cabi_abort( "Resumed dead coroutine" );
    7169        }
     
    7573}
    7674
    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 );
     75void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc * cor) __attribute__ ((__noreturn__));
     76void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc * cor) {
     77        _Unwind_Reason_Code ret = _Unwind_ForcedUnwind( storage, _CtxCoroutine_UnwindStop, cor );
    8078        printf("UNWIND ERROR %d after force unwind\n", ret);
    8179        abort();
     
    8886        void *this
    8987) {
     88        // Fetch the thread handle from the user defined thread structure
     89        struct thread_desc* thrd = get_thread( this );
     90
    9091        // First suspend, once the thread arrives here,
    9192        // 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 );
    9794
    9895        // Officially start the thread by enabling preemption
     
    120117        void (*invoke)(void *)
    121118) {
    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;
    123121
    124122#if defined( __i386 )
    125123
    126124        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)
    130126            void *rturn;                          // where to go on return from uSwitch
    131             void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
    132             void *argument[3];                          // for 16-byte ABI, 16-byte alignment starts here
    133             void *padding;                              // padding to force 16-byte alignment, as "base" is 16-byte aligned
     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
    134130        };
    135131
    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 fp
     132        cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
     133        cor->context.FP = NULL;         // terminate stack with NULL fp
    138134
    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-520
    143         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
     135        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;
    144140
    145141#elif defined( __x86_64 )
     
    147143        struct FakeStack {
    148144                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)
    151145                void *rturn;                        // where to go on return from uSwitch
    152146                void *dummyReturn;                  // NULL return address to provide proper alignment
    153147        };
    154148
    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 fp
     149        cor->context.SP = (char *)stack->base - sizeof( struct FakeStack );
     150        cor->context.FP = NULL;         // terminate stack with NULL fp
    157151
    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-520
    163         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
     152        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;
    164158
    165159#elif defined( __ARM_ARCH )
     
    171165        };
    172166
    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;
    175169
    176         struct FakeStack *fs = (struct FakeStack *)((struct machine_context_t *)stack->context)->SP;
     170        struct FakeStack *fs = (struct FakeStack *)cor->context.SP;
    177171
    178172        fs->intRegs[8] = CtxInvokeStub;
Note: See TracChangeset for help on using the changeset viewer.