hard reseet
This commit is contained in:
@@ -3,14 +3,11 @@ mod call_frame;
|
||||
mod scope_frame;
|
||||
pub mod local_addressing;
|
||||
pub mod verifier;
|
||||
pub mod vm_init_error;
|
||||
|
||||
pub use prometeu_abi::ProgramImage;
|
||||
pub use prometeu_abi::{Value, VmFault};
|
||||
pub use prometeu_bytecode::abi::TrapInfo;
|
||||
pub use prometeu_bytecode::opcode::OpCode;
|
||||
pub use prometeu_hal::{
|
||||
HostContext, HostReturn, NativeInterface, SyscallId,
|
||||
};
|
||||
pub type VmInitError = prometeu_abi::VmInitError<VerifierError>;
|
||||
pub use verifier::VerifierError;
|
||||
pub use virtual_machine::{BudgetReport, LogicalFrameEndingReason, VirtualMachine};
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
use crate::call_frame::CallFrame;
|
||||
use crate::scope_frame::ScopeFrame;
|
||||
use crate::Value;
|
||||
use crate::{HostContext, NativeInterface, ProgramImage, VmInitError};
|
||||
use crate::{HostContext, NativeInterface};
|
||||
use prometeu_bytecode::abi::{
|
||||
TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DEAD_GATE, TRAP_DIV_ZERO, TRAP_INVALID_FUNC, TRAP_INVALID_GATE, TRAP_OOB,
|
||||
TRAP_TYPE,
|
||||
};
|
||||
use prometeu_bytecode::opcode::OpCode;
|
||||
use prometeu_bytecode::program_image::ProgramImage;
|
||||
use prometeu_bytecode::Value;
|
||||
use prometeu_hal::vm_fault::VmFault;
|
||||
use crate::verifier::Verifier;
|
||||
use crate::vm_init_error::VmInitError;
|
||||
|
||||
/// Reason why the Virtual Machine stopped execution during a specific run.
|
||||
/// This allows the system to decide if it should continue execution in the next tick
|
||||
@@ -142,14 +146,14 @@ impl VirtualMachine {
|
||||
self.heap.clear();
|
||||
self.gate_pool.clear();
|
||||
self.cycles = 0;
|
||||
self.halted = true; // execution is impossible until successful load
|
||||
self.halted = true; // execution is impossible until a successful load
|
||||
|
||||
// Only recognized format is loadable: PBS v0 industrial format
|
||||
let program = if program_bytes.starts_with(b"PBS\0") {
|
||||
match prometeu_bytecode::BytecodeLoader::load(&program_bytes) {
|
||||
Ok(module) => {
|
||||
// Run verifier on the module
|
||||
let max_stacks = crate::verifier::Verifier::verify(&module.code, &module.functions)
|
||||
let max_stacks = Verifier::verify(&module.code, &module.functions)
|
||||
.map_err(VmInitError::VerificationFailed)?;
|
||||
|
||||
let mut program = ProgramImage::from(module);
|
||||
@@ -164,7 +168,7 @@ impl VirtualMachine {
|
||||
}
|
||||
Err(prometeu_bytecode::LoadError::InvalidVersion) => return Err(VmInitError::UnsupportedFormat),
|
||||
Err(e) => {
|
||||
return Err(VmInitError::PbsV0LoadFailed(e));
|
||||
return Err(VmInitError::ImageLoadFailed(e));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -904,9 +908,9 @@ impl VirtualMachine {
|
||||
let stack_height_before = self.operand_stack.len();
|
||||
let mut ret = crate::HostReturn::new(&mut self.operand_stack);
|
||||
native.syscall(id, &args, &mut ret, ctx).map_err(|fault| match fault {
|
||||
crate::VmFault::Trap(code, msg) => self.trap(code, OpCode::Syscall as u16, msg, pc_at_syscall),
|
||||
crate::VmFault::Panic(msg) => LogicalFrameEndingReason::Panic(msg),
|
||||
crate::VmFault::Unavailable => LogicalFrameEndingReason::Panic("Host feature unavailable".into()),
|
||||
VmFault::Trap(code, msg) => self.trap(code, OpCode::Syscall as u16, msg, pc_at_syscall),
|
||||
VmFault::Panic(msg) => LogicalFrameEndingReason::Panic(msg),
|
||||
VmFault::Unavailable => LogicalFrameEndingReason::Panic("Host feature unavailable".into()),
|
||||
})?;
|
||||
|
||||
let stack_height_after = self.operand_stack.len();
|
||||
@@ -1010,7 +1014,7 @@ mod tests {
|
||||
}]);
|
||||
vm
|
||||
}
|
||||
use crate::{HostReturn, Value, VmFault};
|
||||
use crate::{HostReturn};
|
||||
use prometeu_bytecode::abi::SourceSpan;
|
||||
use prometeu_bytecode::FunctionMeta;
|
||||
use prometeu_hal::expect_int;
|
||||
@@ -2000,7 +2004,7 @@ mod tests {
|
||||
let res = ret.push_bounded(65536);
|
||||
assert!(res.is_err());
|
||||
match res.err().unwrap() {
|
||||
crate::VmFault::Trap(code, _) => {
|
||||
VmFault::Trap(code, _) => {
|
||||
assert_eq!(code, prometeu_bytecode::abi::TRAP_OOB);
|
||||
}
|
||||
_ => panic!("Expected Trap"),
|
||||
@@ -2036,7 +2040,7 @@ mod tests {
|
||||
|
||||
let res = vm.initialize(header, "");
|
||||
match res {
|
||||
Err(VmInitError::PbsV0LoadFailed(prometeu_bytecode::LoadError::UnexpectedEof)) => {},
|
||||
Err(VmInitError::ImageLoadFailed(prometeu_bytecode::LoadError::UnexpectedEof)) => {},
|
||||
_ => panic!("Expected PbsV0LoadFailed(UnexpectedEof), got {:?}", res),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
use crate::verifier::VerifierError;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum VmInitError {
|
||||
InvalidFormat,
|
||||
UnsupportedFormat,
|
||||
ImageLoadFailed(prometeu_bytecode::LoadError),
|
||||
EntrypointNotFound,
|
||||
VerificationFailed(VerifierError),
|
||||
}
|
||||
Reference in New Issue
Block a user