Skip to content

Commit

Permalink
Merge pull request #456 from Foundation-Devices/wip/misc
Browse files Browse the repository at this point in the history
xous-rs: miscellaneous impromevements.
  • Loading branch information
bunnie authored Dec 1, 2023
2 parents 49c2e1a + b265985 commit 05aa899
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 33 deletions.
3 changes: 0 additions & 3 deletions xous-rs/build.rs

This file was deleted.

6 changes: 3 additions & 3 deletions xous-rs/src/arch/hosted/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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`.
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions xous-rs/src/arch/hosted/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl TryFrom<[usize; 7]> for ProcessInit {
type Error = crate::Error;
fn try_from(src: [usize; 7]) -> core::result::Result<ProcessInit, crate::Error> {
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];
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions xous-rs/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub const BASE_QUANTA_MS: u32 = 10;
// where _|TT|_ and _|TE|_ are bookends around the data to be reported
// <ident> is a single-word identifier that routes the data to a given parser
// <data> 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;
Expand Down Expand Up @@ -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],
Expand Down
8 changes: 4 additions & 4 deletions xous-rs/src/definitions/messages/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(_) => {
Expand Down
2 changes: 1 addition & 1 deletion xous-rs/src/definitions/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
34 changes: 17 additions & 17 deletions xous-rs/src/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -770,7 +770,7 @@ impl SysCall {
],
SysCall::IncreaseHeap(a1, a2) => [
SysCallNumber::IncreaseHeap as usize,
*a1 as usize,
*a1,
a2.bits(),
0,
0,
Expand All @@ -780,7 +780,7 @@ impl SysCall {
],
SysCall::DecreaseHeap(a1) => [
SysCallNumber::DecreaseHeap as usize,
*a1 as usize,
*a1,
0,
0,
0,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -978,7 +978,7 @@ impl SysCall {
],
SysCall::JoinThread(tid) => [
SysCallNumber::JoinThread as usize,
*tid as usize,
*tid,
0,
0,
0,
Expand Down Expand Up @@ -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)?,
Expand Down Expand Up @@ -1986,7 +1986,7 @@ pub fn reply_and_receive_next(
/// ## Arguments
///
/// * **server**: The SID of the server to receive messages from
/// * **msg**: An Option<MessageEnvelope> specifying the message to return.
/// * **msg**: An `Option<MessageEnvelope>` 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.
Expand Down

0 comments on commit 05aa899

Please sign in to comment.