From fd98acc82e06d8ee3efe9479768269308d9e8c28 Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:10:25 +0100 Subject: [PATCH 01/10] xous-rs: Remove build.rs. Not used so it's best to remove it to avoid compiling it. Signed-off-by: Jean-Pierre De Jesus DIAZ --- xous-rs/build.rs | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 xous-rs/build.rs diff --git a/xous-rs/build.rs b/xous-rs/build.rs deleted file mode 100644 index c2bce4fe2..000000000 --- a/xous-rs/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("cargo:rerun-if-changed=build.rs"); -} From 9a393ed0aa697665620d6e8c410a066a2f27bc07 Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:25:09 +0100 Subject: [PATCH 02/10] xous-rs: Fix doc comment warning. --- xous-rs/src/syscall.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index 13d3f03e2..d0b6f290b 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -1986,7 +1986,7 @@ pub fn reply_and_receive_next( /// ## Arguments /// /// * **server**: The SID of the server to receive messages from -/// * **msg**: An Option specifying the message to return. +/// * **msg**: An `Option` specifying the message to return. /// * **return_type**: If 1 or 2, responds to a BlockingScalarMessage /// with a Scalar1 or a Scalar2. Otherwise, will respond /// as normal. From 6c9cc968f6e4cf5a5fb51bba178b0050a87f1f3d Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:33:30 +0100 Subject: [PATCH 03/10] xous-rs: Remove usize castings when not necessary. --- xous-rs/src/definitions.rs | 2 +- xous-rs/src/syscall.rs | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/xous-rs/src/definitions.rs b/xous-rs/src/definitions.rs index d7da743c5..6b90c2301 100644 --- a/xous-rs/src/definitions.rs +++ b/xous-rs/src/definitions.rs @@ -425,7 +425,7 @@ impl Result { 9, me_enc[0], me_enc[1], me_enc[2], me_enc[3], me_enc[4], me_enc[5], me_enc[6], ] } - Result::ThreadID(ctx) => [10, *ctx as usize, 0, 0, 0, 0, 0, 0], + Result::ThreadID(ctx) => [10, *ctx, 0, 0, 0, 0, 0, 0], Result::ProcessID(pid) => [11, pid.get() as _, 0, 0, 0, 0, 0, 0], Result::Unimplemented => [21, 0, 0, 0, 0, 0, 0, 0], Result::BlockedProcess => [13, 0, 0, 0, 0, 0, 0, 0], diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index d0b6f290b..576bc7348 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -728,7 +728,7 @@ impl SysCall { SysCall::ReturnToParent(a1, a2) => [ SysCallNumber::ReturnToParent as usize, a1.get() as usize, - *a2 as usize, + *a2, 0, 0, 0, @@ -751,7 +751,7 @@ impl SysCall { SysCall::SwitchTo(a1, a2) => [ SysCallNumber::SwitchTo as usize, a1.get() as usize, - *a2 as usize, + *a2, 0, 0, 0, @@ -770,7 +770,7 @@ impl SysCall { ], SysCall::IncreaseHeap(a1, a2) => [ SysCallNumber::IncreaseHeap as usize, - *a1 as usize, + *a1, a2.bits(), 0, 0, @@ -780,7 +780,7 @@ impl SysCall { ], SysCall::DecreaseHeap(a1) => [ SysCallNumber::DecreaseHeap as usize, - *a1 as usize, + *a1, 0, 0, 0, @@ -841,17 +841,17 @@ impl SysCall { SysCallNumber::SendMessage as usize, *a1 as usize, a2.message_type(), - mm.id as usize, + mm.id, mm.buf.as_ptr() as usize, mm.buf.len(), - mm.offset.map(|x| x.get()).unwrap_or(0) as usize, - mm.valid.map(|x| x.get()).unwrap_or(0) as usize, + mm.offset.map(|x| x.get()).unwrap_or(0), + mm.valid.map(|x| x.get()).unwrap_or(0), ], Message::Scalar(sc) | Message::BlockingScalar(sc) => [ SysCallNumber::SendMessage as usize, *a1 as usize, a2.message_type(), - sc.id as usize, + sc.id, sc.arg1, sc.arg2, sc.arg3, @@ -914,17 +914,17 @@ impl SysCall { SysCallNumber::TrySendMessage as usize, *a1 as usize, a2.message_type(), - mm.id as usize, + mm.id, mm.buf.as_ptr() as usize, mm.buf.len(), - mm.offset.map(|x| x.get()).unwrap_or(0) as usize, - mm.valid.map(|x| x.get()).unwrap_or(0) as usize, + mm.offset.map(|x| x.get()).unwrap_or(0), + mm.valid.map(|x| x.get()).unwrap_or(0), ], Message::Scalar(sc) | Message::BlockingScalar(sc) => [ SysCallNumber::TrySendMessage as usize, *a1 as usize, a2.message_type(), - sc.id as usize, + sc.id, sc.arg1, sc.arg2, sc.arg3, @@ -978,7 +978,7 @@ impl SysCall { ], SysCall::JoinThread(tid) => [ SysCallNumber::JoinThread as usize, - *tid as usize, + *tid, 0, 0, 0, @@ -1073,13 +1073,13 @@ impl SysCall { MemoryAddress::new(a3), ), SysCallNumber::FreeInterrupt => SysCall::FreeInterrupt(a1), - SysCallNumber::SwitchTo => SysCall::SwitchTo(pid_from_usize(a1)?, a2 as usize), + SysCallNumber::SwitchTo => SysCall::SwitchTo(pid_from_usize(a1)?, a2), SysCallNumber::ReadyThreads => SysCall::ReadyThreads(pid_from_usize(a1)?), SysCallNumber::IncreaseHeap => SysCall::IncreaseHeap( - a1 as usize, + a1, crate::MemoryFlags::from_bits(a2).ok_or(Error::InvalidSyscall)?, ), - SysCallNumber::DecreaseHeap => SysCall::DecreaseHeap(a1 as usize), + SysCallNumber::DecreaseHeap => SysCall::DecreaseHeap(a1), SysCallNumber::UpdateMemoryFlags => SysCall::UpdateMemoryFlags( unsafe { MemoryRange::new(a1, a2) }?, crate::MemoryFlags::from_bits(a3).ok_or(Error::InvalidSyscall)?, From 014137819223e1bd8b56dde7b6d763b1f8133fce Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:34:44 +0100 Subject: [PATCH 04/10] xous-rs: Remove reference on self match. --- xous-rs/src/definitions/messages/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xous-rs/src/definitions/messages/mod.rs b/xous-rs/src/definitions/messages/mod.rs index 5b93bf45a..60a127a44 100644 --- a/xous-rs/src/definitions/messages/mod.rs +++ b/xous-rs/src/definitions/messages/mod.rs @@ -276,7 +276,7 @@ impl Message { } pub fn to_usize(&self) -> [usize; 6] { - let ret = match &*self { + let ret = match self { Message::MutableBorrow(m) => (0, m.to_usize()), Message::Borrow(m) => (1, m.to_usize()), Message::Move(m) => (2, m.to_usize()), From 94737e9be2f07f25569bc891f7fb4f13e92cba09 Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:35:59 +0100 Subject: [PATCH 05/10] xous-rs: Simplify return expressions. --- xous-rs/src/definitions/messages/envelope.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xous-rs/src/definitions/messages/envelope.rs b/xous-rs/src/definitions/messages/envelope.rs index cc9ba3fcf..d4c5fe766 100644 --- a/xous-rs/src/definitions/messages/envelope.rs +++ b/xous-rs/src/definitions/messages/envelope.rs @@ -91,10 +91,10 @@ impl Envelope { return Err((ManuallyDrop::into_inner(manual_self), e)); } - return Err(( + Err(( ManuallyDrop::into_inner(manual_self), crate::Error::MemoryInUse, - )); + )) } Message::BlockingScalar(_) => { let result = crate::send_message(connection, body); @@ -113,10 +113,10 @@ impl Envelope { } return Ok(()); } - return Err(( + Err(( ManuallyDrop::into_inner(manual_self), crate::Error::MemoryInUse, - )); + )) } Message::Borrow(_) | Message::MutableBorrow(_) | Message::Scalar(_) => { From 0a1382224ac1344997dbf38b0c2ae73841e78cad Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:39:06 +0100 Subject: [PATCH 06/10] xous-rs: hosted: Do not pass &mut data. data is already a &mut [_] so we were passing &mut &mut [_]. --- xous-rs/src/arch/hosted/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xous-rs/src/arch/hosted/mod.rs b/xous-rs/src/arch/hosted/mod.rs index ec20370ef..c4a0eb9b3 100644 --- a/xous-rs/src/arch/hosted/mod.rs +++ b/xous-rs/src/arch/hosted/mod.rs @@ -262,7 +262,7 @@ fn read_next_syscall_result( } else if kind == CallMemoryKind::Borrow || kind == CallMemoryKind::MutableBorrow { // Read the buffer back from the remote host. use core::slice; - let mut data = unsafe { slice::from_raw_parts_mut(mem.as_mut_ptr(), mem.len()) }; + let data = unsafe { slice::from_raw_parts_mut(mem.as_mut_ptr(), mem.len()) }; // If it's a Borrow, verify the contents haven't changed by saving the previous // buffer in a Vec called `previous_data`. @@ -272,7 +272,7 @@ fn read_next_syscall_result( }; // Read the incoming data from the network. - if let Err(e) = stream.read_exact(&mut data) { + if let Err(e) = stream.read_exact(data) { eprintln!("Server shut down: {}", e); std::process::exit(0); } From b4e020b027e7af6e0781aed43dd844c4b66d2dc8 Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:41:35 +0100 Subject: [PATCH 07/10] xous-rs: Simplify TcpStream::connect. --- xous-rs/src/arch/hosted/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xous-rs/src/arch/hosted/mod.rs b/xous-rs/src/arch/hosted/mod.rs index c4a0eb9b3..7fedcf26e 100644 --- a/xous-rs/src/arch/hosted/mod.rs +++ b/xous-rs/src/arch/hosted/mod.rs @@ -49,7 +49,7 @@ lazy_static::lazy_static! { // Note: &* is required due to how `lazy_static` works behind the scenes: // https://github.com/rust-lang-nursery/lazy-static.rs/issues/119#issuecomment-419595818 - let mut conn = TcpStream::connect(&*NETWORK_CONNECT_ADDRESS).expect("unable to connect to Xous kernel"); + let mut conn = TcpStream::connect(*NETWORK_CONNECT_ADDRESS).expect("unable to connect to Xous kernel"); // Disable Nagel's algorithm, since we're running locally and managing buffers ourselves conn.set_nodelay(true).unwrap(); From c85658def9f9c0a7abc0a9f1cbbec193f52deee6 Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:42:07 +0100 Subject: [PATCH 08/10] xous-rs: Do not pass reference to command args. --- xous-rs/src/arch/hosted/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xous-rs/src/arch/hosted/process.rs b/xous-rs/src/arch/hosted/process.rs index a6ff8b252..36f96022c 100644 --- a/xous-rs/src/arch/hosted/process.rs +++ b/xous-rs/src/arch/hosted/process.rs @@ -156,7 +156,7 @@ pub fn create_process_post( // println!("Launching process..."); Command::new(shell) - .args(&args) + .args(args) .env("XOUS_SERVER", server_env) .env("XOUS_PID", pid_env) .env("XOUS_PROCESS_NAME", process_name_env) From 233108675508ffb890ec92ff415d8fc6fa0990a2 Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:43:05 +0100 Subject: [PATCH 09/10] xous-rs: Omit 'static lifetime on consts. --- xous-rs/src/definitions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xous-rs/src/definitions.rs b/xous-rs/src/definitions.rs index 6b90c2301..4165a78d6 100644 --- a/xous-rs/src/definitions.rs +++ b/xous-rs/src/definitions.rs @@ -52,8 +52,8 @@ pub const BASE_QUANTA_MS: u32 = 10; // where _|TT|_ and _|TE|_ are bookends around the data to be reported // is a single-word identifier that routes the data to a given parser // is free-form data, which will be split at comma boundaries by the parser -pub const BOOKEND_START: &'static str = "_|TT|_"; -pub const BOOKEND_END: &'static str = "_|TE|_"; +pub const BOOKEND_START: &str = "_|TT|_"; +pub const BOOKEND_END: &str = "_|TE|_"; #[cfg(not(target_os = "xous"))] use core::sync::atomic::AtomicU64; From b265985f06aae8564d92fe271f85e57d30e9604f Mon Sep 17 00:00:00 2001 From: Jean-Pierre De Jesus DIAZ Date: Fri, 1 Dec 2023 11:45:25 +0100 Subject: [PATCH 10/10] xous-rs: Change into_iter to iter. --- xous-rs/src/arch/hosted/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xous-rs/src/arch/hosted/process.rs b/xous-rs/src/arch/hosted/process.rs index 36f96022c..ca9f5d99b 100644 --- a/xous-rs/src/arch/hosted/process.rs +++ b/xous-rs/src/arch/hosted/process.rs @@ -71,7 +71,7 @@ impl TryFrom<[usize; 7]> for ProcessInit { type Error = crate::Error; fn try_from(src: [usize; 7]) -> core::result::Result { let mut exploded = vec![]; - for word in src[0..4].into_iter() { + for word in src[0..4].iter() { exploded.extend_from_slice(&(*word as u32).to_le_bytes()); } let mut key = [0u8; 16];