mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
start to lay out skeleton for pddb
This commit is contained in:
parent
7ef9fd011c
commit
e4c79a5f47
6 changed files with 287 additions and 6 deletions
105
Cargo.lock
generated
105
Cargo.lock
generated
|
|
@ -41,6 +41,17 @@ dependencies = [
|
|||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.15"
|
||||
|
|
@ -225,6 +236,27 @@ version = "3.7.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631"
|
||||
|
||||
[[package]]
|
||||
name = "bytecheck"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb738a1e65989ecdcd5bba16079641bd7209688fa546e1064832fd6e012fd32a"
|
||||
dependencies = [
|
||||
"bytecheck_derive",
|
||||
"ptr_meta",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytecheck_derive"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3b4dff26fdc9f847dab475c9fec16f2cba82d5aa1f09981b87c44520721e10a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.2"
|
||||
|
|
@ -851,6 +883,15 @@ dependencies = [
|
|||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.18"
|
||||
|
|
@ -1328,6 +1369,22 @@ dependencies = [
|
|||
"sdl2-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pddb"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"log-server",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"rkyv 0.7.18",
|
||||
"susres",
|
||||
"ticktimer-server",
|
||||
"utralib",
|
||||
"xous",
|
||||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "peeking_take_while"
|
||||
version = "0.1.2"
|
||||
|
|
@ -1374,18 +1431,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ptr_meta"
|
||||
version = "0.1.1"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aad980f4bb4053abd4733b1680024a8c71ffde345f6e584c6af9eb6f0067a198"
|
||||
checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1"
|
||||
dependencies = [
|
||||
"ptr_meta_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ptr_meta_derive"
|
||||
version = "0.1.1"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7bcd6232fa7d7fcd15703da5c07c9f10d203ee4fdf6ecf6d7ac5056db78089a3"
|
||||
checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -1556,6 +1613,15 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rend"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d0351a2e529ee30d571ef31faa5a4e0b9addaad087697b77efb20d2809e41c7"
|
||||
dependencies = [
|
||||
"bytecheck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.16.20"
|
||||
|
|
@ -1592,6 +1658,20 @@ dependencies = [
|
|||
"rkyv_derive 0.4.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rkyv"
|
||||
version = "0.7.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f371763528cb5a45ff01879d08355c39d49b849e2e6e665989abe3262997bde0"
|
||||
dependencies = [
|
||||
"bytecheck",
|
||||
"hashbrown",
|
||||
"ptr_meta",
|
||||
"rend",
|
||||
"rkyv_derive 0.7.18",
|
||||
"seahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rkyv-test-client"
|
||||
version = "0.1.0"
|
||||
|
|
@ -1644,6 +1724,17 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rkyv_derive"
|
||||
version = "0.7.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97fc962ad6ffbcc218212c465318c7c151221474350b281b4912f4890ea590b5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "root-keys"
|
||||
version = "0.1.0"
|
||||
|
|
@ -1780,6 +1871,12 @@ dependencies = [
|
|||
"version-compare",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "seahash"
|
||||
version = "4.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.4"
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ default-members = [
|
|||
"services/root-keys",
|
||||
"services/jtag",
|
||||
"services/oqc-test",
|
||||
"services/test-stub2"
|
||||
"services/test-stub2",
|
||||
"services/pddb",
|
||||
]
|
||||
members = [
|
||||
"xous-ipc",
|
||||
|
|
@ -81,7 +82,8 @@ members = [
|
|||
"services/jtag",
|
||||
"tools/wycheproof-import",
|
||||
"services/oqc-test",
|
||||
"services/test-stub2"
|
||||
"services/test-stub2",
|
||||
"services/pddb",
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
|
|
|
|||
23
services/pddb/Cargo.toml
Normal file
23
services/pddb/Cargo.toml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
[package]
|
||||
name = "pddb"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = "Plausibly Deniable Database"
|
||||
|
||||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
log-server = { path = "../log-server" }
|
||||
ticktimer-server = { path = "../ticktimer-server" }
|
||||
xous-names = { path = "../xous-names" }
|
||||
log = "0.4"
|
||||
num-derive = {version = "0.3", default-features = false}
|
||||
num-traits = {version = "0.2", default-features = false}
|
||||
susres = {path = "../susres"}
|
||||
rkyv = "0.7.18"
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = { path = "../../utralib"}
|
||||
|
||||
[features]
|
||||
default = []
|
||||
9
services/pddb/src/api.rs
Normal file
9
services/pddb/src/api.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
pub(crate) const SERVER_NAME_PDDB: &str = "_Plausibly Deniable Database_";
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum Opcode {
|
||||
|
||||
/// Suspend/resume callback
|
||||
SuspendResume,
|
||||
}
|
||||
33
services/pddb/src/lib.rs
Normal file
33
services/pddb/src/lib.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
|
||||
pub mod api;
|
||||
use xous::{CID, send_message};
|
||||
use num_traits::*;
|
||||
|
||||
pub struct Pddb {
|
||||
conn: CID,
|
||||
}
|
||||
impl Pddb {
|
||||
pub fn new(xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
|
||||
REFCOUNT.store(REFCOUNT.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
|
||||
let conn = xns.request_connection_blocking(api::SERVER_NAME_CODEC).expect("Can't connect to Pddb server");
|
||||
Ok(Pddb {
|
||||
conn
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
static REFCOUNT: AtomicU32 = AtomicU32::new(0);
|
||||
impl Drop for Pddb {
|
||||
fn drop(&mut self) {
|
||||
// the connection to the server side must be reference counted, so that multiple instances of this object within
|
||||
// a single process do not end up de-allocating the CID on other threads before they go out of scope.
|
||||
// Note to future me: you want this. Don't get rid of it because you think, "nah, nobody will ever make more than one copy of this object".
|
||||
if REFCOUNT.load(Ordering::Relaxed) == 0 {
|
||||
unsafe{xous::disconnect(self.conn).unwrap();}
|
||||
}
|
||||
// if there was object-specific state (such as a one-time use server for async callbacks, specific to the object instance),
|
||||
// de-allocate those items here. They don't need a reference count because they are object-specific
|
||||
}
|
||||
}
|
||||
117
services/pddb/src/main.rs
Normal file
117
services/pddb/src/main.rs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
mod api;
|
||||
|
||||
use num_traits::*;
|
||||
|
||||
#[cfg(any(target_os = "none", target_os = "xous"))]
|
||||
mod implementation {
|
||||
use utralib::generated::*;
|
||||
// use crate::api::*;
|
||||
use log::info;
|
||||
use susres::{RegManager, RegOrField, SuspendResume};
|
||||
|
||||
pub struct Pddb {
|
||||
csr: utralib::CSR<u32>,
|
||||
fifo: xous::MemoryRange,
|
||||
susres_manager: RegManager::<{utra::audio::AUDIO_NUMREGS}>,
|
||||
}
|
||||
|
||||
impl Pddb {
|
||||
pub fn new() -> Pddb {
|
||||
let csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::audio::HW_AUDIO_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map Audio CSR range");
|
||||
let fifo = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utralib::HW_AUDIO_MEM),
|
||||
None,
|
||||
utralib::HW_AUDIO_MEM_LEN,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map Audio CSR range");
|
||||
|
||||
let mut pddb = Pddb {
|
||||
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
||||
susres_manager: RegManager::new(csr.as_mut_ptr() as *mut u32),
|
||||
fifo,
|
||||
};
|
||||
|
||||
pddb
|
||||
}
|
||||
|
||||
pub fn suspend(&mut self) {
|
||||
self.susres_manager.suspend();
|
||||
}
|
||||
pub fn resume(&mut self) {
|
||||
self.susres_manager.resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// a stub to try to avoid breaking hosted mode for as long as possible.
|
||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||
mod implementation {
|
||||
use log::info;
|
||||
|
||||
pub struct Pddb {
|
||||
}
|
||||
|
||||
impl Pddb {
|
||||
pub fn new() -> Pddb {
|
||||
Pddb {
|
||||
}
|
||||
}
|
||||
pub fn suspend(&self) {
|
||||
}
|
||||
pub fn resume(&self) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
use crate::implementation::Pddb;
|
||||
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let pddb_sid = xns.register_name(api::SERVER_NAME_PDDB).expect("can't register server");
|
||||
log::trace!("registered with NS -- {:?}", pddb_sid);
|
||||
|
||||
let mut pddb = Pddb::new();
|
||||
|
||||
log::trace!("ready to accept requests");
|
||||
|
||||
// register a suspend/resume listener
|
||||
let sr_cid = xous::connect(pddb_sid).expect("couldn't create suspend callback connection");
|
||||
let mut susres = susres::Susres::new(&xns, api::Opcode::SuspendResume as u32, sr_cid).expect("couldn't create suspend/resume object");
|
||||
|
||||
loop {
|
||||
let msg = xous::receive_message(pddb_sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(api::Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, {
|
||||
pddb.suspend();
|
||||
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
||||
pddb.resume();
|
||||
}),
|
||||
None => {
|
||||
log::error!("couldn't convert opcode");
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up our program
|
||||
log::trace!("main loop exit, destroying servers");
|
||||
xns.unregister_server(pddb_sid).unwrap();
|
||||
xous::destroy_server(pddb_sid).unwrap();
|
||||
log::trace!("quitting");
|
||||
xous::terminate_process(0)
|
||||
}
|
||||
Loading…
Reference in a new issue