@@ -124,19 +124,18 @@ void restore_signals(void)
124124    SetConsoleCtrlHandler (NULL , 0 );
125125}
126126
127- void  jl_throw_in_ctx (jl_value_t  * excpt , PCONTEXT  ctxThread )
127+ void  jl_throw_in_ctx (jl_task_t   * ct ,  jl_value_t  * excpt , PCONTEXT  ctxThread )
128128{
129-     jl_task_t  * ct  =  jl_current_task ;
130-     jl_ptls_t  ptls  =  ct -> ptls ;
131129#if  defined(_CPU_X86_64_ )
132130    DWORD64  Rsp  =  (ctxThread -> Rsp  &  (DWORD64 )- 16 ) -  8 ;
133131#elif  defined(_CPU_X86_ )
134132    DWORD32  Esp  =  (ctxThread -> Esp  &  (DWORD32 )- 16 ) -  4 ;
135133#else 
136134#error  WIN16 not supported :P
137135#endif 
138-     if  (!jl_get_safe_restore ()) {
136+     if  (ct   &&   !jl_get_safe_restore ()) {
139137        assert (excpt  !=  NULL );
138+         jl_ptls_t  ptls  =  ct -> ptls ;
140139        ptls -> bt_size  =  0 ;
141140        if  (excpt  !=  jl_stackovf_exception ) {
142141            ptls -> bt_size  =  rec_backtrace_ctx (ptls -> bt_data , JL_MAX_BT_SIZE , ctxThread ,
@@ -193,7 +192,8 @@ static void jl_try_deliver_sigint(void)
193192            jl_safe_printf ("error: GetThreadContext failed\n" );
194193            return ;
195194        }
196-         jl_throw_in_ctx (jl_interrupt_exception , & ctxThread );
195+         jl_task_t  * ct  =  jl_atomic_load_relaxed (& ptls2 -> current_task );
196+         jl_throw_in_ctx (ct , jl_interrupt_exception , & ctxThread );
197197        ctxThread .ContextFlags  =  CONTEXT_CONTROL  | CONTEXT_INTEGER ;
198198        if  (!SetThreadContext (hMainThread , & ctxThread )) {
199199            jl_safe_printf ("error: SetThreadContext failed\n" );
@@ -237,14 +237,14 @@ LONG WINAPI jl_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo)
237237        case  EXCEPTION_INT_DIVIDE_BY_ZERO :
238238            if  (ct -> eh  !=  NULL ) {
239239                fpreset ();
240-                 jl_throw_in_ctx (jl_diverror_exception , ExceptionInfo -> ContextRecord );
240+                 jl_throw_in_ctx (ct ,  jl_diverror_exception , ExceptionInfo -> ContextRecord );
241241                return  EXCEPTION_CONTINUE_EXECUTION ;
242242            }
243243            break ;
244244        case  EXCEPTION_STACK_OVERFLOW :
245245            if  (ct -> eh  !=  NULL ) {
246246                ptls -> needs_resetstkoflw  =  1 ;
247-                 jl_throw_in_ctx (jl_stackovf_exception , ExceptionInfo -> ContextRecord );
247+                 jl_throw_in_ctx (ct ,  jl_stackovf_exception , ExceptionInfo -> ContextRecord );
248248                return  EXCEPTION_CONTINUE_EXECUTION ;
249249            }
250250            break ;
@@ -259,17 +259,17 @@ LONG WINAPI jl_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo)
259259                }
260260                else  if  (jl_safepoint_consume_sigint ()) {
261261                    jl_clear_force_sigint ();
262-                     jl_throw_in_ctx (jl_interrupt_exception , ExceptionInfo -> ContextRecord );
262+                     jl_throw_in_ctx (ct ,  jl_interrupt_exception , ExceptionInfo -> ContextRecord );
263263                }
264264                return  EXCEPTION_CONTINUE_EXECUTION ;
265265            }
266266            if  (jl_get_safe_restore ()) {
267-                 jl_throw_in_ctx (NULL , ExceptionInfo -> ContextRecord );
267+                 jl_throw_in_ctx (NULL , NULL ,  ExceptionInfo -> ContextRecord );
268268                return  EXCEPTION_CONTINUE_EXECUTION ;
269269            }
270270            if  (ct -> eh  !=  NULL ) {
271271                if  (ExceptionInfo -> ExceptionRecord -> ExceptionInformation [0 ] ==  1 ) { // writing to read-only memory (e.g. mmap) 
272-                     jl_throw_in_ctx (jl_readonlymemory_exception , ExceptionInfo -> ContextRecord );
272+                     jl_throw_in_ctx (ct ,  jl_readonlymemory_exception , ExceptionInfo -> ContextRecord );
273273                    return  EXCEPTION_CONTINUE_EXECUTION ;
274274                }
275275            }
0 commit comments