harden deterministic headless runtime control
This commit is contained in:
@@ -11,9 +11,9 @@ mod program_image;
|
||||
mod value;
|
||||
|
||||
pub use abi::{
|
||||
TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_EXPLICIT, TRAP_ILLEGAL_INSTRUCTION,
|
||||
TRAP_INVALID_FUNC, TRAP_INVALID_INTRINSIC, TRAP_INVALID_LOCAL, TRAP_INVALID_SYSCALL, TRAP_OOB,
|
||||
TRAP_STACK_UNDERFLOW, TRAP_TYPE,
|
||||
SourceSpan, TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_EXPLICIT,
|
||||
TRAP_ILLEGAL_INSTRUCTION, TRAP_INVALID_FUNC, TRAP_INVALID_INTRINSIC, TRAP_INVALID_LOCAL,
|
||||
TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_STACK_UNDERFLOW, TRAP_TYPE,
|
||||
};
|
||||
pub use assembler::{assemble, AsmError};
|
||||
pub use decoder::{decode_next, DecodeError};
|
||||
|
||||
@@ -159,6 +159,15 @@ impl<'a> VmFacade<'a> {
|
||||
self.os.vm_runtime.debug_step_request = true;
|
||||
}
|
||||
|
||||
pub fn clear_debug_step_request(&mut self) {
|
||||
if let Some(session) = self.active_session_mut() {
|
||||
session.runtime.debug_step_request = false;
|
||||
return;
|
||||
}
|
||||
|
||||
self.os.vm_runtime.debug_step_request = false;
|
||||
}
|
||||
|
||||
pub fn debug_step_requested(&self) -> bool {
|
||||
self.active_session()
|
||||
.map(|session| session.runtime.debug_step_request)
|
||||
|
||||
@@ -65,7 +65,7 @@ pub struct VirtualMachineRuntime {
|
||||
|
||||
impl VirtualMachineRuntime {
|
||||
pub const CYCLES_PER_LOGICAL_FRAME: u64 = 1_500_000;
|
||||
pub const SLICE_PER_TICK: u64 = 1_500_000;
|
||||
pub const SLICE_PER_TICK: u64 = 250_000;
|
||||
pub const MAX_LOG_LEN: usize = 256;
|
||||
pub const MAX_LOGS_PER_FRAME: u32 = 10;
|
||||
|
||||
|
||||
@@ -76,6 +76,9 @@ impl VirtualMachineRuntime {
|
||||
vm: &mut VirtualMachine,
|
||||
platform: &mut dyn RuntimePlatform,
|
||||
) -> Option<CrashReport> {
|
||||
if vm.call_stack_is_empty() {
|
||||
vm.prepare_boot_call();
|
||||
}
|
||||
let step_result = {
|
||||
let mut ctx = HostContext::new_platform(Some(platform));
|
||||
let mut fs = VirtualFS::new();
|
||||
@@ -96,18 +99,28 @@ impl VirtualMachineRuntime {
|
||||
};
|
||||
|
||||
match step_result {
|
||||
Ok(_) => None,
|
||||
Err(e) => {
|
||||
let report = match e {
|
||||
LogicalFrameEndingReason::Trap(trap) => CrashReport::VmTrap { trap },
|
||||
LogicalFrameEndingReason::Panic(message) => {
|
||||
CrashReport::VmPanic { message, pc: Some(vm.pc() as u32) }
|
||||
}
|
||||
other => CrashReport::VmPanic {
|
||||
message: format!("Unexpected fault during step: {:?}", other),
|
||||
pc: Some(vm.pc() as u32),
|
||||
},
|
||||
};
|
||||
Ok(())
|
||||
| Err(
|
||||
LogicalFrameEndingReason::FrameSync
|
||||
| LogicalFrameEndingReason::BudgetExhausted
|
||||
| LogicalFrameEndingReason::Halted
|
||||
| LogicalFrameEndingReason::EndOfRom
|
||||
| LogicalFrameEndingReason::Breakpoint,
|
||||
) => None,
|
||||
Err(LogicalFrameEndingReason::Trap(trap)) => {
|
||||
let report = CrashReport::VmTrap { trap };
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Error,
|
||||
LogSource::Vm,
|
||||
report.log_tag(),
|
||||
format!("PVM Fault during Step: {}", report),
|
||||
);
|
||||
self.last_crash_report = Some(report.clone());
|
||||
Some(report)
|
||||
}
|
||||
Err(LogicalFrameEndingReason::Panic(message)) => {
|
||||
let report = CrashReport::VmPanic { message, pc: Some(vm.pc() as u32) };
|
||||
self.log(
|
||||
log_service,
|
||||
LogLevel::Error,
|
||||
|
||||
Reference in New Issue
Block a user