rate limit debug output in allow_untrustable_code()

This commit is contained in:
bunnie 2024-01-26 01:33:35 +08:00
parent 8703764b8e
commit 73b6d919af

View file

@ -1,3 +1,5 @@
use std::cell::RefCell;
use gam::{EXPECTED_APP_CONTEXTS, EXPECTED_BOOT_CONTEXTS}; use gam::{EXPECTED_APP_CONTEXTS, EXPECTED_BOOT_CONTEXTS};
/* /*
@ -21,7 +23,11 @@ pub(crate) struct TokenManager {
#[cfg(feature = "unsafe-app-loading")] #[cfg(feature = "unsafe-app-loading")]
extra_names: Vec<String>, extra_names: Vec<String>,
trng: trng::Trng, trng: trng::Trng,
tt: ticktimer_server::Ticktimer,
last_time: RefCell<u64>,
} }
const REPEAT_MSG_INTERVAL_MS: u64 = 5000;
impl<'a> TokenManager { impl<'a> TokenManager {
pub(crate) fn new(xns: &xous_names::XousNames) -> TokenManager { pub(crate) fn new(xns: &xous_names::XousNames) -> TokenManager {
TokenManager { TokenManager {
@ -29,6 +35,8 @@ impl<'a> TokenManager {
#[cfg(feature = "unsafe-app-loading")] #[cfg(feature = "unsafe-app-loading")]
extra_names: Vec::new(), extra_names: Vec::new(),
trng: trng::Trng::new(&xns).unwrap(), trng: trng::Trng::new(&xns).unwrap(),
tt: ticktimer_server::Ticktimer::new().unwrap(),
last_time: RefCell::new(0),
} }
} }
@ -45,20 +53,24 @@ impl<'a> TokenManager {
} else { } else {
// throw a bone to the dev who has to debug this error. This typically only triggers after a major // throw a bone to the dev who has to debug this error. This typically only triggers after a major
// refactor and some UX element was removed and we forgot to update it in this table here. // refactor and some UX element was removed and we forgot to update it in this table here.
log::info!("Occupied token slots: ***"); let now = self.tt.elapsed_ms();
for t in self.tokens.iter() { if *self.last_time.borrow() < now - REPEAT_MSG_INTERVAL_MS {
log::info!(" {}", t.name); log::info!("Occupied token slots: ***");
} for t in self.tokens.iter() {
log::info!("Expected token slots:"); log::info!(" {}", t.name);
for t in EXPECTED_BOOT_CONTEXTS.iter() { }
log::info!(" {}", t); log::info!("Expected token slots:");
} for t in EXPECTED_BOOT_CONTEXTS.iter() {
for t in EXPECTED_APP_CONTEXTS.iter() { log::info!(" {}", t);
log::info!(" {}", t); }
} for t in EXPECTED_APP_CONTEXTS.iter() {
#[cfg(feature = "unsafe-app-loading")] log::info!(" {}", t);
for t in self.extra_names.iter() { }
log::info!("{}", t); #[cfg(feature = "unsafe-app-loading")]
for t in self.extra_names.iter() {
log::info!("{}", t);
}
self.last_time.replace(now);
} }
false false
} }