From 6ccbacf65f7b808afa085b7d7c1ae95c267e77ca Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 7 Jan 2021 18:51:14 +0800 Subject: [PATCH] loader: assign sections to process ownership This ensures these addresses aren't re-used and handed out again by memory allocation. Signed-off-by: Sean Cross --- Cargo.lock | 1 + services/com/Cargo.toml | 1 + services/com/src/main.rs | 15 +++++-------- services/shell/src/main.rs | 2 +- services/xous-names/src/lib.rs | 38 +++++++++++++++++++++++++++------ services/xous-names/src/main.rs | 16 ++++++++------ xous-rs/src/definitions.rs | 3 +++ 7 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d89b36da7..942cf5e66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,6 +151,7 @@ dependencies = [ "typenum", "utralib", "xous", + "xous-names", ] [[package]] diff --git a/services/com/Cargo.toml b/services/com/Cargo.toml index 70a67f179..ba24e323d 100644 --- a/services/com/Cargo.toml +++ b/services/com/Cargo.toml @@ -10,6 +10,7 @@ xous = { path = "../../xous-rs" } heapless = "0.5" log-server = { path = "../log-server" } ticktimer-server = { path = "../ticktimer-server" } +xous-names = { path = "../xous-names" } log = "0.4" com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "a9e05f414accef08348b77be6fc0f668b319e6ff" } #com_rs = { path = "../../../betrusted-ec/sw/com_rs" } diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 46bb4076c..b5c414790 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -237,22 +237,17 @@ fn xmain() -> ! { log_server::init_wait().unwrap(); + xous_names::register_name("COM manager to EC"); + let com_server = xous::create_server_with_address(b"com ").expect("Couldn't create COM server"); let shell_id = xous::SID::from_bytes(b"shell ").unwrap(); let shell_conn = xous::connect(shell_id).unwrap(); - /* - info!("Test NS registration"); - let registration = Registration::new(); - let mut sendable_registration = Sendable::new(registration) - .expect("can't create sendable registration structure"); - write!(sendable_registration.name, "A test Name!").unwrap(); - info!("namserver registration input: {:?}", sendable_registration.success); - sendable_registration.lend_mut(ns_conn, sendable_registration.mid()).expect("nameserver registration failure!"); - info!("nameserver registration result: {:?}, {:?}", sendable_registration.success, sendable_registration.sid); -*/ + let testconn = xous_names::request_connection("COM manager to EC"); + info!("testconn result: {:?}", testconn); + let agent_conn: usize; if cfg!(feature = "fccagent") { let agent_id = xous::SID::from_bytes(b"fcc-agent-server").unwrap(); diff --git a/services/shell/src/main.rs b/services/shell/src/main.rs index 2aabd54c1..0094a34a9 100644 --- a/services/shell/src/main.rs +++ b/services/shell/src/main.rs @@ -357,7 +357,7 @@ fn shell_main() -> ! { info!("memtest: iter {}", iter); iter += 1; } - + // Periodic tasks if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) { if elapsed_time - last_time > 500 { diff --git a/services/xous-names/src/lib.rs b/services/xous-names/src/lib.rs index 167756a70..6134eec7b 100644 --- a/services/xous-names/src/lib.rs +++ b/services/xous-names/src/lib.rs @@ -2,17 +2,41 @@ pub mod api; -/* -Calls are made using the xous::ipc::Sendable IPC wrapper, for example: +use xous::ipc::*; +use api::{Registration, Lookup}; +use core::fmt::Write; - use xous::ipc::*; +pub fn register_name(name: &str) -> Result { + let ns_id = xous::SID::from_bytes(b"xous-name-server").unwrap(); + let ns_conn = xous::connect(ns_id).unwrap(); - let mut registration = Registration::new(); + let registration = Registration::new(); let mut sendable_registration = Sendable::new(registration) .expect("can't create sendable registration structure"); + write!(sendable_registration.name, "{}", name).unwrap(); + sendable_registration.lend_mut(ns_conn, sendable_registration.mid()).expect("nameserver registration failure!"); - write!(sendable_registration.name, "I'm a server, please call me Fred!"); + Ok(sendable_registration.success) +} - sendable_registration.lend_mut(ns_conn, sendable_registration.mid()); +/// note: if this throws an AccessDenied error, you can retry with a request_authenticat_connection() call (to be written) +pub fn request_connection(name: &str) -> Result { + let ns_id = xous::SID::from_bytes(b"xous-name-server").unwrap(); + let ns_conn = xous::connect(ns_id).unwrap(); -*/ + let lookup = Lookup::new(); + let mut sendable_lookup = Sendable::new(lookup) + .expect("can't create sendable lookup structure"); + write!(sendable_lookup.name, "{}", name).unwrap(); + sendable_lookup.lend_mut(ns_conn, sendable_lookup.mid()).expect("nameserver lookup failure!"); + + if sendable_lookup.success { + Ok(sendable_lookup.cid) + } else { + if sendable_lookup.authenticate_request { + Err(xous::Error::AccessDenied) + } else { + Err(xous::Error::ServerNotFound) + } + } +} \ No newline at end of file diff --git a/services/xous-names/src/main.rs b/services/xous-names/src/main.rs index 6d21b0c3f..043a66f0c 100644 --- a/services/xous-names/src/main.rs +++ b/services/xous-names/src/main.rs @@ -58,17 +58,19 @@ fn xmain() -> ! { let lookup: &mut Lookup = unsafe { &mut *(m.buf.as_mut_ptr() as *mut Lookup) }; - /* info!("NS: Lookup request for {}", lookup.name); - if let Ok(server_sid) = name_table.get(lookup) { - lookup.success = true; - let sender_pid = &envelope.sender.pid()?; - let connection_id = xous::connect_for_process(sender_pid, server_sid).expect("NS: can't broker connection"); - lookup.cid = connection_id; + if let Some(server_sid) = name_table.get(&lookup.name) { + let sender_pid = envelope.sender.pid().expect("NS: can't extract sender PID on Lookup"); + match xous::connect_for_process(sender_pid, *server_sid).expect("NS: can't broker connection") { + xous::Result::ConnectionID(connection_id) => { + lookup.cid = connection_id; + lookup.success = true}, + _ => lookup.success = false + } } else { lookup.success = false; // no authenticate remedy currently supported, but we'd put that code somewhere around here eventually. - }*/ + } } else { error!("NS: unknown message ID received"); } diff --git a/xous-rs/src/definitions.rs b/xous-rs/src/definitions.rs index 456b87c53..c250566f0 100644 --- a/xous-rs/src/definitions.rs +++ b/xous-rs/src/definitions.rs @@ -154,6 +154,7 @@ pub enum Error { InvalidThread = 20, InvalidPID = 21, UnknownError = 22, + AccessDenied = 23, } impl Error { @@ -182,6 +183,7 @@ impl Error { 19 => ShareViolation, 20 => InvalidThread, 21 => InvalidPID, + 23 => AccessDenied, _ => UnknownError, } } @@ -210,6 +212,7 @@ impl Error { ShareViolation => 19, InvalidThread => 20, InvalidPID => 21, + AccessDenied => 23, UnknownError => usize::MAX, } }