Skip to content

Commit

Permalink
Reorder frame invoke logic for safety
Browse files Browse the repository at this point in the history
The call stack entry needs to be sufficiently set up before we try to GC
mark it. Sending spesh log entries can cause us to enter GC. Make sure
we have set code_ref and outer before that can ever happen, so that we
don't mark leftover junk pointers.
  • Loading branch information
jnthn committed Jun 29, 2020
1 parent 2b52b73 commit 008d4af
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/core/frame.c
Expand Up @@ -570,6 +570,8 @@ void MVM_frame_invoke(MVMThreadContext *tc, MVMStaticFrame *static_frame,
frame = allocate_frame(tc, static_frame, chosen_cand, 0);
frame->spesh_correlation_id = 0;
}
frame->code_ref = code_ref;
frame->outer = outer;
if (chosen_cand->jitcode) {
chosen_bytecode = chosen_cand->jitcode->bytecode;
frame->jit_entry_label = chosen_cand->jitcode->labels[0];
Expand All @@ -593,6 +595,8 @@ void MVM_frame_invoke(MVMThreadContext *tc, MVMStaticFrame *static_frame,
frame->effective_spesh_slots = NULL;
frame->spesh_correlation_id = 0;
}
frame->code_ref = code_ref;
frame->outer = outer;
chosen_bytecode = static_frame->body.bytecode;

/* If we should be spesh logging, set the correlation ID. */
Expand All @@ -616,12 +620,6 @@ void MVM_frame_invoke(MVMThreadContext *tc, MVMStaticFrame *static_frame,
}
}

/* Store the code ref (NULL at the top-level). */
frame->code_ref = code_ref;

/* Outer. */
frame->outer = outer;

/* Initialize argument processing. */
MVM_args_proc_init(tc, &frame->params, callsite, args);

Expand Down Expand Up @@ -719,6 +717,8 @@ void MVM_frame_dispatch(MVMThreadContext *tc, MVMCode *code, MVMArgs args, MVMin
frame = allocate_frame(tc, static_frame, chosen_cand, 0);
frame->spesh_correlation_id = 0;
}
frame->code_ref = (MVMObject *)code;
frame->outer = outer;
if (chosen_cand->jitcode) {
chosen_bytecode = chosen_cand->jitcode->bytecode;
frame->jit_entry_label = chosen_cand->jitcode->labels[0];
Expand All @@ -742,6 +742,8 @@ void MVM_frame_dispatch(MVMThreadContext *tc, MVMCode *code, MVMArgs args, MVMin
frame->effective_spesh_slots = NULL;
frame->spesh_correlation_id = 0;
}
frame->code_ref = (MVMObject *)code;
frame->outer = outer;
chosen_bytecode = static_frame->body.bytecode;

/* If we should be spesh logging, set the correlation ID. */
Expand All @@ -766,12 +768,6 @@ void MVM_frame_dispatch(MVMThreadContext *tc, MVMCode *code, MVMArgs args, MVMin
}
}

/* Store the code ref (NULL at the top-level). */
frame->code_ref = (MVMObject *)code;

/* Outer. */
frame->outer = outer;

/* Initialize argument processing. */
MVM_args_proc_setup(tc, &(frame->params), args);

Expand Down

0 comments on commit 008d4af

Please sign in to comment.