diff --git a/sys/amd64/amd64/vm_machdep.c b/sys/amd64/amd64/vm_machdep.c index 5f4f43c2352..fae37d731b0 100644 --- a/sys/amd64/amd64/vm_machdep.c +++ b/sys/amd64/amd64/vm_machdep.c @@ -508,6 +508,9 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, (((uintptr_t)stack->ss_sp + stack->ss_size - 4) & ~0x0f) - 4; td->td_frame->tf_rip = (uintptr_t)entry; + /* Return address sentinel value to stop stack unwinding. */ + suword32((void *)td->td_frame->tf_rsp, 0); + /* Pass the argument to the entry point. */ suword32((void *)(td->td_frame->tf_rsp + sizeof(int32_t)), (uint32_t)(uintptr_t)arg); @@ -531,6 +534,9 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, td->td_frame->tf_gs = _ugssel; td->td_frame->tf_flags = TF_HASSEGS; + /* Return address sentinel value to stop stack unwinding. */ + suword((void *)td->td_frame->tf_rsp, 0); + /* Pass the argument to the entry point. */ td->td_frame->tf_rdi = (register_t)arg; } diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c index a0a9473b3bd..562cdfdd756 100644 --- a/sys/i386/i386/vm_machdep.c +++ b/sys/i386/i386/vm_machdep.c @@ -524,6 +524,9 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, (((int)stack->ss_sp + stack->ss_size - 4) & ~0x0f) - 4; td->td_frame->tf_eip = (int)entry; + /* Return address sentinel value to stop stack unwinding. */ + suword((void *)td->td_frame->tf_esp, 0); + /* Pass the argument to the entry point. */ suword((void *)(td->td_frame->tf_esp + sizeof(void *)), (int)arg);