From 9b77677e4b6b9b0281dbcc7dcd9adb1c37ba7716 Mon Sep 17 00:00:00 2001 From: losfair Date: Sun, 15 Sep 2019 18:23:42 +0800 Subject: [PATCH] Relax constraints a bit to compile on aarch64. --- lib/runtime-core/src/fault.rs | 18 ++- lib/runtime-core/src/lib.rs | 2 +- lib/runtime-core/src/state.rs | 165 +++++++++++----------- lib/singlepass-backend/src/emitter_x64.rs | 9 +- 4 files changed, 110 insertions(+), 84 deletions(-) diff --git a/lib/runtime-core/src/fault.rs b/lib/runtime-core/src/fault.rs index 2d46d8ca2..a826e1bbd 100644 --- a/lib/runtime-core/src/fault.rs +++ b/lib/runtime-core/src/fault.rs @@ -1,9 +1,13 @@ pub mod raw { use std::ffi::c_void; + #[cfg(target_arch = "x86_64")] extern "C" { pub fn run_on_alternative_stack(stack_end: *mut u64, stack_begin: *mut u64) -> u64; pub fn register_preservation_trampoline(); // NOT safe to call directly + } + + extern "C" { pub fn setjmp(env: *mut c_void) -> i32; pub fn longjmp(env: *mut c_void, val: i32) -> !; } @@ -25,13 +29,14 @@ use std::process; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Once; +#[cfg(target_arch = "x86_64")] pub(crate) unsafe fn run_on_alternative_stack(stack_end: *mut u64, stack_begin: *mut u64) -> u64 { raw::run_on_alternative_stack(stack_end, stack_begin) } const TRAP_STACK_SIZE: usize = 1048576; // 1MB -const SETJMP_BUFFER_LEN: usize = 27; +const SETJMP_BUFFER_LEN: usize = 128; type SetJmpBuffer = [i32; SETJMP_BUFFER_LEN]; struct UnwindInfo { @@ -181,6 +186,12 @@ unsafe fn with_breakpoint_map) -> R>(f: F) - f(inner.breakpoints.as_ref()) } +#[cfg(not(target_arch = "x86_64"))] +pub fn allocate_and_run R>(size: usize, f: F) -> R { + unimplemented!("allocate_and_run only supported on x86_64"); +} + +#[cfg(target_arch = "x86_64")] pub fn allocate_and_run R>(size: usize, f: F) -> R { struct Context R, R> { f: Option, @@ -353,6 +364,11 @@ pub struct FaultInfo { pub known_registers: [Option; 24], } +#[cfg(target_arch = "aarch64")] +pub unsafe fn get_fault_info(siginfo: *const c_void, ucontext: *const c_void) -> FaultInfo { + unimplemented!("get_fault_info is not yet implemented for aarch64."); +} + #[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::{ diff --git a/lib/runtime-core/src/lib.rs b/lib/runtime-core/src/lib.rs index fa4450693..6d6d1e3bb 100644 --- a/lib/runtime-core/src/lib.rs +++ b/lib/runtime-core/src/lib.rs @@ -53,7 +53,7 @@ pub mod vm; pub mod vmcalls; #[cfg(all(unix, target_arch = "x86_64"))] pub use trampoline_x64 as trampoline; -#[cfg(all(unix, target_arch = "x86_64"))] +#[cfg(unix)] pub mod fault; pub mod state; #[cfg(feature = "managed")] diff --git a/lib/runtime-core/src/state.rs b/lib/runtime-core/src/state.rs index b6bbb95f5..f61c6aa5c 100644 --- a/lib/runtime-core/src/state.rs +++ b/lib/runtime-core/src/state.rs @@ -398,8 +398,91 @@ impl InstanceImage { } } -#[cfg(all(unix, target_arch = "x86_64"))] +pub mod x64_decl { + use super::*; + #[repr(u8)] + #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] + pub enum GPR { + RAX, + RCX, + RDX, + RBX, + RSP, + RBP, + RSI, + RDI, + R8, + R9, + R10, + R11, + R12, + R13, + R14, + R15, + } + + #[repr(u8)] + #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] + pub enum XMM { + XMM0, + XMM1, + XMM2, + XMM3, + XMM4, + XMM5, + XMM6, + XMM7, + } + + #[derive(Copy, Clone, Debug, Eq, PartialEq)] + pub enum X64Register { + GPR(GPR), + XMM(XMM), + } + + impl X64Register { + pub fn to_index(&self) -> RegisterIndex { + match *self { + X64Register::GPR(x) => RegisterIndex(x as usize), + X64Register::XMM(x) => RegisterIndex(x as usize + 16), + } + } + + pub fn from_dwarf_regnum(x: u16) -> Option { + Some(match x { + 0 => X64Register::GPR(GPR::RAX), + 1 => X64Register::GPR(GPR::RDX), + 2 => X64Register::GPR(GPR::RCX), + 3 => X64Register::GPR(GPR::RBX), + 4 => X64Register::GPR(GPR::RSI), + 5 => X64Register::GPR(GPR::RDI), + 6 => X64Register::GPR(GPR::RBP), + 7 => X64Register::GPR(GPR::RSP), + 8 => X64Register::GPR(GPR::R8), + 9 => X64Register::GPR(GPR::R9), + 10 => X64Register::GPR(GPR::R10), + 11 => X64Register::GPR(GPR::R11), + 12 => X64Register::GPR(GPR::R12), + 13 => X64Register::GPR(GPR::R13), + 14 => X64Register::GPR(GPR::R14), + 15 => X64Register::GPR(GPR::R15), + + 17 => X64Register::XMM(XMM::XMM0), + 18 => X64Register::XMM(XMM::XMM1), + 19 => X64Register::XMM(XMM::XMM2), + 20 => X64Register::XMM(XMM::XMM3), + 21 => X64Register::XMM(XMM::XMM4), + 22 => X64Register::XMM(XMM::XMM5), + 23 => X64Register::XMM(XMM::XMM6), + 24 => X64Register::XMM(XMM::XMM7), + _ => return None, + }) + } + } +} + pub mod x64 { + pub use super::x64_decl::*; use super::*; use crate::codegen::BreakpointMap; use crate::fault::{ @@ -998,84 +1081,4 @@ pub mod x64 { unreachable!(); } - - #[repr(u8)] - #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] - pub enum GPR { - RAX, - RCX, - RDX, - RBX, - RSP, - RBP, - RSI, - RDI, - R8, - R9, - R10, - R11, - R12, - R13, - R14, - R15, - } - - #[repr(u8)] - #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] - pub enum XMM { - XMM0, - XMM1, - XMM2, - XMM3, - XMM4, - XMM5, - XMM6, - XMM7, - } - - #[derive(Copy, Clone, Debug, Eq, PartialEq)] - pub enum X64Register { - GPR(GPR), - XMM(XMM), - } - - impl X64Register { - pub fn to_index(&self) -> RegisterIndex { - match *self { - X64Register::GPR(x) => RegisterIndex(x as usize), - X64Register::XMM(x) => RegisterIndex(x as usize + 16), - } - } - - pub fn from_dwarf_regnum(x: u16) -> Option { - Some(match x { - 0 => X64Register::GPR(GPR::RAX), - 1 => X64Register::GPR(GPR::RDX), - 2 => X64Register::GPR(GPR::RCX), - 3 => X64Register::GPR(GPR::RBX), - 4 => X64Register::GPR(GPR::RSI), - 5 => X64Register::GPR(GPR::RDI), - 6 => X64Register::GPR(GPR::RBP), - 7 => X64Register::GPR(GPR::RSP), - 8 => X64Register::GPR(GPR::R8), - 9 => X64Register::GPR(GPR::R9), - 10 => X64Register::GPR(GPR::R10), - 11 => X64Register::GPR(GPR::R11), - 12 => X64Register::GPR(GPR::R12), - 13 => X64Register::GPR(GPR::R13), - 14 => X64Register::GPR(GPR::R14), - 15 => X64Register::GPR(GPR::R15), - - 17 => X64Register::XMM(XMM::XMM0), - 18 => X64Register::XMM(XMM::XMM1), - 19 => X64Register::XMM(XMM::XMM2), - 20 => X64Register::XMM(XMM::XMM3), - 21 => X64Register::XMM(XMM::XMM4), - 22 => X64Register::XMM(XMM::XMM5), - 23 => X64Register::XMM(XMM::XMM6), - 24 => X64Register::XMM(XMM::XMM7), - _ => return None, - }) - } - } } diff --git a/lib/singlepass-backend/src/emitter_x64.rs b/lib/singlepass-backend/src/emitter_x64.rs index 24e01231a..2bc232a78 100644 --- a/lib/singlepass-backend/src/emitter_x64.rs +++ b/lib/singlepass-backend/src/emitter_x64.rs @@ -1,5 +1,5 @@ use dynasmrt::{x64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi}; -pub use wasmer_runtime_core::state::x64::{GPR, XMM}; +pub use wasmer_runtime_core::state::x64_decl::{GPR, XMM}; #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] pub enum Location { @@ -170,6 +170,13 @@ pub trait Emitter { fn emit_bkpt(&mut self); } +fn _dummy(a: &mut Assembler) { + dynasm!( + self + ; .arch x64 + ); +} + macro_rules! unop_gpr { ($ins:ident, $assembler:tt, $sz:expr, $loc:expr, $otherwise:block) => { match ($sz, $loc) {