From 263afa8a80bd38cb346f9f70fe726e2231ac371c Mon Sep 17 00:00:00 2001 From: losfair Date: Mon, 15 Jul 2019 23:00:27 +0800 Subject: [PATCH] Fix trap handler in WSL environment. --- lib/runtime-core/src/fault.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/runtime-core/src/fault.rs b/lib/runtime-core/src/fault.rs index 119aeae04..24a8b91a8 100644 --- a/lib/runtime-core/src/fault.rs +++ b/lib/runtime-core/src/fault.rs @@ -304,8 +304,9 @@ pub struct FaultInfo { #[cfg(all(target_os = "linux", target_arch = "x86_64"))] pub unsafe fn get_fault_info(siginfo: *const c_void, ucontext: *const c_void) -> FaultInfo { use libc::{ - _libc_xmmreg, ucontext_t, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_R8, - REG_R9, REG_RAX, REG_RBP, REG_RBX, REG_RCX, REG_RDI, REG_RDX, REG_RIP, REG_RSI, REG_RSP, + _libc_fpstate, _libc_xmmreg, mcontext_t, ucontext_t, REG_R10, REG_R11, REG_R12, REG_R13, + REG_R14, REG_R15, REG_R8, REG_R9, REG_RAX, REG_RBP, REG_RBX, REG_RCX, REG_RDI, REG_RDX, + REG_RIP, REG_RSI, REG_RSP, }; fn read_xmm(reg: &_libc_xmmreg) -> u64 { @@ -327,7 +328,16 @@ pub unsafe fn get_fault_info(siginfo: *const c_void, ucontext: *const c_void) -> let ucontext = ucontext as *const ucontext_t; let gregs = &(*ucontext).uc_mcontext.gregs; - let fpregs = &*(*ucontext).uc_mcontext.fpregs; + + // WSL bug: (*ucontext).uc_mcontext.fpregs is always null. + let fpregs: &_libc_fpstate = + &*(((&(*ucontext).uc_mcontext) as *const mcontext_t).offset(1) as *const _libc_fpstate); + if !(*ucontext).uc_mcontext.fpregs.is_null() { + assert_eq!( + (*ucontext).uc_mcontext.fpregs as *const _, + fpregs as *const _ + ); + } let mut known_registers: [Option; 24] = [None; 24]; known_registers[X64Register::GPR(GPR::R15).to_index().0] = Some(gregs[REG_R15 as usize] as _);