part way through the main module, we have more clarity on the task

i think it's becoming clearer at this point that other elements
need to be implemented before we can attack this. leaving notes
and bread crumbs so I can come back to this branch later
This commit is contained in:
bunnie 2025-02-01 02:37:33 +08:00
parent ecaab9041f
commit 858d7a739f

View file

@ -1,6 +1,3 @@
#![cfg_attr(target_os = "none", no_std)]
#![cfg_attr(target_os = "none", no_main)]
extern crate bitfield; extern crate bitfield;
/// # PDDB - Plausibly Deniable DataBase /// # PDDB - Plausibly Deniable DataBase
/// ///
@ -369,12 +366,19 @@ mod api;
use api::*; use api::*;
mod backend; mod backend;
use backend::*; use backend::*;
#[cfg(feature = "gen1")]
mod ux; mod ux;
use rkyv::with::Identity; use rkyv::with::Identity;
#[cfg(feature = "gen1")]
use ux::*; use ux::*;
#[cfg(feature = "gen1")]
mod menu; mod menu;
#[cfg(feature = "gen1")]
use menu::*; use menu::*;
#[cfg(feature = "gen2")]
mod hw;
mod libstd; mod libstd;
#[cfg(not(target_os = "xous"))] #[cfg(not(target_os = "xous"))]
@ -399,6 +403,7 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::thread; use std::thread;
#[cfg(feature = "gen1")]
use locales::t; use locales::t;
use num_traits::*; use num_traits::*;
use rkyv::{ use rkyv::{
@ -504,12 +509,16 @@ fn wrapped_main() -> ! {
let entropy = Rc::new(RefCell::new(TrngPool::new())); let entropy = Rc::new(RefCell::new(TrngPool::new()));
// for less-secured user prompts (everything but password entry) // for less-secured user prompts (everything but password entry)
#[cfg(feature = "gen1")]
let modals = modals::Modals::new(&xns).expect("can't connect to Modals server"); let modals = modals::Modals::new(&xns).expect("can't connect to Modals server");
// our very own password modal. Password modals are precious and privately owned, to avoid // our very own password modal. Password modals are precious and privately owned, to avoid
// other processes from crafting them. // other processes from crafting them.
#[cfg(feature = "gen1")]
let pw_sid = xous::create_server().expect("couldn't create a server for the password UX handler"); let pw_sid = xous::create_server().expect("couldn't create a server for the password UX handler");
#[cfg(feature = "gen1")]
let pw_cid = xous::connect(pw_sid).expect("couldn't connect to the password UX handler"); let pw_cid = xous::connect(pw_sid).expect("couldn't connect to the password UX handler");
#[cfg(feature = "gen1")]
let pw_handle = thread::spawn({ let pw_handle = thread::spawn({
// this comment keeps rustfmt from flattening this block // this comment keeps rustfmt from flattening this block
move || password_ux_manager(xous::connect(pddb_sid).unwrap(), pw_sid) move || password_ux_manager(xous::connect(pddb_sid).unwrap(), pw_sid)
@ -555,8 +564,9 @@ fn wrapped_main() -> ! {
} }
}); });
// our menu handler
let my_cid = xous::connect(pddb_sid).unwrap(); let my_cid = xous::connect(pddb_sid).unwrap();
// our menu handler
#[cfg(feature = "gen1")]
let _ = thread::spawn({ let _ = thread::spawn({
let my_cid = my_cid.clone(); let my_cid = my_cid.clone();
move || { move || {
@ -664,6 +674,7 @@ fn wrapped_main() -> ! {
let mut scratch = [MaybeUninit::<u8>::uninit(); 256]; let mut scratch = [MaybeUninit::<u8>::uninit(); 256];
// register a suspend/resume listener // register a suspend/resume listener
#[cfg(feature = "gen1")]
let mut susres = let mut susres =
susres::Susres::new(Some(susres::SuspendOrder::Early), &xns, Opcode::SuspendResume as u32, my_cid) susres::Susres::new(Some(susres::SuspendOrder::Early), &xns, Opcode::SuspendResume as u32, my_cid)
.expect("couldn't create suspend/resume object"); .expect("couldn't create suspend/resume object");
@ -672,6 +683,7 @@ fn wrapped_main() -> ! {
let op: Opcode = FromPrimitive::from_usize(msg.body.id() & 0xffff).unwrap_or(Opcode::InvalidOpcode); let op: Opcode = FromPrimitive::from_usize(msg.body.id() & 0xffff).unwrap_or(Opcode::InvalidOpcode);
log::debug!("{:x?}", op); log::debug!("{:x?}", op);
match op { match op {
#[cfg(feature = "gen1")]
Opcode::SuspendResume => xous::msg_scalar_unpack!(msg, token, _, _, _, { Opcode::SuspendResume => xous::msg_scalar_unpack!(msg, token, _, _, _, {
basis_cache.suspend(&mut pddb_os); basis_cache.suspend(&mut pddb_os);
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume"); susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
@ -714,6 +726,11 @@ fn wrapped_main() -> ! {
// retries. // retries.
// If we need more nuance out of this routine, consider creating a custom public enum type to help // If we need more nuance out of this routine, consider creating a custom public enum type to help
// marshall this. // marshall this.
#[cfg(feature = "gen2")]
Opcode::TryMount => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
unimplemented!();
}),
#[cfg(feature = "gen1")]
Opcode::TryMount => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, { Opcode::TryMount => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
let llio = llio::Llio::new(&xns); let llio = llio::Llio::new(&xns);
while !llio.is_ec_ready() { while !llio.is_ec_ready() {
@ -2329,6 +2346,7 @@ fn wrapped_main() -> ! {
xous::terminate_process(0) xous::terminate_process(0)
} }
#[cfg(feature = "gen1")]
fn ensure_password(modals: &modals::Modals, pddb_os: &mut PddbOs, _pw_cid: xous::CID) -> PasswordState { fn ensure_password(modals: &modals::Modals, pddb_os: &mut PddbOs, _pw_cid: xous::CID) -> PasswordState {
log::info!("Requesting login password"); log::info!("Requesting login password");
loop { loop {
@ -2388,6 +2406,8 @@ fn ensure_password(modals: &modals::Modals, pddb_os: &mut PddbOs, _pw_cid: xous:
} }
} }
} }
#[cfg(feature = "gen1")]
fn try_mount_or_format( fn try_mount_or_format(
modals: &modals::Modals, modals: &modals::Modals,
pddb_os: &mut PddbOs, pddb_os: &mut PddbOs,