41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
//! 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 {}
|