Move yunq client to use syscall helpers.

This commit is contained in:
Drew Galbraith 2024-07-28 20:54:52 -07:00
parent 5705f8d2ab
commit c2f9f5388b
3 changed files with 53 additions and 25 deletions

View File

@ -115,3 +115,43 @@ pub fn port_poll(
syscall(zion::kZionPortPoll, &req)?; syscall(zion::kZionPortPoll, &req)?;
Ok((num_bytes, num_caps)) Ok((num_bytes, num_caps))
} }
pub fn endpoint_send(
endpoint_cap: z_cap_t,
bytes: &[u8],
caps: &[z_cap_t],
) -> Result<z_cap_t, ZError> {
let mut reply_port_cap: u64 = 0;
let send_req = zion::ZEndpointSendReq {
caps: caps.as_ptr(),
num_caps: caps.len() as u64,
endpoint_cap,
data: bytes.as_ptr() as *const c_void,
num_bytes: bytes.len() as u64,
reply_port_cap: &mut reply_port_cap as *mut z_cap_t,
};
syscall(zion::kZionEndpointSend, &send_req)?;
Ok(reply_port_cap)
}
pub fn reply_port_recv(
reply_port_cap: z_cap_t,
bytes: &mut [u8],
caps: &mut [z_cap_t],
) -> Result<(u64, u64), ZError> {
let mut num_bytes = bytes.len() as u64;
let mut num_caps = caps.len() as u64;
let recv_req = zion::ZReplyPortRecvReq {
reply_port_cap,
caps: caps.as_mut_ptr(),
num_caps: &mut num_caps as *mut u64,
data: bytes.as_mut_ptr() as *mut c_void,
num_bytes: &mut num_bytes as *mut u64,
};
syscall(zion::kZionReplyPortRecv, &recv_req)?;
Ok((num_bytes, num_caps))
}

View File

@ -15,12 +15,12 @@ impl<const N: usize> ByteBuffer<N> {
N as u64 N as u64
} }
pub fn raw_ptr(&self) -> *const u8 { pub fn slice(&self, len: usize) -> &[u8] {
self.buffer.as_ptr() &self.buffer[..len]
} }
pub fn mut_ptr(&mut self) -> *mut u8 { pub fn mut_slice(&mut self) -> &mut [u8] {
self.buffer.as_mut_ptr() &mut self.buffer[..]
} }
pub fn write_at<T>(&mut self, offset: usize, obj: T) -> Result<(), ZError> { pub fn write_at<T>(&mut self, offset: usize, obj: T) -> Result<(), ZError> {

View File

@ -1,7 +1,6 @@
use crate::buffer::ByteBuffer; use crate::buffer::ByteBuffer;
use crate::message::YunqMessage; use crate::message::YunqMessage;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::ffi::c_void;
use mammoth::zion::z_cap_t; use mammoth::zion::z_cap_t;
use mammoth::zion::ZError; use mammoth::zion::ZError;
@ -21,31 +20,20 @@ pub fn call_endpoint<Req: YunqMessage, Resp: YunqMessage, const N: usize>(
byte_buffer.write_at(4, (16 + length) as u32)?; byte_buffer.write_at(4, (16 + length) as u32)?;
let mut reply_port_cap: u64 = 0; let reply_port_cap = mammoth::syscall::endpoint_send(
let send_req = mammoth::zion::ZEndpointSendReq {
caps: cap_buffer.as_ptr(),
num_caps: cap_buffer.len() as u64,
endpoint_cap, endpoint_cap,
data: byte_buffer.raw_ptr() as *const c_void, byte_buffer.slice(16 + length),
num_bytes: 16 + length as u64, cap_buffer.as_slice(),
reply_port_cap: &mut reply_port_cap as *mut z_cap_t, )?;
};
mammoth::syscall::syscall(mammoth::zion::kZionEndpointSend, &send_req)?;
// FIXME: Add a way to zero out the byte buffer. // FIXME: Add a way to zero out the byte buffer.
let mut buffer_size = byte_buffer.size(); cap_buffer = vec![0; 10];
let mut num_caps: u64 = 10; mammoth::syscall::reply_port_recv(
cap_buffer = vec![0; num_caps as usize];
let recv_req = mammoth::zion::ZReplyPortRecvReq {
reply_port_cap, reply_port_cap,
caps: cap_buffer.as_mut_ptr(), byte_buffer.mut_slice(),
num_caps: &mut num_caps as *mut u64, cap_buffer.as_mut_slice(),
data: byte_buffer.mut_ptr() as *mut c_void, )?;
num_bytes: &mut buffer_size as *mut u64,
};
mammoth::syscall::syscall(mammoth::zion::kZionReplyPortRecv, &recv_req)?;
if byte_buffer.at::<u32>(0)? != SENTINEL { if byte_buffer.at::<u32>(0)? != SENTINEL {
return Err(ZError::INVALID_RESPONSE); return Err(ZError::INVALID_RESPONSE);