From 17a70d25678a0e8f87ec49a993e3180e8d11c6e7 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 11 Nov 2021 18:04:28 -0500 Subject: [PATCH] Null out lastt->ptls after setting current task (pgcstack) This makes it difficult for `usr2_handler` to observe null ptls. --- src/task.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/task.c b/src/task.c index cef294551a6d4..ccab5bded2c33 100644 --- a/src/task.c +++ b/src/task.c @@ -424,18 +424,17 @@ static void ctx_switch(jl_task_t *lastt) else #endif *pt = NULL; // can't fail after here: clear the gc-root for the target task now - lastt->ptls = NULL; } // set up global state for new task and clear global state for old task t->ptls = ptls; jl_atomic_store_relaxed(&ptls->current_task, t); JL_GC_PROMISE_ROOTED(t); + jl_set_pgcstack(&t->gcstack); lastt->ptls = NULL; #ifdef MIGRATE_TASKS ptls->previous_task = lastt; #endif - jl_set_pgcstack(&t->gcstack); if (t->started) { #ifdef COPY_STACKS