[x64] Restore FP rounding mode after host callbacks

Add MXCSR restore to the x64 GuestToHostThunk so host callbacks can't
leak their rounding state into subsequent guest FP operations.
This commit is contained in:
Herman S.
2026-03-23 12:01:03 +09:00
parent ecd7501029
commit 3747f5e282
2 changed files with 93 additions and 0 deletions

View File

@@ -753,6 +753,9 @@ GuestToHostThunk X64HelperEmitter::EmitGuestToHostThunk() {
call(rax);
EmitLoadVolatileRegs();
// Host callbacks may change MXCSR. Restore the guest scalar rounding mode
// so later guest FP ops observe the correct PPC rounding state.
vldmxcsr(GetBackendCtxPtr(offsetof(X64BackendContext, mxcsr_fpu)));
code_offsets.epilog = getSize();
@@ -801,6 +804,9 @@ GuestToHostThunk X64HelperEmitter::EmitGuestToHostThunk() {
call(rax);
EmitLoadVolatileRegs();
// Host callbacks may change MXCSR. Restore the guest scalar rounding mode
// so later guest FP ops observe the correct PPC rounding state.
vldmxcsr(GetBackendCtxPtr(offsetof(X64BackendContext, mxcsr_fpu)));
code_offsets.epilog = getSize();