//! A shutdown request is authorization, never completion. The EL0 harness //! returns to its trusted kernel continuation before this token can be used. use super::lease_io::{Backend,Drain,Owner,Receipt,Failure}; #[derive(Clone,Copy,Debug,PartialEq,Eq)]pub enum Error{InvalidOwner,Owner,Arguments,Repeated,NoRequest} pub struct Authorized{owner:Owner} impl Authorized{ pub fn execute(self,drain:&mut Drain,deadline:u64)->Result{drain.drain(Owner{generation:self.owner.generation+1,..self.owner},deadline)} } pub struct Request{owner:Owner,requested:bool,pending:Option} impl Request{ pub fn new(owner:Owner)->Result{if owner.pid!=1||owner.generation==0{return Err(Error::InvalidOwner)}Ok(Self{owner,requested:false,pending:None})} pub fn request(&mut self,caller:Owner,args:[u64;3])->Result<(),Error>{ // Identity is the kernel's current EL0 context, not an argument or // user-controlled register purporting to name a PID/generation. if caller!=self.owner{return Err(Error::Owner)} if args!=[0;3]{return Err(Error::Arguments)} if self.requested{return Err(Error::Repeated)} self.requested=true;self.pending=Some(Authorized{owner:self.owner});Ok(()) } pub fn pending(&self)->bool{self.pending.is_some()} pub fn take(&mut self)->Result{self.pending.take().ok_or(Error::NoRequest)} }