pr1.2
This commit is contained in:
@@ -1,19 +1,17 @@
|
||||
//! This module defines the Application Binary Interface (ABI) of the Prometeu Virtual Machine.
|
||||
//! It specifies how instructions are encoded in bytes and how they interact with memory.
|
||||
|
||||
// --- HIP Trap Codes ---
|
||||
// --- Runtime Trap Codes (post-HIP reset) ---
|
||||
|
||||
/// Attempted to access a gate that does not exist or has been recycled incorrectly.
|
||||
pub const TRAP_INVALID_GATE: u32 = 0x01;
|
||||
/// Attempted to access a gate that has been explicitly released (RC=0).
|
||||
pub const TRAP_DEAD_GATE: u32 = 0x02;
|
||||
/// Attempted to access a field or index beyond the allocated slots for a gate.
|
||||
pub const TRAP_OOB: u32 = 0x03;
|
||||
/// Attempted a typed operation on a gate whose storage type does not match.
|
||||
pub const TRAP_TYPE: u32 = 0x04;
|
||||
/// Attempted to execute an unknown or invalid opcode.
|
||||
pub const TRAP_ILLEGAL_INSTRUCTION: u32 = 0x0000_0001;
|
||||
/// Out-of-bounds access (e.g., stack/heap/local index out of range).
|
||||
pub const TRAP_OOB: u32 = 0x0000_0003;
|
||||
/// Type mismatch for the attempted operation (e.g., wrong operand type or syscall argument type).
|
||||
pub const TRAP_TYPE: u32 = 0x0000_0004;
|
||||
/// The syscall ID provided is not recognized by the system.
|
||||
pub const TRAP_INVALID_SYSCALL: u32 = 0x0000_0007;
|
||||
/// Not enough arguments on the stack for the requested syscall.
|
||||
/// Not enough values on the operand stack for the requested operation/syscall.
|
||||
pub const TRAP_STACK_UNDERFLOW: u32 = 0x0000_0008;
|
||||
/// Attempted to access a local slot that is out of bounds for the current frame.
|
||||
pub const TRAP_INVALID_LOCAL: u32 = 0x0000_0009;
|
||||
|
||||
@@ -8,9 +8,8 @@ mod program_image;
|
||||
mod value;
|
||||
|
||||
pub use abi::{
|
||||
TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DEAD_GATE, TRAP_DIV_ZERO, TRAP_INVALID_FUNC,
|
||||
TRAP_INVALID_GATE, TRAP_INVALID_LOCAL, TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_STACK_UNDERFLOW,
|
||||
TRAP_TYPE,
|
||||
TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_ILLEGAL_INSTRUCTION, TRAP_INVALID_FUNC,
|
||||
TRAP_INVALID_LOCAL, TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_STACK_UNDERFLOW, TRAP_TYPE,
|
||||
};
|
||||
pub use decoder::{decode_next, DecodeError};
|
||||
pub use layout::{compute_function_layouts, FunctionLayout};
|
||||
|
||||
@@ -7,8 +7,8 @@ use prometeu_bytecode::OpCode;
|
||||
use prometeu_bytecode::ProgramImage;
|
||||
use prometeu_bytecode::Value;
|
||||
use prometeu_bytecode::{
|
||||
TRAP_BAD_RET_SLOTS, TRAP_DEAD_GATE, TRAP_DIV_ZERO, TRAP_INVALID_FUNC, TRAP_INVALID_GATE,
|
||||
TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_STACK_UNDERFLOW, TRAP_TYPE, TrapInfo,
|
||||
TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_INVALID_FUNC, TRAP_INVALID_SYSCALL, TRAP_OOB,
|
||||
TRAP_STACK_UNDERFLOW, TRAP_TYPE, TrapInfo,
|
||||
};
|
||||
use prometeu_hal::vm_fault::VmFault;
|
||||
|
||||
@@ -1156,11 +1156,11 @@ impl VirtualMachine {
|
||||
) -> Result<&GateEntry, LogicalFrameEndingReason> {
|
||||
let idx = gate_id as usize;
|
||||
let entry = self.gate_pool.get(idx).ok_or_else(|| {
|
||||
self.trap(TRAP_INVALID_GATE, opcode, format!("Invalid gate id: {}", gate_id), pc)
|
||||
self.trap(TRAP_OOB, opcode, format!("Invalid gate id: {}", gate_id), pc)
|
||||
})?;
|
||||
if !entry.alive {
|
||||
return Err(self.trap(
|
||||
TRAP_DEAD_GATE,
|
||||
TRAP_OOB,
|
||||
opcode,
|
||||
format!("Dead gate id: {}", gate_id),
|
||||
pc,
|
||||
@@ -2034,7 +2034,7 @@ mod tests {
|
||||
let report = vm.run_budget(100, &mut native, &mut ctx).unwrap();
|
||||
match report.reason {
|
||||
LogicalFrameEndingReason::Trap(trap) => {
|
||||
assert_eq!(trap.code, TRAP_INVALID_GATE);
|
||||
assert_eq!(trap.code, TRAP_OOB);
|
||||
assert_eq!(trap.opcode, OpCode::GateLoad as u16);
|
||||
}
|
||||
_ => panic!("Expected Trap, got {:?}", report.reason),
|
||||
|
||||
Reference in New Issue
Block a user