From c5e6391e22e718d6a91a9d7d648a704cea0e584b Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 18 Feb 2021 02:01:11 +0800 Subject: [PATCH] remove mention of Sendable and the ipc.rs module --- Cargo.lock | 3 + services/benchmark-target/Cargo.toml | 1 + services/benchmark-target/src/api.rs | 5 +- services/benchmark-target/src/lib.rs | 24 +- services/benchmark-target/src/main.rs | 26 ++- services/benchmark/Cargo.toml | 1 + services/benchmark/src/main.rs | 6 +- services/gam/Cargo.toml | 1 + services/gam/README.md | 2 +- services/gam/src/api.rs | 5 +- services/gam/src/lib.rs | 33 +-- services/gam/src/main.rs | 36 ++- services/graphics-server/src/api.rs | 2 +- services/graphics-server/src/api/text.rs | 55 ++--- services/keyboard/src/api.rs | 4 +- xous-rs/src/ipc.rs | 268 ----------------------- xous-rs/src/lib.rs | 1 - xous-rs/src/string.rs | 11 +- 18 files changed, 125 insertions(+), 359 deletions(-) delete mode 100644 xous-rs/src/ipc.rs diff --git a/Cargo.lock b/Cargo.lock index 62e0b4a08..b37ed9be2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,6 +70,7 @@ dependencies = [ "graphics-server", "log", "log-server", + "rkyv", "ticktimer-server", "utralib", "xous", @@ -82,6 +83,7 @@ version = "0.1.0" dependencies = [ "log", "log-server", + "rkyv", "utralib", "xous", "xous-names", @@ -390,6 +392,7 @@ dependencies = [ "keyboard", "log", "log-server", + "rkyv", "ticktimer-server", "trng", "utralib", diff --git a/services/benchmark-target/Cargo.toml b/services/benchmark-target/Cargo.toml index e1ce4e125..7b453c50f 100644 --- a/services/benchmark-target/Cargo.toml +++ b/services/benchmark-target/Cargo.toml @@ -7,6 +7,7 @@ description = "Benchmark target for Xous" [dependencies] xous = { path = "../../xous-rs" } +rkyv = { version = "0.3.1", default_features = false } xous-names = { path = "../xous-names" } log-server = { path = "../log-server" } log = "0.4" diff --git a/services/benchmark-target/src/api.rs b/services/benchmark-target/src/api.rs index 71c3ae4b3..aad33e79e 100644 --- a/services/benchmark-target/src/api.rs +++ b/services/benchmark-target/src/api.rs @@ -1,7 +1,6 @@ use xous::{Message, ScalarMessage}; -#[repr(C)] -#[derive(Debug)] +#[derive(Debug, rkyv::Archive, rkyv::Unarchive)] pub struct TestStruct { pub challenge: [u32; 8], } @@ -14,7 +13,7 @@ impl TestStruct { } #[allow(dead_code)] -#[derive(Debug)] +#[derive(Debug, rkyv::Archive, rkyv::Unarchive)] pub enum Opcode { TestScalar(u32), TestMemory(TestStruct), diff --git a/services/benchmark-target/src/lib.rs b/services/benchmark-target/src/lib.rs index ec7864361..8e6042762 100644 --- a/services/benchmark-target/src/lib.rs +++ b/services/benchmark-target/src/lib.rs @@ -4,7 +4,6 @@ pub mod api; use api::*; use xous::{CID, send_message}; -use xous::ipc::Sendable; pub fn test_scalar(cid: CID, testvar: u32) -> Result { let response = send_message(cid, api::Opcode::TestScalar(testvar).into())?; @@ -16,9 +15,22 @@ pub fn test_scalar(cid: CID, testvar: u32) -> Result { } pub fn test_memory(cid: CID, testvar: u32) -> Result { - let reg = TestStruct::new(); - let mut sendable_reg = Sendable::new(reg).expect("can't create test structure"); - sendable_reg.challenge[0] = testvar; - sendable_reg.lend_mut(cid, 0).expect("test failure"); - Ok(sendable_reg.challenge[0]) + use rkyv::Write; + let mut reg = TestStruct::new(); + reg.challenge[0] = testvar; + + let reg_opcode = api::Opcode::TestMemory(reg); + let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096)); + let pos = writer.archive(®_opcode).expect("couldn't archive test structure"); + let mut xous_buffer = writer.into_inner(); + + xous_buffer.lend_mut(cid, pos as u32).expect("test failure"); + + let archived = unsafe {rkyv::archived_value::(xous_buffer.as_ref(), pos) }; + match archived { + rkyv::Archived::::TestMemory(result) => { + Ok(result.challenge[0]) + }, + _ => panic!("mutable lend did not return a recognizable value") + } } diff --git a/services/benchmark-target/src/main.rs b/services/benchmark-target/src/main.rs index 5f27941b6..443e5276b 100644 --- a/services/benchmark-target/src/main.rs +++ b/services/benchmark-target/src/main.rs @@ -8,6 +8,11 @@ use core::convert::TryFrom; use log::{error, info}; +use rkyv::archived_value_mut; +use core::pin::Pin; +use core::convert::TryInto; +use rkyv::Unarchive; + #[xous::xous_main] fn xmain() -> ! { log_server::init_wait().unwrap(); @@ -27,9 +32,24 @@ fn xmain() -> ! { _ => error!("BENCHTARGET: opcode not yet implemented"), } } else if let xous::Message::MutableBorrow(m) = &envelope.body { - //let lookup: &mut Lookup = unsafe { &mut *(m.buf.as_mut_ptr() as *mut Lookup) }; - let lookup: &mut TestStruct = unsafe { &mut *(m.buf.as_mut_ptr() as *mut TestStruct) }; - lookup.challenge[0] = lookup.challenge[0] + 1; + let mut buf = unsafe { xous::XousBuffer::from_memory_message(m) }; + let value = unsafe { + archived_value_mut::(Pin::new(buf.as_mut()), m.id.try_into().unwrap()) + }; + match &*value { + rkyv::Archived::::TestMemory(reg) => { + use rkyv::Write; + + let mut ret = TestStruct::new(); + ret.challenge[0] = reg.challenge[0] + 1; + + let retop = Opcode::TestMemory(ret); + let mut writer = rkyv::ArchiveBuffer::new(buf); + let pos = writer.archive(&retop).expect("couldn't archive return value"); + unsafe{ rkyv::archived_value::(writer.into_inner().as_ref(), pos) }; + } + _ => panic!("Invalid response from server -- corruption occurred"), + }; } else { error!("BENCHTARGET: couldn't convert opcode"); } diff --git a/services/benchmark/Cargo.toml b/services/benchmark/Cargo.toml index 1af6f5a9a..9bcaba7de 100644 --- a/services/benchmark/Cargo.toml +++ b/services/benchmark/Cargo.toml @@ -7,6 +7,7 @@ description = "Benchmarks for Xous" [dependencies] xous = { path = "../../xous-rs" } +rkyv = { version = "0.3.1", default_features = false } graphics-server = { path = "../graphics-server" } ticktimer-server = { path = "../ticktimer-server" } xous-names = { path = "../xous-names" } diff --git a/services/benchmark/src/main.rs b/services/benchmark/src/main.rs index 25ae086ea..8258cd37b 100644 --- a/services/benchmark/src/main.rs +++ b/services/benchmark/src/main.rs @@ -106,7 +106,7 @@ fn shell_main() -> ! { let screensize = graphics_server::screen_size(graphics_conn).expect("Couldn't get screen size"); - let mut string_buffer = String::new(4096); + let mut string_buffer = String::<4096>::new(); graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small) .expect("unable to set glyph"); @@ -154,12 +154,12 @@ fn shell_main() -> ! { // actual benchmark // get a scalar message if false { - // measured at 1349 iterations per second in this loop (hardware); 55/s (hosted) + // measured at 1479.2 iterations per second in this loop (hardware); 55/s (hosted) count = benchmark_target::test_scalar(target_conn, count).expect("BENCHMARK: couldn't send test message"); check_count = check_count + 1; } else { // works on hosted mode, 35/s (hosted) - // does *not* work on hardware + // measured at 762.6 iterations per second (hardware) count = benchmark_target::test_memory(target_conn, count).expect("BENCHMARK: couldn't send test message"); check_count = check_count + 1; } diff --git a/services/gam/Cargo.toml b/services/gam/Cargo.toml index a0ec9c288..53453bd1a 100644 --- a/services/gam/Cargo.toml +++ b/services/gam/Cargo.toml @@ -8,6 +8,7 @@ description = "Graphical Abstraction Manager for Xous" [dependencies] bitflags = "1.2.1" xous = { path = "../../xous-rs" } +rkyv = { version = "0.3.1", default_features = false } graphics-server = { path = "../graphics-server" } ticktimer-server = { path = "../ticktimer-server" } xous-names = { path = "../xous-names" } diff --git a/services/gam/README.md b/services/gam/README.md index 7cabda10d..834a9f989 100644 --- a/services/gam/README.md +++ b/services/gam/README.md @@ -80,7 +80,7 @@ be able to have exquisite control over the "look and feel" of their applications calls can "simulate" certain properties (such as figuring out the dynamic width or height of a text box based on the size of the string within) to assist with laying out `TextViews`. Once the layout is finalized, the `TextView` objects -are then immutably lent to the GAM using a `xous::ipc::Sendable.lend()` wrapper; +are then immutably lent to the GAM using an `rkyv` lend wrapper; the calling thread then blocks until the GAM completes the rendering operation. One can think of a `TextView` as a text bubble, that can have rounded or square diff --git a/services/gam/src/api.rs b/services/gam/src/api.rs index b3547df2a..9656f34eb 100644 --- a/services/gam/src/api.rs +++ b/services/gam/src/api.rs @@ -3,7 +3,7 @@ use graphics_server::{Point, Rectangle, TextView, Gid}; use blitstr_ref as blitstr; use blitstr::{GlyphStyle, Cursor}; -#[derive(Debug)] +#[derive(Debug, rkyv::Archive)] pub enum Opcode { // clears a canvas with a given GID ClearCanvas(Gid), @@ -11,6 +11,9 @@ pub enum Opcode { // renders a TextView RenderTextView(TextView), + // result codes from operations on TextViews + TextViewResult(TextViewResult), + // returns a GID to the "content" Canvas; requires an authentication token RequestContentCanvas(Gid), diff --git a/services/gam/src/lib.rs b/services/gam/src/lib.rs index 0a40e5a47..b39afcd9a 100644 --- a/services/gam/src/lib.rs +++ b/services/gam/src/lib.rs @@ -10,27 +10,34 @@ use graphics_server::api::{TextOp, TextView}; use graphics_server::api::{Rectangle, Point, Gid, TextBounds}; use log::{error, info}; +use rkyv::Write; /// this "posts" a textview -- it's not a "draw" as the update is neither guaranteed nor instantaneous /// the GAM first has to check that the textview is allowed to be updated, and then it will decide when /// the actual screen update is allowed pub fn post_textview(gam_cid: xous::CID, tv: &mut TextView) -> Result<(), xous::Error> { - let mut tv_backup = TextView::new(Gid::new([0,0,0,0]), 0, - TextBounds::BoundingBox(Rectangle::new(Point::new(0, 0), Point::new(0, 0)))); - tv_backup.populate_from(&tv); - info!("tv_backup: {:?}", tv_backup); + // for testing only + tv.set_op(TextOp::Render); + tv.cursor.pt.x = 37; + tv.cursor.pt.y = 5; - let mut sendable_tv = Sendable::new(tv).expect("can't create sendable textview"); - sendable_tv.populate_from(&tv_backup); - info!("sendable_tv: {:?}", sendable_tv); + info!("tv before lend: {:?}", tv); + let mut rkyv_tv = api::Opcode::RenderTextView(tv); + let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096)); + let pos = writer.archive(&rkyv_tv).expect("couldn't archive textview"); + let mut xous_buffer = writer.into_inner(); - sendable_tv.set_op(TextOp::Render); - sendable_tv.cursor.pt.x = 37; - sendable_tv.cursor.pt.y = 5; + xous_buffer.lend_mut(gam_cid, pos as u32).expect("RenderTextView operation failure"); - info!("sendable_tv before lend: {:?}", sendable_tv); - sendable_tv.lend_mut(gam_cid, sendable_tv.get_op().into()).expect("draw_textview operation failure"); + let returned = unsafe { rkyv::archived_value::(xous_buffer.as_ref(), pos)}; + match returned { + rkyv::Archived::::TextViewResult(result) => { + tv.set_bounds_computed(result.bounds_computed); + tv.cursor = result.cursor; + }, + _ => panic!("post_textview got a return value from the server that isn't expected or handled") + } - sendable_tv.set_op(TextOp::Nop); + tv.set_op(TextOp::Nop); Ok(()) } \ No newline at end of file diff --git a/services/gam/src/main.rs b/services/gam/src/main.rs index 25b8a953f..478af44ee 100644 --- a/services/gam/src/main.rs +++ b/services/gam/src/main.rs @@ -189,19 +189,31 @@ fn xmain() -> ! { _ => todo!("GAM: opcode not yet implemented"), } } else if let xous::Message::MutableBorrow(m) = &envelope.body { - match TextOp::from(m.id) { - TextOp::Nop => (), - TextOp::Render => { - let mut tv: &mut TextView = unsafe { - &mut *(m.buf.as_mut_ptr() as *mut TextView) - }; - info!("GAM: render request for {:?}", tv); - tv_draw(gfx_conn, trng_conn, &mut canvases, &mut tv).expect("GAM: can't render TextView"); - }, - TextOp::ComputeBounds => { + let mut buf = unsafe { buffer::XousBuffer::from_memory_message(m) }; + let value = unsafe { + archived_value_mut::(Pin::new(buf.as_mut()), m.id.try_into().unwrap()) + }; + let new_value = match &*value { + rkyv::Archived::::RenderTextView(tv) => { + match tv.operation { + TextOp::Nop => (), + TextOp::Render => { + info!("GAM: render request for {:?}", tv); + tv_draw(gfx_conn, trng_conn, &mut canvases, &mut tv).expect("GAM: can't render TextView"); + }, + TextOp::ComputeBounds => { - }, - } + }, + }; + let tv_ret = TextViewResult { + bounds_computed: tv.get_boundscomputed(), + cursor: tv.cursor, + }; + rkyv::Archived::::TextViewResult(tv_ret) + } + _ => panic!("GAM: invalid mutable borrow message"), + }; + unsafe { *value.get_unchecked_mut() = new_value }; } } _ => xous::yield_slice(), diff --git a/services/graphics-server/src/api.rs b/services/graphics-server/src/api.rs index cbc768cfb..05c48c38c 100644 --- a/services/graphics-server/src/api.rs +++ b/services/graphics-server/src/api.rs @@ -31,7 +31,7 @@ use hash32::{Hash, Hasher}; //////////////// OS APIs -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive)] pub struct Gid { /// a 128-bit random identifier for graphical objects gid: [u32; 4], diff --git a/services/graphics-server/src/api/text.rs b/services/graphics-server/src/api/text.rs index 18a610120..a1fe954a2 100644 --- a/services/graphics-server/src/api/text.rs +++ b/services/graphics-server/src/api/text.rs @@ -4,14 +4,14 @@ use blitstr::{GlyphStyle, Cursor}; use log::info; -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, rkyv::Archive)] pub enum TextAlignment { Left, Center, Right, } -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, rkyv::Archive)] pub enum TextBounds { // fixed width and height in a rectangle BoundingBox(Rectangle), @@ -23,7 +23,7 @@ pub enum TextBounds { GrowableFromBl(Point, u16), } -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, rkyv::Archive)] // operations that may be requested of a TextView when sent to GAM pub enum TextOp { Nop, @@ -52,8 +52,13 @@ impl From for TextOp { // roughly 168 bytes to represent the rest of the struct, and we want to fill out the 4096 byte page with text const TEXTVIEW_LEN: usize = 3072; -#[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, rkyv::Archive)] +pub struct TextViewResult { + pub bounds_computed: Option, + pub cursor: Cursor, +} + +#[derive(Copy, Clone, rkyv::Archive)] pub struct TextView { // this is the operation as specified for the GAM. Note this is different from the "op" when sent to graphics-server // only the GAM should be sending TextViews to the graphics-server, and a different coding scheme is used for that link. @@ -71,7 +76,7 @@ pub struct TextView { bounds_computed: Option, // is Some(Rectangle) if bounds have been computed and text has not been modified pub style: GlyphStyle, - text: [u8; TEXTVIEW_LEN], + text: xous::String::<3072>, length: u32, pub alignment: TextAlignment, pub cursor: Cursor, @@ -99,7 +104,7 @@ impl TextView { bounds_hint, bounds_computed: None, style: GlyphStyle::Regular, - text: [0; TEXTVIEW_LEN], + text: xous::String::<3072>::new(), length: 0, alignment: TextAlignment::Left, cursor: Cursor::new(0,0,0), @@ -128,15 +133,15 @@ impl TextView { } Ok(()) } - - pub fn to_str(&self) -> &str { - core::str::from_utf8(unsafe { - core::slice::from_raw_parts(self.text.as_ptr(), self.length as usize) - }) - .unwrap() + pub(crate) fn set_computed_bounds(&mut self, r: Option) { + self.bounds_computed = r; } - pub fn clear_str(&mut self) { self.text = [0; TEXTVIEW_LEN] } + pub fn to_str(&self) -> &str { + self.text.as_str().unwrap() + } + + pub fn clear_str(&mut self) { self.text.clear() } pub fn populate_from(&mut self, t: &TextView) { self.operation = t.operation; @@ -187,26 +192,6 @@ impl core::fmt::Display for TextView { // allow `write!()` macro on a` &TextView` impl core::fmt::Write for TextView { fn write_str(&mut self, s: &str) -> core::result::Result<(), core::fmt::Error> { - self.bounds_computed = None; - - let b = s.bytes(); - - // Ensure the length is acceptable - if b.len() + self.length as usize > self.text.len() as usize { - Err(core::fmt::Error)?; - } - // append the write to the array - for c in s.bytes() { - if self.length < self.text.len() as u32 { - self.text[self.length as usize] = c; - self.length += 1; - } - } - // Attempt to convert the string to UTF-8 to validate it's correct UTF-8. - core::str::from_utf8(unsafe { - core::slice::from_raw_parts(self.text.as_ptr(), self.length as usize) - }) - .map_err(|_| core::fmt::Error)?; - Ok(()) + write!(self.text, "{}", s) } } diff --git a/services/keyboard/src/api.rs b/services/keyboard/src/api.rs index ea8e8c0fb..547e9c23f 100644 --- a/services/keyboard/src/api.rs +++ b/services/keyboard/src/api.rs @@ -21,8 +21,8 @@ pub struct ScanCode { #[derive(Debug, Default, Copy, Clone)] pub struct RowCol { - pub r: u8, - pub c: u8, + pub r: u32, + pub c: u32, } #[repr(packed)] pub struct KeyRawStates { diff --git a/xous-rs/src/ipc.rs b/xous-rs/src/ipc.rs deleted file mode 100644 index 581a5f31f..000000000 --- a/xous-rs/src/ipc.rs +++ /dev/null @@ -1,268 +0,0 @@ -use core::cmp::Ordering; -use core::fmt; -use core::hash::{Hash, Hasher}; -use core::marker::{PhantomData, Unpin}; -use core::ops::{Deref, DerefMut}; -use core::ptr::NonNull; - -#[derive(PartialEq, Debug)] -enum MemoryState { - /// This struct is available for lending and sending - Available, - - /// This memory has been mutably lent out and will be returned - MutablyLent, - - /// This memory was moved, and should be forgotten - Moved, -} - -// #[repr(C)] -pub struct UninitializedSendable { - contents: NonNull, -} - -pub struct Sendable { - contents: *mut T, - total_size: usize, - memory_state: MemoryState, - // NOTE: this marker has no consequences for variance, but is necessary - // for dropck to understand that we logically own a `T`. - // - // For details, see: - // https://github.com/rust-lang/rfcs/blob/master/text/0769-sound-generic-drop.md#phantom-data - _marker: PhantomData, -} - -impl UninitializedSendable { - fn type_size() -> usize { - let type_size = core::mem::size_of::(); - let remainder = type_size & 4095; - type_size + (4096 - remainder) - } - - pub fn new(val: T) -> Result, crate::Error> - where - T: Unpin, - { - let uninitialized = Self::uninit()?; - let type_size = core::mem::size_of::(); - unsafe { - let src_slice = core::slice::from_raw_parts(&val as *const _ as *const u8, type_size); - let dest_slice = core::slice::from_raw_parts_mut( - uninitialized.contents.as_ptr() as *mut u8, - type_size, - ); - for (src, dest) in src_slice.iter().zip(dest_slice) { - *dest = *src; - } - } - Ok(uninitialized) - } - - pub fn uninit() -> Result, crate::Error> { - let padded_size = Self::type_size(); - - // Ensure this object takes up exactly a multiple of a page. This - // ensures it can be sent to another process. - let new_mem = crate::map_memory( - None, - None, - padded_size, - crate::MemoryFlags::R | crate::MemoryFlags::W, - )?; - - let contents = unsafe { NonNull::new_unchecked(new_mem.as_mut_ptr() as *mut T) }; - Ok(UninitializedSendable { contents }) - } - - pub unsafe fn assume_init(self) -> Sendable { - Sendable { - contents: self.contents.as_ptr(), - total_size: Self::type_size(), - memory_state: MemoryState::Available, - _marker: PhantomData, - } - } -} - -impl Default for Sendable { - /// Creates a `Box`, with the `Default` value for T. - fn default() -> Sendable { - Sendable::new(Default::default()).unwrap() - } -} - -// impl Default for Sendable<[T]> { -// fn default() -> Sendable<[T]> { -// Sendable::<[T; 0]>::new([]) -// } -// } - -/// `Unique` pointers are `Send` if `T` is `Send` because the data they -/// reference is unaliased. Note that this aliasing invariant is -/// unenforced by the type system; the abstraction using the -/// `Unique` must enforce it. -unsafe impl Send for Sendable {} - -/// `Unique` pointers are `Sync` if `T` is `Sync` because the data they -/// reference is unaliased. Note that this aliasing invariant is -/// unenforced by the type system; the abstraction using the -/// `Unique` must enforce it. -unsafe impl Sync for Sendable {} - -impl Sendable { - pub fn new(val: T) -> Result, crate::Error> - where - T: Unpin, - { - Ok(unsafe { UninitializedSendable::new(val)?.assume_init() }) - } - - /// Perform an immutable lend of this Carton to the specified server. - /// This function will block until the server returns. - pub fn lend(&self, connection: crate::CID, id: u32) -> Result { - let buf = crate::MemoryRange::new(self.contents as usize, self.total_size)?; - let msg = crate::MemoryMessage { - id: id as usize, - buf, - offset: None, - valid: crate::MemorySize::new(core::mem::size_of::()), - }; - crate::send_message(connection, crate::Message::Borrow(msg)) - } - - /// Perform a mutable lend of this Carton to the server. - pub fn lend_mut( - &mut self, - connection: crate::CID, - id: u32, - ) -> Result { - let buf = crate::MemoryRange::new(self.contents as usize, self.total_size)?; - let msg = crate::MemoryMessage { - id: id as usize, - buf, - offset: None, - valid: crate::MemorySize::new(core::mem::size_of::()), - }; - self.memory_state = MemoryState::MutablyLent; - let result = crate::send_message(connection, crate::Message::MutableBorrow(msg)); - self.memory_state = MemoryState::Available; - result - } - - /// Perform a move of this Carton to the server. - pub fn send( - mut self, - connection: crate::CID, - id: u32, - ) -> Result { - let buf = crate::MemoryRange::new(self.contents as usize, self.total_size)?; - let msg = crate::MemoryMessage { - id: id as usize, - buf, - offset: None, - valid: crate::MemorySize::new(core::mem::size_of::()), - }; - let result = crate::send_message(connection, crate::Message::Move(msg))?; - - // Mark this state as Moved, which prevents it from being Dropped. - self.memory_state = MemoryState::Moved; - Ok(result) - } -} - -impl Deref for Sendable { - type Target = T; - - fn deref(&self) -> &T { - unsafe { &*self.contents } - } -} - -impl DerefMut for Sendable { - fn deref_mut(&mut self) -> &mut T { - unsafe { &mut *self.contents } - } -} - -// Display formatting -impl fmt::Display for Sendable { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(&**self, f) - } -} - -impl fmt::Debug for Sendable { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&**self, f) - } -} - -impl fmt::Pointer for Sendable { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // It's not possible to extract the inner Uniq directly from the Box, - // instead we cast it to a *const which aliases the Unique - let ptr: *const T = &**self; - fmt::Pointer::fmt(&ptr, f) - } -} - -impl PartialEq for Sendable { - #[inline] - fn eq(&self, other: &Sendable) -> bool { - PartialEq::eq(&**self, &**other) - } - #[inline] - fn ne(&self, other: &Sendable) -> bool { - PartialEq::ne(&**self, &**other) - } -} - -impl PartialOrd for Sendable { - #[inline] - fn partial_cmp(&self, other: &Sendable) -> Option { - PartialOrd::partial_cmp(&**self, &**other) - } - #[inline] - fn lt(&self, other: &Sendable) -> bool { - PartialOrd::lt(&**self, &**other) - } - #[inline] - fn le(&self, other: &Sendable) -> bool { - PartialOrd::le(&**self, &**other) - } - #[inline] - fn ge(&self, other: &Sendable) -> bool { - PartialOrd::ge(&**self, &**other) - } - #[inline] - fn gt(&self, other: &Sendable) -> bool { - PartialOrd::gt(&**self, &**other) - } -} - -impl Ord for Sendable { - #[inline] - fn cmp(&self, other: &Sendable) -> Ordering { - Ord::cmp(&**self, &**other) - } -} - -impl Eq for Sendable {} - -impl Hash for Sendable { - fn hash(&self, state: &mut H) { - (**self).hash(state); - } -} - -impl Drop for Sendable { - fn drop(&mut self) { - if self.memory_state != MemoryState::Available { - panic!("invalid memory state: {:?}", self.memory_state); - } - let range = crate::MemoryRange::new(self.contents as usize, self.total_size).unwrap(); - crate::unmap_memory(range).unwrap(); - } -} diff --git a/xous-rs/src/lib.rs b/xous-rs/src/lib.rs index 970d2a4b7..1229a7c14 100644 --- a/xous-rs/src/lib.rs +++ b/xous-rs/src/lib.rs @@ -11,7 +11,6 @@ pub mod arch; pub mod carton; pub mod definitions; -pub mod ipc; mod messages; pub mod string; pub mod buffer; diff --git a/xous-rs/src/string.rs b/xous-rs/src/string.rs index 9d877061d..d8d6b91ea 100644 --- a/xous-rs/src/string.rs +++ b/xous-rs/src/string.rs @@ -5,7 +5,7 @@ use rkyv::Unarchive; use rkyv::archived_value; use core::pin::Pin; -//#[derive(rkyv::Archive)] +#[derive(Copy, Clone)] pub struct String { bytes: [u8; N], len: u32, @@ -121,15 +121,6 @@ pub struct ArchivedString { ptr: rkyv::RelPtr, len: u32, } -/* -impl ArchivedString { - pub fn as_str(&self) -> &str { - unsafe { - let bytes = core::slice::from_raw_parts(self.ptr.as_ptr(), self.len as usize); - core::str::from_utf8_unchecked(&bytes) - } - } -}*/ pub struct StringResolver { bytes_pos: usize, }