diff --git a/src/libtools/signal32.c b/src/libtools/signal32.c index 064fd3a0f..7d92f91f1 100644 --- a/src/libtools/signal32.c +++ b/src/libtools/signal32.c @@ -863,8 +863,8 @@ EXPORT int my32_getcontext(x64emu_t* emu, void* ucp) u->uc_mcontext.gregs[I386_CS] = R_CS; u->uc_mcontext.gregs[I386_SS] = R_SS; // get FloatPoint status - if(u->uc_mcontext.fpregs) - save_fpreg(emu, from_ptrv(u->uc_mcontext.fpregs)); + u->uc_mcontext.fpregs = to_ptrv(ucp + 236); // magic offset of fpregs in an actual i386 u_context + fpu_savenv(emu, from_ptrv(u->uc_mcontext.fpregs), 1); // it seems getcontext only save fpu env, not fpu regs // get signal mask sigprocmask(SIG_SETMASK, NULL, (sigset_t*)&u->uc_sigmask); // ensure uc_link is properly initialized @@ -898,8 +898,7 @@ EXPORT int my32_setcontext(x64emu_t* emu, void* ucp) R_CS = u->uc_mcontext.gregs[I386_CS]; R_SS = u->uc_mcontext.gregs[I386_SS]; // set FloatPoint status - if(u->uc_mcontext.fpregs) - load_fpreg(emu, from_ptrv(u->uc_mcontext.fpregs)); + fpu_loadenv(emu, from_ptrv(u->uc_mcontext.fpregs), 1); // set signal mask sigprocmask(SIG_SETMASK, (sigset_t*)&u->uc_sigmask, NULL); // set uc_link diff --git a/src/libtools/signals.c b/src/libtools/signals.c index a4602bc6a..6bebf6d23 100644 --- a/src/libtools/signals.c +++ b/src/libtools/signals.c @@ -2243,8 +2243,10 @@ EXPORT int my_getcontext(x64emu_t* emu, void* ucp) // get segments u->uc_mcontext.gregs[X64_CSGSFS] = ((uint64_t)(R_CS)) | (((uint64_t)(R_GS))<<16) | (((uint64_t)(R_FS))<<32); // get FloatPoint status - u->uc_mcontext.fpregs = &u->xstate; - fpu_fxsave64(emu, &u->xstate); + u->uc_mcontext.fpregs = ucp + 408; + fpu_savenv(emu, (void*)u->uc_mcontext.fpregs, 1); + *(uint32_t*)(ucp + 432) = emu->mxcsr.x32; + // get signal mask sigprocmask(SIG_SETMASK, NULL, (sigset_t*)&u->uc_sigmask); // ensure uc_link is properly initialized @@ -2283,7 +2285,8 @@ EXPORT int my_setcontext(x64emu_t* emu, void* ucp) R_GS = (u->uc_mcontext.gregs[X64_CSGSFS]>>16)&0xffff; R_FS = (u->uc_mcontext.gregs[X64_CSGSFS]>>32)&0xffff; // set FloatPoint status - fpu_fxrstor64(emu, &u->xstate); + fpu_loadenv(emu, (void*)u->uc_mcontext.fpregs, 1); + emu->mxcsr.x32 = *(uint32_t*)(ucp + 432); // set signal mask sigprocmask(SIG_SETMASK, (sigset_t*)&u->uc_sigmask, NULL); // set uc_link