feat(diagnostics): preserve Registry and resource fault context for PLN-0176 step 28
This commit is contained in:
@@ -56,4 +56,6 @@ pub struct TrapInfo {
|
||||
pub pc: u32,
|
||||
/// Optional source span information if debug symbols are available.
|
||||
pub span: Option<SourceSpan>,
|
||||
/// Machine-readable quota context; messages are not its serialization.
|
||||
pub resource: Option<crate::ResourceFailure>,
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ pub mod model;
|
||||
mod opcode;
|
||||
mod opcode_spec;
|
||||
mod program_image;
|
||||
mod resource_failure;
|
||||
mod value;
|
||||
|
||||
pub use abi::{
|
||||
@@ -22,6 +23,7 @@ pub use disassembler::disassemble;
|
||||
pub use layout::{compute_function_layouts, FunctionLayout};
|
||||
pub use model::{BytecodeLoader, FunctionMeta, LoadError, SyscallDecl, PBX_MAGIC};
|
||||
pub use program_image::ProgramImage;
|
||||
pub use resource_failure::{ResourceFailure, ResourceReason, RuntimeResource};
|
||||
pub use value::{string_materialization_count, HeapRef, Value};
|
||||
|
||||
pub mod load_limits;
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
//! Shared PBX v1 resource limits and structured validation failures.
|
||||
//! Counters are deterministic; a failed reservation never changes usage.
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
const MIB: u64 = 1_048_576;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum LoadCode {
|
||||
#[serde(rename = "LOAD_INVALID_FORMAT")]
|
||||
InvalidFormat,
|
||||
#[serde(rename = "LOAD_UNSUPPORTED_FORMAT")]
|
||||
UnsupportedFormat,
|
||||
#[serde(rename = "LOAD_INVALID_REFERENCE")]
|
||||
InvalidReference,
|
||||
#[serde(rename = "LOAD_INVALID_REGISTRY")]
|
||||
InvalidRegistry,
|
||||
#[serde(rename = "LOAD_INVALID_CODE")]
|
||||
InvalidCode,
|
||||
#[serde(rename = "LOAD_RESOURCE_LIMIT")]
|
||||
ResourceLimit,
|
||||
#[serde(rename = "LOAD_INVALID_ENTRYPOINT")]
|
||||
InvalidEntrypoint,
|
||||
}
|
||||
impl LoadCode {
|
||||
@@ -27,7 +35,7 @@ impl LoadCode {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum LoadReason {
|
||||
Magic,
|
||||
Version,
|
||||
@@ -80,7 +88,7 @@ pub enum LoadReason {
|
||||
InvalidYield,
|
||||
TypeMismatch,
|
||||
}
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[repr(usize)]
|
||||
pub enum LoadResource {
|
||||
PbxBytes,
|
||||
@@ -98,14 +106,14 @@ pub enum LoadResource {
|
||||
}
|
||||
const RESOURCE_COUNT: usize = 12;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum IdDomain {
|
||||
Type,
|
||||
Function,
|
||||
Implementation,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct LoadFailure {
|
||||
pub code: LoadCode,
|
||||
pub reason: LoadReason,
|
||||
|
||||
@@ -50,7 +50,7 @@ impl ProgramImage {
|
||||
}
|
||||
}
|
||||
|
||||
TrapInfo { code, opcode, message, pc, span }
|
||||
TrapInfo { code, opcode, message, pc, span, resource: None }
|
||||
}
|
||||
|
||||
pub fn find_function_index(&self, pc: u32) -> Option<usize> {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//! Resource fault context shared by the VM, native boundary and host tooling.
|
||||
//! Accounting and product ceilings remain owned by the runtime budget.
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[repr(usize)]
|
||||
pub enum RuntimeResource {
|
||||
GuestBytes,
|
||||
HandleSlots,
|
||||
AuxiliaryBytes,
|
||||
TemporaryBytes,
|
||||
StringBytes,
|
||||
StringAllocations,
|
||||
IndividualStringBytes,
|
||||
CallDepth,
|
||||
}
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum ResourceReason {
|
||||
Limit,
|
||||
SizeOverflow,
|
||||
AllocationFailed,
|
||||
}
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ResourceFailure {
|
||||
pub resource: RuntimeResource,
|
||||
pub reason: ResourceReason,
|
||||
pub requested: u64,
|
||||
pub limit: u64,
|
||||
}
|
||||
impl fmt::Display for ResourceFailure {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{:?}: {:?}, requested {}, limit {}",
|
||||
self.resource, self.reason, self.requested, self.limit
|
||||
)
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ResourceFailure {}
|
||||
@@ -55,6 +55,7 @@ mod tests {
|
||||
message: "type mismatch".into(),
|
||||
pc: 0x44,
|
||||
span: None,
|
||||
resource: None,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -79,6 +79,9 @@ pub enum DebugEvent {
|
||||
pc: Option<u32>,
|
||||
trap_code: Option<u32>,
|
||||
opcode: Option<u16>,
|
||||
span: Option<prometeu_bytecode::SourceSpan>,
|
||||
resource: Option<prometeu_bytecode::ResourceFailure>,
|
||||
init: Option<serde_json::Value>,
|
||||
},
|
||||
#[serde(rename = "cert")]
|
||||
Cert { rule: String, used: u64, limit: u64, frame_index: u64 },
|
||||
@@ -138,6 +141,9 @@ mod tests {
|
||||
pc: Some(12),
|
||||
trap_code: Some(4),
|
||||
opcode: Some(0x70),
|
||||
span: None,
|
||||
resource: None,
|
||||
init: None,
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&event).unwrap();
|
||||
|
||||
@@ -5,6 +5,7 @@ use std::sync::Arc;
|
||||
/// Native producers describe their output before materializing guest content.
|
||||
/// The VM provides the session allocator; HAL does not own guest quotas.
|
||||
pub trait GuestStringAllocator {
|
||||
fn byte_limit(&self) -> u64;
|
||||
fn build(
|
||||
&mut self,
|
||||
length: usize,
|
||||
@@ -23,6 +24,16 @@ pub struct HostReturn<'a> {
|
||||
}
|
||||
|
||||
impl<'a> HostReturn<'a> {
|
||||
fn size_overflow(&mut self) -> VmFault {
|
||||
let error = VmFault::ResourceLimit(prometeu_bytecode::ResourceFailure {
|
||||
resource: prometeu_bytecode::RuntimeResource::StringBytes,
|
||||
reason: prometeu_bytecode::ResourceReason::SizeOverflow,
|
||||
requested: u64::MAX,
|
||||
limit: self.strings.byte_limit(),
|
||||
});
|
||||
self.failure = Some(error.clone());
|
||||
error
|
||||
}
|
||||
pub fn new(
|
||||
stack: &'a mut Vec<Value>,
|
||||
result_slots: usize,
|
||||
@@ -97,14 +108,14 @@ impl<'a> HostReturn<'a> {
|
||||
length = length.checked_add(part.len()).ok_or(std::fmt::Error)?;
|
||||
Ok(())
|
||||
})
|
||||
.map_err(|_| size_overflow())?;
|
||||
.map_err(|_| self.size_overflow())?;
|
||||
self.push_string_with_len(length, &mut |writer| {
|
||||
lossy_chunks(bytes, &mut |part| writer.write_str(part))
|
||||
})
|
||||
}
|
||||
pub fn push_hex(&mut self, bytes: &[u8]) -> Result<(), VmFault> {
|
||||
const HEX: &[u8; 16] = b"0123456789abcdef";
|
||||
let length = bytes.len().checked_mul(2).ok_or_else(size_overflow)?;
|
||||
let length = bytes.len().checked_mul(2).ok_or_else(|| self.size_overflow())?;
|
||||
self.push_string_with_len(length, &mut |writer| {
|
||||
for &byte in bytes {
|
||||
let pair = [HEX[(byte >> 4) as usize], HEX[(byte & 15) as usize]];
|
||||
@@ -121,9 +132,9 @@ impl<'a> HostReturn<'a> {
|
||||
let mut length = 0usize;
|
||||
for (index, part) in parts.clone().enumerate() {
|
||||
if index > 0 {
|
||||
length = length.checked_add(separator.len()).ok_or_else(size_overflow)?;
|
||||
length = length.checked_add(separator.len()).ok_or_else(|| self.size_overflow())?;
|
||||
}
|
||||
length = length.checked_add(part.len()).ok_or_else(size_overflow)?;
|
||||
length = length.checked_add(part.len()).ok_or_else(|| self.size_overflow())?;
|
||||
}
|
||||
self.push_string_with_len(length, &mut |writer| {
|
||||
for (index, part) in parts.clone().enumerate() {
|
||||
@@ -137,9 +148,6 @@ impl<'a> HostReturn<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn size_overflow() -> VmFault {
|
||||
VmFault::Trap(prometeu_bytecode::TRAP_RESOURCE_LIMIT, "Native string length overflow".into())
|
||||
}
|
||||
fn lossy_chunks(
|
||||
mut bytes: &[u8],
|
||||
emit: &mut dyn FnMut(&str) -> std::fmt::Result,
|
||||
@@ -169,6 +177,9 @@ mod tests {
|
||||
use super::*;
|
||||
struct RejectStrings;
|
||||
impl GuestStringAllocator for RejectStrings {
|
||||
fn byte_limit(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
fn build(
|
||||
&mut self,
|
||||
_length: usize,
|
||||
@@ -198,6 +209,9 @@ mod tests {
|
||||
|
||||
struct Collect;
|
||||
impl GuestStringAllocator for Collect {
|
||||
fn byte_limit(&self) -> u64 {
|
||||
u64::MAX
|
||||
}
|
||||
fn build(
|
||||
&mut self,
|
||||
length: usize,
|
||||
|
||||
@@ -39,7 +39,8 @@ pub enum LoadError {
|
||||
}
|
||||
|
||||
/// Load-time error for PBX-declared syscall resolution.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(tag = "reason", rename_all = "snake_case")]
|
||||
pub enum DeclaredLoadError {
|
||||
UnknownSyscall {
|
||||
module: String,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum VmFault {
|
||||
Trap(u32, String),
|
||||
ResourceLimit(prometeu_bytecode::ResourceFailure),
|
||||
Panic(String),
|
||||
Unavailable,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use prometeu_bytecode::TrapInfo;
|
||||
use prometeu_vm::VmInitError;
|
||||
use std::fmt;
|
||||
mod init_diagnostic;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum CrashReport {
|
||||
@@ -10,6 +11,20 @@ pub enum CrashReport {
|
||||
}
|
||||
|
||||
impl CrashReport {
|
||||
/// The same machine fields serve headless and desktop transports.
|
||||
pub fn init_diagnostic(&self) -> Option<serde_json::Value> {
|
||||
match self {
|
||||
Self::VmInit { error } => Some(init_diagnostic::serialize(error)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn resource_failure(&self) -> Option<prometeu_bytecode::ResourceFailure> {
|
||||
match self {
|
||||
Self::VmTrap { trap } => trap.resource,
|
||||
Self::VmInit { error: VmInitError::RuntimeResourceLimit(resource) } => Some(*resource),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn kind(&self) -> &'static str {
|
||||
match self {
|
||||
Self::VmTrap { .. } => "vm_trap",
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
use prometeu_vm::VmInitError;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
pub(super) fn serialize(error: &VmInitError) -> Value {
|
||||
let code = match error {
|
||||
VmInitError::RegistryLoadFailed(_) => "registry_load_failed",
|
||||
VmInitError::RuntimeResourceLimit(_) => "runtime_resource_limit",
|
||||
VmInitError::InvalidFormat => "invalid_format",
|
||||
VmInitError::UnsupportedFormat => "unsupported_format",
|
||||
VmInitError::ImageLoadFailed(_) => "image_load_failed",
|
||||
VmInitError::LoaderPatchFailed(_) => "loader_patch_failed",
|
||||
VmInitError::EntrypointNotFound => "entrypoint_not_found",
|
||||
VmInitError::EntrypointArgumentsInvalid { .. } => "entrypoint_arguments_invalid",
|
||||
VmInitError::VerificationFailed(_) => "verification_failed",
|
||||
};
|
||||
let mut result = json!({"code":code,"message":format!("{error:?}")});
|
||||
match error {
|
||||
VmInitError::RegistryLoadFailed(load) => {
|
||||
result["load"] = json!(load);
|
||||
result["load"]["code"] = json!(load.code.tag());
|
||||
}
|
||||
VmInitError::RuntimeResourceLimit(resource) => result["resource"] = json!(resource),
|
||||
VmInitError::EntrypointArgumentsInvalid { function, slot, trap_code } => {
|
||||
result["entry"] = json!({"function":function,"slot":slot,"trapCode":trap_code});
|
||||
}
|
||||
VmInitError::LoaderPatchFailed(patch) => {
|
||||
use prometeu_vm::LoaderPatchError as P;
|
||||
result["binding"] = match patch {
|
||||
P::ResolveFailed(native) => json!(native),
|
||||
P::HostcallIndexOutOfBounds { pc, sysc_index, syscalls_len } => {
|
||||
json!({"reason":"hostcall_index_out_of_bounds","pc":pc,"syscallIndex":sysc_index,"syscallsLength":syscalls_len})
|
||||
}
|
||||
P::RawSyscallInPreloadArtifact { pc, syscall_id } => {
|
||||
json!({"reason":"raw_syscall","pc":pc,"syscallId":syscall_id})
|
||||
}
|
||||
P::UnusedSyscallDecl { sysc_index, module, name, version } => {
|
||||
json!({"reason":"unused_syscall","syscallIndex":sysc_index,"module":module,"name":name,"version":version})
|
||||
}
|
||||
P::HostcallRemaining { pc, sysc_index } => {
|
||||
json!({"reason":"hostcall_remaining","pc":pc,"syscallIndex":sysc_index})
|
||||
}
|
||||
P::DecodeFailed(_) => json!({"reason":"decode_failed"}),
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::CrashReport;
|
||||
use prometeu_bytecode::{
|
||||
ResourceFailure, ResourceReason, RuntimeResource,
|
||||
load_limits::{IdDomain, LoadCode, LoadFailure, LoadReason},
|
||||
};
|
||||
#[test]
|
||||
fn load_tag_and_reference_context_survive_without_fabricating_runtime_pc() {
|
||||
let error = LoadFailure::new(LoadCode::InvalidReference, LoadReason::TypeId)
|
||||
.at(6, 159)
|
||||
.record(4)
|
||||
.member(2)
|
||||
.reference(IdDomain::Type, 77)
|
||||
.in_function(3, Some(18));
|
||||
let report = CrashReport::VmInit { error: VmInitError::RegistryLoadFailed(error) };
|
||||
assert_eq!(report.pc(), None);
|
||||
let wire = report.init_diagnostic().unwrap();
|
||||
assert_eq!(wire["code"], "registry_load_failed");
|
||||
assert_eq!(wire["load"]["code"], "LOAD_INVALID_REFERENCE");
|
||||
for (field, value) in [
|
||||
("section", 6),
|
||||
("offset", 159),
|
||||
("record", 4),
|
||||
("member", 2),
|
||||
("referenced_id", 77),
|
||||
("function", 3),
|
||||
("pc", 18),
|
||||
] {
|
||||
assert_eq!(wire["load"][field], value);
|
||||
}
|
||||
assert_eq!(wire["load"]["id_domain"], "Type");
|
||||
assert_eq!(wire["load"]["reason"], "TypeId");
|
||||
}
|
||||
#[test]
|
||||
fn native_abi_and_resource_context_are_machine_fields() {
|
||||
let native = prometeu_hal::syscalls::DeclaredLoadError::AbiMismatch {
|
||||
module: "system".into(),
|
||||
name: "has_cart".into(),
|
||||
version: 1,
|
||||
declared_arg_slots: 0,
|
||||
declared_ret_slots: 2,
|
||||
expected_arg_slots: 0,
|
||||
expected_ret_slots: 1,
|
||||
};
|
||||
let wire = serialize(&VmInitError::LoaderPatchFailed(
|
||||
prometeu_vm::LoaderPatchError::ResolveFailed(native),
|
||||
));
|
||||
assert_eq!(wire["binding"]["reason"], "abi_mismatch");
|
||||
assert_eq!(wire["binding"]["module"], "system");
|
||||
assert_eq!(wire["binding"]["declared_ret_slots"], 2);
|
||||
assert_eq!(wire["binding"]["expected_ret_slots"], 1);
|
||||
let resource = ResourceFailure {
|
||||
resource: RuntimeResource::CallDepth,
|
||||
reason: ResourceReason::Limit,
|
||||
requested: 3,
|
||||
limit: 2,
|
||||
};
|
||||
let report = CrashReport::VmInit { error: VmInitError::RuntimeResourceLimit(resource) };
|
||||
assert_eq!(report.resource_failure(), Some(resource));
|
||||
let wire = report.init_diagnostic().unwrap();
|
||||
assert_eq!(wire["resource"]["resource"], "CallDepth");
|
||||
assert_eq!(wire["resource"]["reason"], "Limit");
|
||||
assert_eq!(wire["resource"]["requested"], 3);
|
||||
assert_eq!(wire["resource"]["limit"], 2);
|
||||
}
|
||||
#[test]
|
||||
fn all_load_codes_serialize_to_the_normative_tags() {
|
||||
for code in [
|
||||
LoadCode::InvalidFormat,
|
||||
LoadCode::UnsupportedFormat,
|
||||
LoadCode::InvalidReference,
|
||||
LoadCode::InvalidRegistry,
|
||||
LoadCode::InvalidCode,
|
||||
LoadCode::ResourceLimit,
|
||||
LoadCode::InvalidEntrypoint,
|
||||
] {
|
||||
assert_eq!(json!(code), code.tag());
|
||||
assert_eq!(serde_json::from_value::<LoadCode>(json!(code)).unwrap(), code);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ pub fn check_local_slot(
|
||||
message: format!("Local slot {} out of bounds for function (limit {})", slot, limit),
|
||||
pc,
|
||||
span: None,
|
||||
resource: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
//! Session accounting shared by owners, with reservations refunded on failure/drop.
|
||||
//! These quotas account VM domains, not process RSS or allocator metadata.
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt;
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(usize)]
|
||||
pub enum RuntimeResource {
|
||||
GuestBytes,
|
||||
HandleSlots,
|
||||
AuxiliaryBytes,
|
||||
TemporaryBytes,
|
||||
StringBytes,
|
||||
StringAllocations,
|
||||
IndividualStringBytes,
|
||||
CallDepth,
|
||||
}
|
||||
pub use prometeu_bytecode::{ResourceFailure, ResourceReason, RuntimeResource};
|
||||
const COUNT: usize = 8;
|
||||
const MIB: u64 = 1_048_576;
|
||||
const CEILINGS: [u64; COUNT] =
|
||||
@@ -51,30 +39,6 @@ impl RuntimeLimits {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ResourceReason {
|
||||
Limit,
|
||||
SizeOverflow,
|
||||
AllocationFailed,
|
||||
}
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct ResourceFailure {
|
||||
pub resource: RuntimeResource,
|
||||
pub reason: ResourceReason,
|
||||
pub requested: u64,
|
||||
pub limit: u64,
|
||||
}
|
||||
impl fmt::Display for ResourceFailure {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{:?}: {:?}, requested {}, limit {}",
|
||||
self.resource, self.reason, self.requested, self.limit
|
||||
)
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ResourceFailure {}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct State {
|
||||
limits: RuntimeLimits,
|
||||
|
||||
@@ -1264,6 +1264,9 @@ impl VirtualMachine {
|
||||
self.operand_stack.truncate(stack_height_before);
|
||||
}
|
||||
native_result.map_err(|fault| match fault {
|
||||
VmFault::ResourceLimit(resource) => {
|
||||
self.resource_trap(resource, opcode, pc_at_syscall)
|
||||
}
|
||||
VmFault::Trap(code, msg) => {
|
||||
self.trap(code, OpCode::Syscall as u16, msg, pc_at_syscall)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@ impl VirtualMachine {
|
||||
opcode: OpCode,
|
||||
pc: u32,
|
||||
) -> LogicalFrameEndingReason {
|
||||
self.trap(TRAP_RESOURCE_LIMIT, opcode as u16, error.to_string(), pc)
|
||||
let mut trap =
|
||||
self.program.create_trap(TRAP_RESOURCE_LIMIT, opcode as u16, error.to_string(), pc);
|
||||
trap.resource = Some(error);
|
||||
LogicalFrameEndingReason::Trap(trap)
|
||||
}
|
||||
|
||||
pub fn trap(
|
||||
|
||||
@@ -7,6 +7,9 @@ pub(super) struct SessionStringAllocator<'a> {
|
||||
pub budget: RuntimeBudget,
|
||||
}
|
||||
impl prometeu_hal::host_return::GuestStringAllocator for SessionStringAllocator<'_> {
|
||||
fn byte_limit(&self) -> u64 {
|
||||
self.budget.limit(RuntimeResource::StringBytes)
|
||||
}
|
||||
fn build(
|
||||
&mut self,
|
||||
length: usize,
|
||||
@@ -24,7 +27,7 @@ impl prometeu_hal::host_return::GuestStringAllocator for SessionStringAllocator<
|
||||
}
|
||||
}
|
||||
fn resource_fault(resource: ResourceFailure) -> VmFault {
|
||||
VmFault::Trap(TRAP_RESOURCE_LIMIT, resource.to_string())
|
||||
VmFault::ResourceLimit(resource)
|
||||
}
|
||||
|
||||
impl VirtualMachine {
|
||||
|
||||
@@ -527,7 +527,7 @@ fn native_string_failures_cannot_publish_partial_results_even_if_handler_ignores
|
||||
// This synthetic native implementation tests the bounded writer, not the
|
||||
// has-cart handler's ordinary Boolean semantic contract.
|
||||
assert!(
|
||||
matches!(report.reason,LogicalFrameEndingReason::Trap(info) if info.code==TRAP_RESOURCE_LIMIT && info.pc==0)
|
||||
matches!(report.reason,LogicalFrameEndingReason::Trap(info) if info.code==TRAP_RESOURCE_LIMIT && info.pc==0 && info.resource.is_some_and(|resource|resource.resource==RuntimeResource::StringBytes && resource.requested==3 && resource.limit==2))
|
||||
);
|
||||
assert!(vm.operand_stack.is_empty());
|
||||
assert_eq!(vm.budget.used(RuntimeResource::StringBytes), 0);
|
||||
|
||||
Reference in New Issue
Block a user