x64 backend: Pass guest return address as first argument to guest functions.
This commit is contained in:
parent
7683069f6c
commit
52c75c8dbc
|
@ -422,7 +422,7 @@ HostToGuestThunk X64ThunkEmitter::EmitHostToGuestThunk() {
|
||||||
|
|
||||||
mov(rax, rcx);
|
mov(rax, rcx);
|
||||||
mov(rsi, rdx); // context
|
mov(rsi, rdx); // context
|
||||||
mov(rdx, r8);
|
mov(rcx, r8); // return address
|
||||||
call(rax);
|
call(rax);
|
||||||
|
|
||||||
movaps(xmm6, qword[rsp + offsetof(StackLayout::Thunk, xmm[0])]);
|
movaps(xmm6, qword[rsp + offsetof(StackLayout::Thunk, xmm[0])]);
|
||||||
|
|
|
@ -169,7 +169,7 @@ bool X64Emitter::Emit(HIRBuilder* builder, size_t* out_stack_size) {
|
||||||
stack_size_ = stack_size;
|
stack_size_ = stack_size;
|
||||||
sub(rsp, (uint32_t)stack_size);
|
sub(rsp, (uint32_t)stack_size);
|
||||||
mov(qword[rsp + StackLayout::GUEST_CTX_HOME], GetContextReg());
|
mov(qword[rsp + StackLayout::GUEST_CTX_HOME], GetContextReg());
|
||||||
mov(qword[rsp + StackLayout::GUEST_RET_ADDR], rdx);
|
mov(qword[rsp + StackLayout::GUEST_RET_ADDR], rcx);
|
||||||
mov(qword[rsp + StackLayout::GUEST_CALL_RET_ADDR], 0);
|
mov(qword[rsp + StackLayout::GUEST_CALL_RET_ADDR], 0);
|
||||||
|
|
||||||
// Safe now to do some tracing.
|
// Safe now to do some tracing.
|
||||||
|
@ -384,13 +384,13 @@ void X64Emitter::Call(const hir::Instr* instr, GuestFunction* function) {
|
||||||
EmitTraceUserCallReturn();
|
EmitTraceUserCallReturn();
|
||||||
|
|
||||||
// Pass the callers return address over.
|
// Pass the callers return address over.
|
||||||
mov(rdx, qword[rsp + StackLayout::GUEST_RET_ADDR]);
|
mov(rcx, qword[rsp + StackLayout::GUEST_RET_ADDR]);
|
||||||
|
|
||||||
add(rsp, static_cast<uint32_t>(stack_size()));
|
add(rsp, static_cast<uint32_t>(stack_size()));
|
||||||
jmp(rax);
|
jmp(rax);
|
||||||
} else {
|
} else {
|
||||||
// Return address is from the previous SET_RETURN_ADDRESS.
|
// Return address is from the previous SET_RETURN_ADDRESS.
|
||||||
mov(rdx, qword[rsp + StackLayout::GUEST_CALL_RET_ADDR]);
|
mov(rcx, qword[rsp + StackLayout::GUEST_CALL_RET_ADDR]);
|
||||||
|
|
||||||
call(rax);
|
call(rax);
|
||||||
}
|
}
|
||||||
|
@ -427,13 +427,13 @@ void X64Emitter::CallIndirect(const hir::Instr* instr,
|
||||||
EmitTraceUserCallReturn();
|
EmitTraceUserCallReturn();
|
||||||
|
|
||||||
// Pass the callers return address over.
|
// Pass the callers return address over.
|
||||||
mov(rdx, qword[rsp + StackLayout::GUEST_RET_ADDR]);
|
mov(rcx, qword[rsp + StackLayout::GUEST_RET_ADDR]);
|
||||||
|
|
||||||
add(rsp, static_cast<uint32_t>(stack_size()));
|
add(rsp, static_cast<uint32_t>(stack_size()));
|
||||||
jmp(rax);
|
jmp(rax);
|
||||||
} else {
|
} else {
|
||||||
// Return address is from the previous SET_RETURN_ADDRESS.
|
// Return address is from the previous SET_RETURN_ADDRESS.
|
||||||
mov(rdx, qword[rsp + StackLayout::GUEST_CALL_RET_ADDR]);
|
mov(rcx, qword[rsp + StackLayout::GUEST_CALL_RET_ADDR]);
|
||||||
|
|
||||||
call(rax);
|
call(rax);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue