mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-13 09:01:21 +00:00
Move inline breakpoint outside of runtime backend
There was some code smell leaking inline breakpoint implementation into the runtime core backend instead of the compiler itself
This commit is contained in:
@ -104,83 +104,6 @@ pub struct InlineBreakpoint {
|
||||
pub ty: InlineBreakpointType,
|
||||
}
|
||||
|
||||
/// Inline breakpoint size for (x86-64, singlepass).
|
||||
pub const INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS: usize = 7;
|
||||
|
||||
/// Inline breakpoint size for (aarch64, singlepass).
|
||||
pub const INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS: usize = 12;
|
||||
|
||||
/// Returns the inline breakpoint size corresponding to an (Architecture, Backend) pair.
|
||||
pub fn get_inline_breakpoint_size(arch: Architecture, backend: Backend) -> Option<usize> {
|
||||
match (arch, backend) {
|
||||
(Architecture::X64, Backend::Singlepass) => Some(INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS),
|
||||
(Architecture::Aarch64, Backend::Singlepass) => {
|
||||
Some(INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to read an inline breakpoint from the code.
|
||||
///
|
||||
/// Inline breakpoints are detected by special instruction sequences that never
|
||||
/// appear in valid code.
|
||||
pub fn read_inline_breakpoint(
|
||||
arch: Architecture,
|
||||
backend: Backend,
|
||||
code: &[u8],
|
||||
) -> Option<InlineBreakpoint> {
|
||||
match arch {
|
||||
Architecture::X64 => match backend {
|
||||
Backend::Singlepass => {
|
||||
if code.len() < INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS {
|
||||
None
|
||||
} else if &code[..INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS - 1]
|
||||
== &[
|
||||
0x0f, 0x0b, // ud2
|
||||
0x0f, 0xb9, // ud
|
||||
0xcd, 0xff, // int 0xff
|
||||
]
|
||||
{
|
||||
Some(InlineBreakpoint {
|
||||
size: INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS,
|
||||
ty: match code[INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS - 1] {
|
||||
0 => InlineBreakpointType::Middleware,
|
||||
_ => return None,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
Architecture::Aarch64 => match backend {
|
||||
Backend::Singlepass => {
|
||||
if code.len() < INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS {
|
||||
None
|
||||
} else if &code[..INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS - 4]
|
||||
== &[
|
||||
0, 0, 0, 0, // udf #0
|
||||
0xff, 0xff, 0x00, 0x00, // udf #65535
|
||||
]
|
||||
{
|
||||
Some(InlineBreakpoint {
|
||||
size: INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS,
|
||||
ty: match code[INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS - 4] {
|
||||
0 => InlineBreakpointType::Middleware,
|
||||
_ => return None,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod backend_test {
|
||||
use super::*;
|
||||
@ -316,6 +239,23 @@ pub trait RunnableModule: Send + Sync {
|
||||
fn get_local_function_offsets(&self) -> Option<Vec<usize>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns the inline breakpoint size corresponding to an Architecture (None in case is not implemented)
|
||||
fn get_inline_breakpoint_size(&self, _arch: Architecture) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Attempts to read an inline breakpoint from the code.
|
||||
///
|
||||
/// Inline breakpoints are detected by special instruction sequences that never
|
||||
/// appear in valid code.
|
||||
fn read_inline_breakpoint(
|
||||
&self,
|
||||
_arch: Architecture,
|
||||
_code: &[u8],
|
||||
) -> Option<InlineBreakpoint> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CacheGen: Send + Sync {
|
||||
|
Reference in New Issue
Block a user