Skip to content

Commit

Permalink
libuser: Push a C Buffer in the server impl.
Browse files Browse the repository at this point in the history
For now, the C Buffer size is hardcoded to 0x300. In the future, that
should probably be a const generic.
  • Loading branch information
roblabla committed Mar 16, 2019
1 parent 277b35c commit 1c9da0e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions libuser/src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use spin::Mutex;
use core::ops::{Deref, DerefMut, Index};
use core::fmt::{self, Debug};
use crate::error::Error;
use crate::ipc::Message;

/// A handle to a waitable object.
pub trait IWaitable: Debug {
Expand Down Expand Up @@ -152,7 +153,9 @@ pub struct SessionWrapper<T: Object> {

/// Command buffer for this session.
/// Ensure 16 bytes of alignment so the raw data is properly aligned.
buf: Align16<[u8; 0x100]>
buf: Align16<[u8; 0x100]>,

type_c_buf: [u8; 0x300]
}

impl<T: Object + Debug> Debug for SessionWrapper<T> {
Expand All @@ -161,6 +164,7 @@ impl<T: Object + Debug> Debug for SessionWrapper<T> {
.field("handle", &self.handle)
.field("object", &self.object)
.field("buf", &&self.buf[..])
.field("type_c_buf", &&self.type_c_buf[..])
.finish()
}
}
Expand All @@ -173,6 +177,7 @@ impl<T: Object> SessionWrapper<T> {
handle,
object,
buf: Align16([0; 0x100]),
type_c_buf: [0; 0x300],
}
}
}
Expand All @@ -183,6 +188,11 @@ impl<T: Object + Debug> IWaitable for SessionWrapper<T> {
}

fn handle_signaled(&mut self, manager: &WaitableManager) -> Result<bool, Error> {
// Push a C Buffer before receiving.
let mut req = Message::<(), [_; 1], [_; 0], [_; 0]>::new_request(None, 0);
req.push_in_pointer(&mut self.type_c_buf, false);
req.pack(&mut self.buf[..]);

self.handle.receive(&mut self.buf[..], Some(0))?;

match super::find_ty_cmdid(&self.buf[..]) {
Expand Down Expand Up @@ -226,7 +236,8 @@ impl<T: Object + Default + Debug + 'static> IWaitable for PortHandler<T> {
let session = Box::new(SessionWrapper {
object: T::default(),
handle: self.handle.accept()?,
buf: Align16([0; 0x100])
buf: Align16([0; 0x100]),
type_c_buf: [0; 0x300]
});
manager.add_waitable(session);
Ok(false)
Expand Down

0 comments on commit 1c9da0e

Please sign in to comment.