Revert "kernel: hosted: don't send responses twice"

This causes problems, and fixes an issue that doesn't actually exist.
Revert it.

This reverts commit fc9f597092.
This commit is contained in:
Sean Cross 2020-11-11 16:18:39 +08:00
parent d9272ba21a
commit b8d9d1e1b3
2 changed files with 24 additions and 36 deletions

View file

@ -550,7 +550,6 @@ pub fn idle() -> bool {
}
// Handle the syscall within the Xous kernel
crate::arch::process::clear_response_sent_already();
let response =
crate::syscall::handle(pid, thread_id, false, call).unwrap_or_else(Result::Error);
@ -575,18 +574,17 @@ pub fn idle() -> bool {
let s = unsafe { core::slice::from_raw_parts(mem.as_ptr(), mem.len()) };
response_vec.extend_from_slice(s);
}
// Send a response only if we haven't already sent one
if ! crate::arch::process::response_sent_already() {
process.send(&response_vec).unwrap_or_else(|_e| {
// If we're unable to send data to the process, assume it's dead and terminate it.
eprintln!(
"KERNEL({}): Unable to send response to process: {:?} -- terminating",
pid, _e
);
crate::syscall::handle(pid, thread_id, false, SysCall::TerminateProcess).ok();
});
}
process.send(&response_vec).unwrap_or_else(|_e| {
// If we're unable to send data to the process, assume it's dead and terminate it.
eprintln!(
"KERNEL({}): Unable to send response to process: {:?} -- terminating",
pid, _e
);
crate::syscall::handle(pid, thread_id, false, SysCall::TerminateProcess).ok();
});
crate::arch::process::set_current_pid(existing_pid);
// SystemServices::with_mut(|ss| {
// ss.switch_from(pid, 1, true)}).unwrap();
}
if is_shutdown {

View file

@ -27,9 +27,6 @@ struct ProcessImpl {
/// Memory that may need to be returned to the caller for each thread
memory_to_return: [Option<Vec<u8>>; MAX_THREAD + 1],
/// We've already sent a response, so don't send another one
response_sent: bool,
/// This enables the kernel to keep track of threads in the
/// target process, and know which threads are ready to
/// receive messages.
@ -61,27 +58,9 @@ thread_local!(
current: unsafe { PID::new_unchecked(1) },
total: 0,
table: Vec::new(),
});
})
);
pub fn response_sent_already() -> bool {
PROCESS_TABLE.with(|pt| {
let mut process_table = pt.borrow_mut();
let current_pid_idx = process_table.current.get() as usize - 1;
let process = &mut process_table.table[current_pid_idx].as_mut().unwrap();
process.response_sent
})
}
pub fn clear_response_sent_already() {
PROCESS_TABLE.with(|pt| {
let mut process_table = pt.borrow_mut();
let current_pid_idx = process_table.current.get() as usize - 1;
let process = &mut process_table.table[current_pid_idx].as_mut().unwrap();
process.response_sent = false;
})
}
pub fn current_pid() -> PID {
PROCESS_TABLE.with(|pt| pt.borrow().current)
}
@ -320,10 +299,22 @@ impl Process {
if result.memory().is_some() {
panic!("Result has memory and we're also returning memory!");
}
// if let xous_kernel::Result::Message(_) = result {
// } else {
// panic!(
// "memory was waiting to be returned, but message was not a result message"
// );
// }
print!(" [adding {} additional bytes from memory being returned]", buf.len());
response.extend_from_slice(&buf);
}
process.response_sent = true;
// eprintln!(
// "KERNEL({}): Setting thread return value to {:?}",
// current_pid_idx + 1,
// response
// );
print!(" [setting thread return value to {} bytes]", response.len());
process
.conn
.as_mut()
@ -356,7 +347,6 @@ impl Process {
conn: None,
key: init_data.key,
memory_to_return: filled_array![None; 32 /* MAX_THREAD */],
response_sent: false,
current_thread: INITIAL_TID,
threads: [Thread { allocated: false }; MAX_THREAD + 1],
};