2022-08-01 14:49:28 -07:00
|
|
|
/// These metadata fields contain VM state specific to a particular context.
|
|
|
|
|
#[derive(Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, Debug)]
|
|
|
|
|
pub(crate) enum ContextMetadata {
|
|
|
|
|
/// The ID of the context which created this one.
|
|
|
|
|
ParentContext = 0,
|
|
|
|
|
/// The program counter to return to when we return to the parent context.
|
|
|
|
|
ParentProgramCounter = 1,
|
2022-08-01 21:21:35 -07:00
|
|
|
/// If we're in a system call, this holds the userspace program counter to return to.
|
|
|
|
|
UserspaceProgramCounter = 2,
|
|
|
|
|
CalldataSize = 3,
|
|
|
|
|
ReturndataSize = 4,
|
2022-08-01 14:49:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ContextMetadata {
|
2022-08-01 21:21:35 -07:00
|
|
|
pub(crate) const COUNT: usize = 5;
|
2022-08-01 14:49:28 -07:00
|
|
|
|
|
|
|
|
pub(crate) fn all() -> [Self; Self::COUNT] {
|
|
|
|
|
[
|
|
|
|
|
Self::ParentContext,
|
|
|
|
|
Self::ParentProgramCounter,
|
2022-08-01 21:21:35 -07:00
|
|
|
Self::UserspaceProgramCounter,
|
2022-08-01 14:49:28 -07:00
|
|
|
Self::CalldataSize,
|
|
|
|
|
Self::ReturndataSize,
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The variable name that gets passed into kernel assembly code.
|
|
|
|
|
pub(crate) fn var_name(&self) -> &'static str {
|
|
|
|
|
match self {
|
|
|
|
|
ContextMetadata::ParentContext => "CTX_METADATA_PARENT_CONTEXT",
|
|
|
|
|
ContextMetadata::ParentProgramCounter => "CTX_METADATA_PARENT_PC",
|
2022-08-01 21:21:35 -07:00
|
|
|
ContextMetadata::UserspaceProgramCounter => "CTX_METADATA_USERSPACE_PC",
|
2022-08-01 14:49:28 -07:00
|
|
|
ContextMetadata::CalldataSize => "CTX_METADATA_CALLDATA_SIZE",
|
|
|
|
|
ContextMetadata::ReturndataSize => "CTX_METADATA_RETURNDATA_SIZE",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|