Make send_ipc syscall use send_ipc_to function
This commit is contained in:
parent
e4782341b0
commit
f0c6432740
@ -501,84 +501,7 @@ extern "C" fn syscall_handler() {
|
||||
let len = usize(regs.rsi);
|
||||
assert!(len <= buffer.len());
|
||||
if TASKING.message_queue_mut(pid, |_| ()).is_ok() {
|
||||
#[cfg(feature = "log-rpc")]
|
||||
{
|
||||
#[expect(
|
||||
clippy::unwrap_used,
|
||||
reason = "The min call guarantees that the value is in the range of a u32 before the cast"
|
||||
)]
|
||||
let trunc_len: u32 = usize::min(len, 4096).try_into().unwrap();
|
||||
#[expect(
|
||||
clippy::arithmetic_side_effects,
|
||||
reason = "Can't underflow, as x % 4 < 4 no matter the x"
|
||||
)]
|
||||
let padding = if (trunc_len % 4) != 0 { 4 - (trunc_len % 4) } else { 0 };
|
||||
#[expect(
|
||||
clippy::arithmetic_side_effects,
|
||||
reason = "Can't overflow, as padding is no more than 4 and trunc_len is no more than 4096."
|
||||
)]
|
||||
let padded_len = trunc_len + padding;
|
||||
#[expect(
|
||||
clippy::arithmetic_side_effects,
|
||||
reason = "Can't overflow, as padded_len is no more than 4096 and 4096+24 < u32::MAX"
|
||||
)]
|
||||
let total_len = padded_len + 8 + (4 * 4);
|
||||
SECOND_PORT.write_u32s(&[
|
||||
0x3, // SPB type
|
||||
total_len, // Total block length
|
||||
len.saturating_cast::<u32>().saturating_add(8), // Packet length
|
||||
]);
|
||||
SECOND_PORT.write_bytes(&pid.to_ne_bytes());
|
||||
#[expect(
|
||||
clippy::indexing_slicing,
|
||||
reason = "The truncated length is always <= the buffer's length"
|
||||
)]
|
||||
SECOND_PORT.write_bytes(&buffer[0..usize(trunc_len)]);
|
||||
for _ in 0..padding {
|
||||
SECOND_PORT.write_bytes(&[0]);
|
||||
}
|
||||
SECOND_PORT.write_u32s(&[
|
||||
total_len, // Total block length
|
||||
]);
|
||||
}
|
||||
let buf_num_pages = buffer.len() / 4096;
|
||||
let buffer = Box::into_raw(buffer);
|
||||
let buf_start_page =
|
||||
Page::from_start_address(VirtAddr::new(u64(buffer.expose_provenance())))
|
||||
.unwrap();
|
||||
let dest_buffer = TASKING
|
||||
.address_space_mut(pid, |aspace| {
|
||||
// This is None only if the destiniation is the current process. If so,
|
||||
// no remapping is necessary so just retyurn the old buffer.
|
||||
let Some(aspace) = aspace else {
|
||||
return buffer;
|
||||
};
|
||||
let page = ACTIVE_SPACE
|
||||
.lock()
|
||||
.move_mappings_free(buf_start_page, buf_num_pages, aspace)
|
||||
.unwrap();
|
||||
ptr::slice_from_raw_parts_mut::<u8>(
|
||||
page.start_address().as_mut_ptr(),
|
||||
buffer.len(),
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
#[expect(
|
||||
clippy::unwrap_used,
|
||||
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
||||
)]
|
||||
let new_buffer_key =
|
||||
TASKING.proc_data_buffers_mut(pid, |x| x.insert(dest_buffer)).unwrap();
|
||||
#[expect(
|
||||
clippy::unwrap_used,
|
||||
reason = "The option was already checked at the start of the if-let"
|
||||
)]
|
||||
TASKING.message_queue_mut(pid, |x| x.push((new_buffer_key, len))).unwrap();
|
||||
#[expect(
|
||||
clippy::unwrap_used,
|
||||
reason = "The PID is known valid due to using it in message_queue_mut in the if-let condition"
|
||||
)]
|
||||
TASKING.wake(pid, SleepReason::WaitingForIPC).unwrap();
|
||||
send_ipc_to(pid, buffer, len);
|
||||
retval = 0;
|
||||
} else {
|
||||
println!("ipc_send: Bad PID ({})", pid);
|
||||
|
Loading…
Reference in New Issue
Block a user