Skip to content

Commit

Permalink
Fix segfaults after callbacks originating in JIT compiled calls to na…
Browse files Browse the repository at this point in the history
…tive code

Before running a non-toplevel frame, we need to make sure, the caller's frame
has a valid return_address. While MVM_nativecall_invoke_jit and
MVM_nativecall_invoke did so, the JIT implementation of calls to JIT compiled
native functions did not. This could lead to segfaults when native code called
from JIT compiled code ran callbacks which then tried to return to the NULL
address.

Fix by initializing tc->cur_frame->return_address in the callback_handler, so
it doesn't matter how we ended up there.
  • Loading branch information
niner committed Dec 26, 2019
1 parent 4170864 commit ae66545
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
2 changes: 0 additions & 2 deletions src/core/nativecall.c
Expand Up @@ -1265,8 +1265,6 @@ void MVM_nativecall_invoke_jit(MVMThreadContext *tc, MVMObject *site) {
body = MVM_nativecall_get_nc_body(tc, site);
}

tc->cur_frame->return_address = *tc->interp_cur_op;

MVMJitCode * const jitcode = body->jitcode;
jitcode->func_ptr(tc, *tc->interp_cu, jitcode->labels[0]);
}
3 changes: 1 addition & 2 deletions src/core/nativecall_dyncall.c
Expand Up @@ -342,6 +342,7 @@ static char callback_handler(DCCallback *cb, DCArgs *cb_args, DCValue *cb_result

tc->cur_frame->return_value = &res;
tc->cur_frame->return_type = MVM_RETURN_OBJ;
tc->cur_frame->return_address = *tc->interp_cur_op;

tc->nested_interpreter++;
MVM_interp_run(tc, callback_invoke, &cid);
Expand Down Expand Up @@ -504,8 +505,6 @@ MVMObject * MVM_nativecall_invoke(MVMThreadContext *tc, MVMObject *res_type,
unsigned int interval_id;
DCCallVM *vm;

tc->cur_frame->return_address = *tc->interp_cur_op;

/* Create and set up call VM. */
vm = dcNewCallVM(8192);
dcMode(vm, body->convention);
Expand Down

0 comments on commit ae66545

Please sign in to comment.