Skip to content

Commit

Permalink
Use okref for mailbox packet struct
Browse files Browse the repository at this point in the history
Sometimes when results are unwrapped, the compiler will memcopy the
Ok struct. okref will instead borrow the inner type.

Using this on the packet struct saves about 4KiB of stack space.
  • Loading branch information
jhand2 committed Jan 15, 2025
1 parent 85b732a commit 9e91218
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use tagging::{GetTaggedTciCmd, TagTciCmd};

use caliptra_common::cprintln;

use caliptra_drivers::{CaliptraError, CaliptraResult, ResetReason};
use caliptra_drivers::{CaliptraError, CaliptraResult, ResetReason, okmutref};
use caliptra_registers::el2_pic_ctrl::El2PicCtrl;
use caliptra_registers::{mbox::enums::MboxStatusE, soc_ifc};
use dpe::{
Expand Down Expand Up @@ -230,10 +230,11 @@ fn handle_command(drivers: &mut Drivers) -> CaliptraResult<MboxStatusE> {
CommandId::AUTHORIZE_AND_STASH => AuthorizeAndStashCmd::execute(drivers, cmd_bytes),
CommandId::GET_IDEV_CSR => GetIdevCsrCmd::execute(drivers, cmd_bytes),
_ => Err(CaliptraError::RUNTIME_UNIMPLEMENTED_COMMAND),
}?;
};
let resp = okmutref(&mut resp)?;

// Send the response
Packet::copy_to_mbox(drivers, &mut resp)?;
Packet::copy_to_mbox(drivers, resp)?;

Ok(MboxStatusE::DataReady)
}
Expand Down

0 comments on commit 9e91218

Please sign in to comment.