mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
kernel: rework hosted network protocol
This fixes issues regarding passing memory between processes. We now properly catch `ReturnMemory` and give the memory back. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
7aab01c95d
commit
fa9a3e0954
10 changed files with 194 additions and 109 deletions
1
kernel/Cargo.lock
generated
1
kernel/Cargo.lock
generated
|
|
@ -513,6 +513,7 @@ name = "xous"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"debug-here",
|
||||
"hex",
|
||||
"lazy_static",
|
||||
"xous-macros",
|
||||
|
|
|
|||
|
|
@ -89,10 +89,10 @@ fn handle_connection(
|
|||
loop {
|
||||
let mut raw_data = [0u8; 9 * std::mem::size_of::<usize>()];
|
||||
if let Err(_e) = conn.read_exact(&mut raw_data) {
|
||||
// println!(
|
||||
// "KERNEL(?): Client disconnected: {} ({:?}). Shutting down virtual process.",
|
||||
// _e, _e
|
||||
// );
|
||||
println!(
|
||||
"KERNEL(?): Client disconnected: {} ({:?}). Shutting down virtual process.",
|
||||
_e, _e
|
||||
);
|
||||
sender.send(ServerMessage::Exit).ok();
|
||||
return;
|
||||
}
|
||||
|
|
@ -105,23 +105,33 @@ fn handle_connection(
|
|||
*word = usize::from_le_bytes(bytes.try_into().unwrap());
|
||||
}
|
||||
|
||||
if (packet_data[1] == xous_kernel::syscall::SysCallNumber::SendMessage as _
|
||||
|| packet_data[1] == xous_kernel::syscall::SysCallNumber::TrySendMessage as _)
|
||||
&& (packet_data[3] == 1 || packet_data[3] == 2 || packet_data[3] == 3)
|
||||
{
|
||||
let mut v = vec![0; packet_data[6]];
|
||||
if conn.read_exact(&mut v).is_err() {
|
||||
sender.send(ServerMessage::Exit).ok();
|
||||
return;
|
||||
}
|
||||
sender
|
||||
.send(ServerMessage::ServerPacketWithData(packet_data, v))
|
||||
.unwrap();
|
||||
} else {
|
||||
sender
|
||||
.send(ServerMessage::ServerPacket(packet_data))
|
||||
.unwrap();
|
||||
}
|
||||
sender
|
||||
.send(
|
||||
if (packet_data[1] == xous_kernel::syscall::SysCallNumber::SendMessage as _
|
||||
|| packet_data[1]
|
||||
== xous_kernel::syscall::SysCallNumber::TrySendMessage as _)
|
||||
&& (packet_data[3] == 1 || packet_data[3] == 2 || packet_data[3] == 3)
|
||||
{
|
||||
let mut v = vec![0; packet_data[6]];
|
||||
if conn.read_exact(&mut v).is_err() {
|
||||
sender.send(ServerMessage::Exit).ok();
|
||||
return;
|
||||
}
|
||||
ServerMessage::ServerPacketWithData(packet_data, v)
|
||||
} else if packet_data[1]
|
||||
== xous_kernel::syscall::SysCallNumber::ReturnMemory as _
|
||||
{
|
||||
let mut v = vec![0; packet_data[4]];
|
||||
if conn.read_exact(&mut v).is_err() {
|
||||
sender.send(ServerMessage::Exit).ok();
|
||||
return;
|
||||
}
|
||||
ServerMessage::ServerPacketWithData(packet_data, v)
|
||||
} else {
|
||||
ServerMessage::ServerPacket(packet_data)
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +158,10 @@ fn handle_connection(
|
|||
|
||||
for msg in receiver {
|
||||
match msg {
|
||||
ServerMessage::Exit => break,
|
||||
ServerMessage::Exit => {
|
||||
println!("KERNEL({}): Received ServerMessage::Exit", pid);
|
||||
break;
|
||||
}
|
||||
ServerMessage::ServerPacket(pkt) => {
|
||||
let thread_id = pkt[0];
|
||||
let call = xous_kernel::SysCall::from_args(
|
||||
|
|
@ -216,8 +229,28 @@ fn handle_connection(
|
|||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
xous_kernel::Message::Scalar(_) | xous_kernel::Message::BlockingScalar(_) => (),
|
||||
xous_kernel::Message::Scalar(_)
|
||||
| xous_kernel::Message::BlockingScalar(_) => (),
|
||||
}
|
||||
},
|
||||
SysCall::ReturnMemory(_sender, ref mut buf) => {
|
||||
let sliced_data = data.into_boxed_slice();
|
||||
assert_eq!(
|
||||
sliced_data.len(),
|
||||
buf.len(),
|
||||
"deconstructed data {} != message buf length {}",
|
||||
sliced_data.len(),
|
||||
buf.len()
|
||||
);
|
||||
buf.addr =
|
||||
match MemoryAddress::new(Box::into_raw(sliced_data)
|
||||
as *mut u8
|
||||
as usize)
|
||||
{
|
||||
Some(a) => a,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
}
|
||||
_ => panic!("unsupported message type"),
|
||||
}
|
||||
|
|
@ -228,7 +261,10 @@ fn handle_connection(
|
|||
}
|
||||
}
|
||||
}
|
||||
// eprintln!("KERNEL({}): Finished the thread so sending TerminateProcess", pid);
|
||||
eprintln!(
|
||||
"KERNEL({}): Finished the thread so sending TerminateProcess",
|
||||
pid
|
||||
);
|
||||
chn.send(ThreadMessage::SysCall(
|
||||
pid,
|
||||
1,
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ pub fn enable_irq(_irq_no: usize) {
|
|||
unimplemented!();
|
||||
}
|
||||
|
||||
pub unsafe fn take_isr_return_pair() -> Option<(PID, TID)> {
|
||||
unimplemented!()
|
||||
}
|
||||
// pub unsafe fn take_isr_return_pair() -> Option<(PID, TID)> {
|
||||
// unimplemented!()
|
||||
// }
|
||||
|
||||
pub unsafe fn set_isr_return_pair(_pid: PID, _ctx: TID) {
|
||||
unimplemented!()
|
||||
|
|
|
|||
|
|
@ -288,8 +288,16 @@ impl Process {
|
|||
response.extend_from_slice(&word.to_le_bytes());
|
||||
}
|
||||
|
||||
if let Some(mem) = result.memory() {
|
||||
let s = unsafe { core::slice::from_raw_parts(mem.as_ptr(), mem.len()) };
|
||||
response.extend_from_slice(&s);
|
||||
}
|
||||
|
||||
// If there is memory to return for this thread, also return that.
|
||||
if let Some(buf) = process.memory_to_return[tid - 1].take() {
|
||||
if result.memory().is_some() {
|
||||
panic!("Result has memory and we're also returning memory!");
|
||||
}
|
||||
// if let xous_kernel::Result::Message(_) = result {
|
||||
// } else {
|
||||
// panic!(
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ pub unsafe fn set_isr_return_pair(pid: PID, tid: TID) {
|
|||
PREVIOUS_PAIR = Some((pid, tid));
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub unsafe fn take_isr_return_pair() -> Option<(PID, TID)> {
|
||||
PREVIOUS_PAIR.take()
|
||||
}
|
||||
// #[allow(dead_code)]
|
||||
// pub unsafe fn take_isr_return_pair() -> Option<(PID, TID)> {
|
||||
// PREVIOUS_PAIR.take()
|
||||
// }
|
||||
|
||||
/// Trap entry point rust (_start_trap_rust)
|
||||
///
|
||||
|
|
|
|||
|
|
@ -136,6 +136,16 @@ pub extern "C" fn kmain() {
|
|||
// Start performing round-robin on all child processes.
|
||||
// Note that at this point, no new direct children of INIT may be created.
|
||||
let mut pid = None;
|
||||
|
||||
#[cfg(not(target_os = "none"))]
|
||||
{
|
||||
use std::panic;
|
||||
panic::set_hook(Box::new(|arg| {
|
||||
println!("Panic Details: {:?}", arg);
|
||||
debug_here::debug_here!();
|
||||
}));
|
||||
}
|
||||
|
||||
loop {
|
||||
arch::irq::disable_all_irqs();
|
||||
pid = next_pid_to_run(pid);
|
||||
|
|
|
|||
|
|
@ -331,6 +331,7 @@ impl MemoryManager {
|
|||
return Ok(potential_start as *mut u8);
|
||||
}
|
||||
}
|
||||
// println!("Couldn't find virtual address");
|
||||
Err(xous_kernel::Error::BadAddress)
|
||||
})
|
||||
}
|
||||
|
|
@ -622,10 +623,10 @@ impl MemoryManager {
|
|||
offset += region.mem_size as usize / PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"mem: unable to claim or release physical address {:08x}",
|
||||
addr
|
||||
);
|
||||
// println!(
|
||||
// "mem: unable to claim or release physical address {:08x}",
|
||||
// addr
|
||||
// );
|
||||
Err(xous_kernel::Error::BadAddress)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ use core::mem;
|
|||
use xous_kernel::{MemoryAddress, MemoryRange, MemorySize, Message, PID, SID, TID};
|
||||
|
||||
pub struct SenderID {
|
||||
/// The connection ID inside the server
|
||||
pub cid: usize,
|
||||
/// The index of the server within the SystemServices table
|
||||
pub sidx: usize,
|
||||
/// The index into the queue array
|
||||
pub idx: usize,
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ pub struct SenderID {
|
|||
impl From<usize> for SenderID {
|
||||
fn from(item: usize) -> SenderID {
|
||||
SenderID {
|
||||
cid: item >> 16,
|
||||
sidx: item >> 16,
|
||||
idx: item & 0xffff,
|
||||
}
|
||||
}
|
||||
|
|
@ -20,10 +20,11 @@ impl From<usize> for SenderID {
|
|||
|
||||
impl Into<usize> for SenderID {
|
||||
fn into(self) -> usize {
|
||||
(self.cid << 16) | (self.idx & 0xffff)
|
||||
(self.sidx << 16) | (self.idx & 0xffff)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum WaitingMessage {
|
||||
/// There is no waiting message.
|
||||
None,
|
||||
|
|
@ -333,6 +334,7 @@ impl Server {
|
|||
buf: Option<&MemoryRange>,
|
||||
) -> Result<WaitingMessage, xous_kernel::Error> {
|
||||
if idx > self.queue.len() {
|
||||
// println!("KERNEL: index exceeds queue length");
|
||||
return Err(xous_kernel::Error::BadAddress);
|
||||
}
|
||||
let (pid, ctx, server_addr, client_addr, len, forget, is_memory) = match self.queue[idx] {
|
||||
|
|
@ -350,9 +352,10 @@ impl Server {
|
|||
|
||||
// Sanity check the specified address was correct, and matches what we
|
||||
// had cached.
|
||||
if is_memory {
|
||||
if is_memory && cfg!(baremetal) {
|
||||
let buf = buf.expect("memory message expected but no buffer passed!");
|
||||
if server_addr != buf.as_ptr() as usize || len != buf.len() {
|
||||
// println!("KERNEL: Memory is attached but the returned buffer doesn't match (len: {} vs {}), buf addr: {:08x} vs {:08x}", len, buf.len(), server_addr, buf.as_ptr() as usize);
|
||||
return Err(xous_kernel::Error::BadAddress);
|
||||
}
|
||||
}
|
||||
|
|
@ -407,14 +410,14 @@ impl Server {
|
|||
///
|
||||
/// * **None**: There are no waiting messages
|
||||
/// ***Some(MessageEnvelope): This message is queued.
|
||||
pub fn take_next_message(&mut self, cid: xous_kernel::CID) -> Option<xous_kernel::MessageEnvelope> {
|
||||
pub fn take_next_message(&mut self, sidx: usize) -> Option<xous_kernel::MessageEnvelope> {
|
||||
// println!(
|
||||
// "queue_head: ((({}))) queue_tail: ((({}))): {:?} CID: ((({})))",
|
||||
// self.queue_head, self.queue_tail, self.queue[self.queue_tail], cid
|
||||
// );
|
||||
let sender = SenderID {
|
||||
idx: self.queue_tail,
|
||||
cid,
|
||||
sidx,
|
||||
}.into();
|
||||
let (result, response) = match self.queue[self.queue_tail] {
|
||||
QueuedMessage::Empty => return None,
|
||||
|
|
|
|||
|
|
@ -596,6 +596,7 @@ impl SystemServices {
|
|||
let mut p = crate::arch::process::Process::current();
|
||||
p.setup_thread(INITIAL_TID, setup)?;
|
||||
p.set_thread(INITIAL_TID)?;
|
||||
ArchProcess::with_inner_mut(|process_inner| process_inner.pid = pid);
|
||||
// process.current_thread = INITIAL_TID as u8;
|
||||
|
||||
// Mark the current proces state as "running, and no waiting contexts"
|
||||
|
|
@ -857,10 +858,14 @@ impl SystemServices {
|
|||
// println!("Setting up new process...");
|
||||
ArchProcess::setup_process(new_pid, thread_init)
|
||||
.expect("couldn't set up new process");
|
||||
ArchProcess::with_inner_mut(|process_inner| process_inner.pid = new_pid);
|
||||
|
||||
ProcessState::Running(0)
|
||||
}
|
||||
ProcessState::Allocated => ProcessState::Running(0),
|
||||
ProcessState::Allocated => {
|
||||
ArchProcess::with_inner_mut(|process_inner| process_inner.pid = new_pid);
|
||||
ProcessState::Running(0)
|
||||
},
|
||||
ProcessState::Free => panic!("process was suddenly Free"),
|
||||
ProcessState::Ready(x) | ProcessState::Running(x) => {
|
||||
ProcessState::Running(x & !(1 << new_tid))
|
||||
|
|
@ -1267,7 +1272,10 @@ impl SystemServices {
|
|||
ProcessState::Running(x) => ProcessState::Running(x | (1 << new_tid)),
|
||||
|
||||
// This is the initial thread in this process -- schedule it to be run.
|
||||
ProcessState::Allocated => ProcessState::Ready(1 << new_tid),
|
||||
ProcessState::Allocated => {
|
||||
ArchProcess::with_inner_mut(|process_inner| process_inner.pid = pid);
|
||||
ProcessState::Ready(1 << new_tid)
|
||||
},
|
||||
|
||||
other => panic!(
|
||||
"error spawning thread: process was in an invalid state {:?}",
|
||||
|
|
@ -1340,9 +1348,10 @@ impl SystemServices {
|
|||
// While doing this, find a free slot in case we haven't
|
||||
// yet connected.
|
||||
|
||||
// let _pid = crate::arch::process::current_pid();
|
||||
let pid = crate::arch::process::current_pid();
|
||||
// println!("KERNEL({}): Server table: {:?}", _pid.get(), self.servers);
|
||||
ArchProcess::with_inner_mut(|process_inner| {
|
||||
assert_eq!(pid, process_inner.pid);
|
||||
let mut slot_idx = None;
|
||||
// Look through the connection map for (1) a free slot, and (2) an
|
||||
// existing connection
|
||||
|
|
@ -1378,9 +1387,10 @@ impl SystemServices {
|
|||
process_inner.connection_map[slot_idx] =
|
||||
Some(NonZeroU8::new((server_idx as u8) + 2).unwrap());
|
||||
// println!(
|
||||
// "KERNEL({}): New connection to {:?}. After connection, process connection map is: {:?}",
|
||||
// _pid.get(),
|
||||
// "KERNEL({}): New connection to {:?}. After connection, cid is {} and process connection map is: {:?}",
|
||||
// pid.get(),
|
||||
// sid,
|
||||
// slot_idx + 2,
|
||||
// process_inner.connection_map
|
||||
// );
|
||||
return Ok((slot_idx as CID) + 2);
|
||||
|
|
@ -1391,6 +1401,21 @@ impl SystemServices {
|
|||
})
|
||||
}
|
||||
|
||||
/// Retrieve the server ID index from the specified SID.
|
||||
/// This may only be called if the SID is a server owned by
|
||||
/// the current process.
|
||||
pub fn sidx_from_sid(&mut self, sid: SID, pid: PID) -> Option<usize> {
|
||||
// println!("KERNEL({}): Server table: {:?}", pid.get(), self.servers);
|
||||
for (idx, slot) in self.servers.iter().enumerate() {
|
||||
if let Some(server) = slot {
|
||||
if server.pid == pid && server.sid == sid {
|
||||
return Some(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Return a server based on the connection id and the current process
|
||||
pub fn server_from_sidx(&self, sidx: usize) -> Option<&Server> {
|
||||
if sidx > self.servers.len() {
|
||||
|
|
@ -1409,32 +1434,41 @@ impl SystemServices {
|
|||
}
|
||||
}
|
||||
|
||||
/// Retrieve a Server ID (Extended) value from the given Connection ID
|
||||
/// within the current process.
|
||||
pub fn sidx_from_cid(&self, cid: CID) -> Option<usize> {
|
||||
// println!("KERNEL({}): Attempting to get SIDX from CID {}", crate::arch::process::current_pid(), cid);
|
||||
if cid == 0 {
|
||||
println!("CID is invalid -- returning");
|
||||
// println!("KERNEL({}): CID is invalid -- returning", crate::arch::process::current_pid());
|
||||
return None;
|
||||
} else if cid == 1 {
|
||||
println!("Server has terminated -- returning");
|
||||
// println!("KERNEL({}): Server has terminated -- returning", crate::arch::process::current_pid());
|
||||
return None;
|
||||
}
|
||||
|
||||
let cid = cid - 2;
|
||||
|
||||
ArchProcess::with_inner(|process_inner| {
|
||||
assert_eq!(crate::arch::process::current_pid(), process_inner.pid);
|
||||
if cid >= process_inner.connection_map.len() {
|
||||
println!("KERNEL: CID {} > connection map len", cid);
|
||||
// println!("KERNEL({}): CID {} > connection map len", crate::arch::process::current_pid(), cid);
|
||||
return None;
|
||||
}
|
||||
// if process_inner.connection_map[cid].is_none() {
|
||||
// println!("KERNEL({}): CID {} doesn't exist in the connection map", crate::arch::process::current_pid(), cid + 2);
|
||||
// println!("KERNEL({}): Process inner is: {:?}", crate::arch::process::current_pid(), process_inner);
|
||||
// }
|
||||
let mut server_idx = process_inner.connection_map[cid]?.get() as usize;
|
||||
if server_idx < 2 {
|
||||
panic!("KERNEL: CID {} is invalid", cid + 2);
|
||||
if server_idx == 1 {
|
||||
// println!("KERNEL({}): CID {} is no longer valid", crate::arch::process::current_pid(), cid + 2);
|
||||
return None;
|
||||
}
|
||||
server_idx -= 2;
|
||||
if server_idx >= self.servers.len() {
|
||||
println!("KERNEL: CID {} and server_idx >= {}", cid + 2, server_idx);
|
||||
// println!("KERNEL({}): CID {} and server_idx >= {}", crate::arch::process::current_pid(), cid + 2, server_idx);
|
||||
None
|
||||
} else {
|
||||
// println!("KERNEL: SIDX for CID {} found at index {}", cid + 2, server_idx);
|
||||
// println!("KERNEL({}): SIDX for CID {} found at index {}", crate::arch::process::current_pid(), cid + 2, server_idx);
|
||||
Some(server_idx)
|
||||
}
|
||||
})
|
||||
|
|
@ -1472,27 +1506,27 @@ impl SystemServices {
|
|||
result
|
||||
}
|
||||
|
||||
/// Obtain the connection ID of the server from within the server process.
|
||||
pub fn server_cid(&mut self, sidx: usize) -> Result<CID, xous_kernel::Error> {
|
||||
let current_pid = self.current_pid();
|
||||
let result = {
|
||||
let server = self
|
||||
.server_from_sidx(sidx)
|
||||
.ok_or(xous_kernel::Error::ServerNotFound)?;
|
||||
let server_pid = server.pid;
|
||||
let sid = server.sid;
|
||||
{
|
||||
let server_process = self.get_process(server_pid)?;
|
||||
server_process.mapping.activate().unwrap();
|
||||
}
|
||||
self.connect_to_server(sid)
|
||||
};
|
||||
let current_process = self
|
||||
.get_process(current_pid)
|
||||
.expect("couldn't restore previous process");
|
||||
current_process.mapping.activate()?;
|
||||
result
|
||||
}
|
||||
// /// Obtain the connection ID of the server from within the server process.
|
||||
// pub fn server_cid(&mut self, sidx: usize) -> Result<CID, xous_kernel::Error> {
|
||||
// let current_pid = self.current_pid();
|
||||
// let result = {
|
||||
// let server = self
|
||||
// .server_from_sidx(sidx)
|
||||
// .ok_or(xous_kernel::Error::ServerNotFound)?;
|
||||
// let server_pid = server.pid;
|
||||
// let sid = server.sid;
|
||||
// {
|
||||
// let server_process = self.get_process(server_pid)?;
|
||||
// server_process.mapping.activate().unwrap();
|
||||
// }
|
||||
// self.connect_to_server(sid)
|
||||
// };
|
||||
// let current_process = self
|
||||
// .get_process(current_pid)
|
||||
// .expect("couldn't restore previous process");
|
||||
// current_process.mapping.activate()?;
|
||||
// result
|
||||
// }
|
||||
|
||||
/// Switch to the server's address space and add a "remember this address"
|
||||
/// entry to its server queue, then switch back to the original address space.
|
||||
|
|
@ -1521,17 +1555,17 @@ impl SystemServices {
|
|||
result
|
||||
}
|
||||
|
||||
/// Get a server index based on a SID
|
||||
pub fn server_sidx(&mut self, sid: SID) -> Option<usize> {
|
||||
for (idx, server) in self.servers.iter_mut().enumerate() {
|
||||
if let Some(active_server) = server {
|
||||
if active_server.sid == sid {
|
||||
return Some(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
// /// Get a server index based on a SID
|
||||
// pub fn server_sidx(&mut self, sid: SID) -> Option<usize> {
|
||||
// for (idx, server) in self.servers.iter_mut().enumerate() {
|
||||
// if let Some(active_server) = server {
|
||||
// if active_server.sid == sid {
|
||||
// return Some(idx);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// None
|
||||
// }
|
||||
|
||||
/// Terminate the given process. Returns the process' parent PID.
|
||||
pub fn terminate_process(&mut self, target_pid: PID) -> Result<PID, xous_kernel::Error> {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,6 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
|
|||
// "There are contexts available to handle this message. Marking PID {} as Ready",
|
||||
// server_pid
|
||||
// );
|
||||
let server_cid = ss.server_cid(sidx)?;
|
||||
let sender_idx = if message.is_blocking() {
|
||||
ss.remember_server_message(sidx, pid, thread, &message, client_address)
|
||||
.map_err(|e| {
|
||||
|
|
@ -143,9 +142,13 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
|
|||
0
|
||||
};
|
||||
let sender = SenderID {
|
||||
cid: server_cid,
|
||||
sidx,
|
||||
idx: sender_idx,
|
||||
};
|
||||
// println!(
|
||||
// "KERNEL({}): server connection data: sidx: {}, idx: {}, server pid: {}",
|
||||
// pid, sidx, sender_idx, server_pid
|
||||
// );
|
||||
let envelope = MessageEnvelope {
|
||||
sender: sender.into(),
|
||||
body: message,
|
||||
|
|
@ -227,11 +230,8 @@ fn return_memory(pid: PID, tid: TID, sender: MessageSender, buf: MemoryRange) ->
|
|||
SystemServices::with_mut(|ss| {
|
||||
let sender = SenderID::from(sender);
|
||||
|
||||
let sidx = ss
|
||||
.sidx_from_cid(sender.cid)
|
||||
.ok_or(xous_kernel::Error::ServerNotFound)?;
|
||||
let server = ss
|
||||
.server_from_sidx_mut(sidx)
|
||||
.server_from_sidx_mut(sender.sidx)
|
||||
.ok_or(xous_kernel::Error::ServerNotFound)?;
|
||||
if server.pid != pid {
|
||||
return Err(xous_kernel::Error::ServerNotFound);
|
||||
|
|
@ -276,13 +276,14 @@ fn return_memory(pid: PID, tid: TID, sender: MessageSender, buf: MemoryRange) ->
|
|||
}
|
||||
};
|
||||
// println!(
|
||||
// "Returning {} bytes from {:08x} in PID {} to {:08x} in PID {} in context {}",
|
||||
// "KERNEL({}): Returning {} bytes from {:08x} in PID {} to {:08x} in PID {} in context {}",
|
||||
// pid,
|
||||
// len,
|
||||
// server_addr.get(),
|
||||
// pid,
|
||||
// client_addr.get(),
|
||||
// client_pid,
|
||||
// client_ctx
|
||||
// client_tid
|
||||
// );
|
||||
|
||||
// Return the memory to the calling process
|
||||
|
|
@ -296,10 +297,6 @@ fn return_memory(pid: PID, tid: TID, sender: MessageSender, buf: MemoryRange) ->
|
|||
)?;
|
||||
|
||||
// Unblock the client context to allow it to continue.
|
||||
// println!(
|
||||
// "KERNEL({}): Unblocking PID {} CTX {}",
|
||||
// pid, client_pid, client_ctx
|
||||
// );
|
||||
if !cfg!(baremetal) {
|
||||
ss.ready_thread(client_pid, client_tid)?;
|
||||
ss.switch_to_thread(client_pid, Some(client_tid))?;
|
||||
|
|
@ -328,11 +325,8 @@ fn return_scalar(
|
|||
SystemServices::with_mut(|ss| {
|
||||
let sender = SenderID::from(sender);
|
||||
|
||||
let sidx = ss
|
||||
.sidx_from_cid(sender.cid)
|
||||
.ok_or(xous_kernel::Error::ServerNotFound)?;
|
||||
let server = ss
|
||||
.server_from_sidx_mut(sidx)
|
||||
.server_from_sidx_mut(sender.sidx)
|
||||
.ok_or(xous_kernel::Error::ServerNotFound)?;
|
||||
if server.pid != server_pid {
|
||||
return Err(xous_kernel::Error::ServerNotFound);
|
||||
|
|
@ -397,12 +391,10 @@ fn return_scalar2(
|
|||
SystemServices::with_mut(|ss| {
|
||||
let sender = SenderID::from(sender);
|
||||
|
||||
let sidx = ss
|
||||
.sidx_from_cid(sender.cid)
|
||||
.ok_or(xous_kernel::Error::ServerNotFound)?;
|
||||
let server = ss
|
||||
.server_from_sidx_mut(sidx)
|
||||
.server_from_sidx_mut(sender.sidx)
|
||||
.ok_or(xous_kernel::Error::ServerNotFound)?;
|
||||
// .expect("Couldn't get server from SIDX");
|
||||
if server.pid != server_pid {
|
||||
return Err(xous_kernel::Error::ServerNotFound);
|
||||
}
|
||||
|
|
@ -465,9 +457,8 @@ fn receive_message(pid: PID, tid: TID, sid: SID) -> SysCallResult {
|
|||
"current thread is not running"
|
||||
);
|
||||
// See if there is a pending message. If so, return immediately.
|
||||
let cid = ss.connect_to_server(sid)?;
|
||||
let sidx = ss
|
||||
.server_sidx(sid)
|
||||
.sidx_from_sid(sid, pid)
|
||||
.ok_or(xous_kernel::Error::ServerNotFound)?;
|
||||
let server = ss
|
||||
.server_from_sidx_mut(sidx)
|
||||
|
|
@ -480,7 +471,7 @@ fn receive_message(pid: PID, tid: TID, sid: SID) -> SysCallResult {
|
|||
}
|
||||
|
||||
// If there is a pending message, return it immediately.
|
||||
if let Some(msg) = server.take_next_message(cid) {
|
||||
if let Some(msg) = server.take_next_message(sidx) {
|
||||
return Ok(xous_kernel::Result::Message(msg));
|
||||
}
|
||||
|
||||
|
|
@ -545,6 +536,7 @@ pub fn handle_inner(pid: PID, tid: TID, call: SysCall) -> SysCallResult {
|
|||
.map(|x| x.get() >= arch::mem::USER_AREA_END)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
println!("Exceeded user area");
|
||||
return Err(xous_kernel::Error::BadAddress);
|
||||
|
||||
// Don't allow mapping non-page values
|
||||
|
|
|
|||
Loading…
Reference in a new issue