diff --git a/Cargo.lock b/Cargo.lock index d188a28..8bb91c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ dependencies = [ "bitflags", "byteorder", "serde", - "zerocopy", + "zerocopy 0.6.1", ] [[package]] @@ -260,7 +260,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idol" -version = "0.4.0" +version = "0.5.0" dependencies = [ "indexmap 1.9.2", "once_cell", @@ -276,11 +276,11 @@ dependencies = [ [[package]] name = "idol-runtime" -version = "0.1.0" +version = "0.2.0" dependencies = [ "counters", "userlib", - "zerocopy", + "zerocopy 0.8.25", ] [[package]] @@ -656,7 +656,7 @@ dependencies = [ "paste", "serde", "ssmarshal", - "zerocopy", + "zerocopy 0.6.1", ] [[package]] @@ -795,7 +795,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "332f188cc1bcf1fe1064b8c58d150f497e697f49774aa846f2dc949d9a25f236" dependencies = [ "byteorder", - "zerocopy-derive", + "zerocopy-derive 0.3.1", +] + +[[package]] +name = "zerocopy" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +dependencies = [ + "zerocopy-derive 0.8.25", ] [[package]] @@ -808,3 +817,14 @@ dependencies = [ "syn 1.0.109", "synstructure", ] + +[[package]] +name = "zerocopy-derive" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] diff --git a/Cargo.toml b/Cargo.toml index c05ce3f..2fcd783 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "idol" -version = "0.4.0" +version = "0.5.0" edition = "2021" [features] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 85a7c27..47a64af 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "idol-runtime" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -8,4 +8,4 @@ edition = "2021" [dependencies] counters = { git = "https://github.com/oxidecomputer/hubris" } userlib = {git = "https://github.com/oxidecomputer/hubris"} -zerocopy = "0.6.1" +zerocopy = "0.8.25" diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index afe2ce1..edc8c16 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -15,7 +15,7 @@ use userlib::{ sys_reply_fault, FromPrimitive, LeaseAttributes, RecvMessage, ReplyFaultReason, TaskId, }; -use zerocopy::{AsBytes, FromBytes}; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes}; #[derive(Copy, Clone, Debug, Eq, PartialEq, Count)] #[repr(u32)] @@ -539,7 +539,11 @@ impl Leased { /// These functions are available on any readable lease (that is, read-only or /// read-write) where the content type `T` is `Sized` and can be moved around by /// naive mem-copy. -impl Leased { +impl Leased +where + A: AttributeRead, + T: Sized + Copy + FromZeros + FromBytes + IntoBytes, +{ /// Reads the leased value by copy. /// /// If the lending task has been restarted between the time we checked lease @@ -549,7 +553,7 @@ impl Leased { pub fn read(&self) -> Option { let mut temp = T::new_zeroed(); let (rc, len) = - sys_borrow_read(self.lender, self.index, 0, temp.as_bytes_mut()); + sys_borrow_read(self.lender, self.index, 0, temp.as_mut_bytes()); if rc != 0 || len != core::mem::size_of::() { None } else { @@ -561,7 +565,11 @@ impl Leased { /// These functions are available on any readable leased slice (that is, /// read-only or read-write) where the element type `T` is `Sized` and can be /// moved around by naive mem-copy. -impl Leased { +impl Leased +where + A: AttributeRead, + T: Sized + Copy + FromZeros + FromBytes + IntoBytes, +{ /// Reads a single element of the leased slice by copy. /// /// Like indexing a native slice, `index` must be less than `self.len()`, or @@ -580,7 +588,7 @@ impl Leased { self.lender, self.index, offset, - temp.as_bytes_mut(), + temp.as_mut_bytes(), ); if rc != 0 || len != core::mem::size_of::() { None @@ -615,7 +623,7 @@ impl Leased { self.lender, self.index, offset, - dest.as_bytes_mut(), + dest.as_mut_bytes(), ); if rc != 0 || len != expected_len { @@ -629,7 +637,11 @@ impl Leased { /// These functions are available on any writable lease (that is, write-only or /// read-write) where the content type `T` is `Sized` and can be moved around by /// naive mem-copy. -impl Leased { +impl Leased +where + A: AttributeWrite, + T: Sized + Copy + IntoBytes + Immutable, +{ /// Writes the leased value by copy. /// /// If the lending task has been restarted between the time we checked lease @@ -650,7 +662,11 @@ impl Leased { /// These functions are available on any writable leased slice (that is, /// write-only or read-write) where the element type `T` is `Sized` and can be /// moved around by naive mem-copy. -impl Leased { +impl Leased +where + A: AttributeWrite, + T: Sized + Copy + IntoBytes + Immutable, +{ /// Writes a single element of the leased slice by copy. /// /// Like indexing a native slice, `index` must be less than `self.len()`, or diff --git a/src/client.rs b/src/client.rs index 96ee780..144c7ce 100644 --- a/src/client.rs +++ b/src/client.rs @@ -200,7 +200,10 @@ impl Generator { let attrs = match op.encoding { syntax::Encoding::Zerocopy => { quote! { - #[derive(zerocopy::AsBytes)] + #[derive( + zerocopy_derive::IntoBytes, + zerocopy_derive::Immutable, + )] #[repr(C, packed)] } } @@ -323,7 +326,7 @@ impl Generator { let op_enum_name = iface_name.as_op_enum(); let buf = match op.encoding { syntax::Encoding::Zerocopy => { - quote! { zerocopy::AsBytes::as_bytes(&args) } + quote! { zerocopy::IntoBytes::as_bytes(&args) } } syntax::Encoding::Ssmarshal | syntax::Encoding::Hubpack => { quote! { &argsbuf[..arglen] } @@ -331,8 +334,8 @@ impl Generator { }; let leases = op.leases.iter().map(|(leasename, lease)| { let (ctor, asbytes) = match (lease.read, lease.write) { - (true, true) => ("read_write", "as_bytes_mut"), - (false, true) => ("write_only", "as_bytes_mut"), + (true, true) => ("read_write", "as_mut_bytes"), + (false, true) => ("write_only", "as_mut_bytes"), (true, false) => ("read_only", "as_bytes"), (false, false) => panic!("should have been caught above"), }; @@ -342,7 +345,7 @@ impl Generator { syn::Ident::new(asbytes, proc_macro2::Span::call_site()); let argname = leasename.arg_prefixed(); quote! { - userlib::Lease::#ctor(zerocopy::AsBytes::#asbytes(#argname)) + userlib::Lease::#ctor(zerocopy::IntoBytes::#asbytes(#argname)) } }); quote! { @@ -367,14 +370,15 @@ impl Generator { let repr_ty = t.repr_ty(); quote! { let _len = len; - #[derive(zerocopy::FromBytes, zerocopy::Unaligned)] + #[derive( + zerocopy_derive::FromBytes, + zerocopy_derive::Unaligned, + )] #[repr(C, packed)] struct #reply_ty { value: #repr_ty, } - let lv = zerocopy::LayoutVerified::<_, #reply_ty>::new_unaligned(&reply[..]) - .unwrap_lite(); - let v: #repr_ty = lv.value; + let v: #repr_ty = zerocopy::FromBytes::read_from_bytes(&reply[..]).unwrap_lite(); } } syntax::Encoding::Ssmarshal => quote! { diff --git a/src/server.rs b/src/server.rs index efb967a..6bd2ee9 100644 --- a/src/server.rs +++ b/src/server.rs @@ -213,7 +213,14 @@ impl Generator { let attrs = match op.encoding { syntax::Encoding::Zerocopy => quote! { #[repr(C, packed)] - #[derive(Copy, Clone, zerocopy::FromBytes, zerocopy::Unaligned)] + #[derive( + Copy, + Clone, + zerocopy_derive::FromBytes, + zerocopy_derive::KnownLayout, + zerocopy_derive::Immutable, + zerocopy_derive::Unaligned, + )] }, syntax::Encoding::Ssmarshal => quote! { #[derive(Copy, Clone, serde::Deserialize)] @@ -307,8 +314,7 @@ impl Generator { match op.encoding { syntax::Encoding::Zerocopy => quote! { pub fn #read_fn(bytes: &[u8]) -> Option<&#struct_name> { - Some(zerocopy::LayoutVerified::<_, #struct_name>::new_unaligned(bytes)? - .into_ref()) + zerocopy::FromBytes::ref_from_bytes(bytes).ok() } }, syntax::Encoding::Ssmarshal => quote! { @@ -551,7 +557,7 @@ impl Generator { let reply = { let encode = match op.encoding { syntax::Encoding::Zerocopy => quote! { - userlib::sys_reply(rm.sender, 0, zerocopy::AsBytes::as_bytes(&val)); + userlib::sys_reply(rm.sender, 0, zerocopy::IntoBytes::as_bytes(&val)); }, syntax::Encoding::Hubpack | syntax::Encoding::Ssmarshal => { let reply_size = opname.as_reply_size(); diff --git a/src/syntax.rs b/src/syntax.rs index efc67f6..bf6f986 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -275,11 +275,11 @@ pub struct Lease { #[serde(rename = "type")] pub ty: Ty, /// The server will be able to read from this lease. The type being leased - /// must implement `zerocopy::AsBytes`. + /// must implement `idol_runtime::zerocopy::AsBytes`. #[serde(default)] pub read: bool, /// The server will be able to write to this lease. The type being leased - /// must implement both `zerocopy::AsBytes` and `zerocopy::FromBytes`. + /// must implement both `idol_runtime::zerocopy::AsBytes` and `idol_runtime::zerocopy::FromBytes`. #[serde(default)] pub write: bool, /// The server cannot accept leases longer than this. @@ -538,7 +538,7 @@ impl quote::ToTokens for Error { #[derive(Debug, Clone, Serialize, Deserialize)] pub enum RecvStrategy { /// The received bytes should be directly reinterpreted as the type using - /// `zerocopy::FromBytes`. + /// `idol_runtime::zerocopy::FromBytes`. FromBytes, /// The received bytes should be the named type, which will then be /// converted into the target type using `num_traits::FromPrimitive` (which