Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "idol"
version = "0.4.0"
version = "0.5.0"
edition = "2021"

[features]
Expand Down
4 changes: 2 additions & 2 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[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

[dependencies]
counters = { git = "https://github.com/oxidecomputer/hubris" }
userlib = {git = "https://github.com/oxidecomputer/hubris"}
zerocopy = "0.6.1"
zerocopy = "0.8.25"
32 changes: 24 additions & 8 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -539,7 +539,11 @@ impl<T> Leased<W, [T]> {
/// 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<A: AttributeRead, T: Sized + Copy + FromBytes + AsBytes> Leased<A, T> {
impl<A, T> Leased<A, T>
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
Expand All @@ -549,7 +553,7 @@ impl<A: AttributeRead, T: Sized + Copy + FromBytes + AsBytes> Leased<A, T> {
pub fn read(&self) -> Option<T> {
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::<T>() {
None
} else {
Expand All @@ -561,7 +565,11 @@ impl<A: AttributeRead, T: Sized + Copy + FromBytes + AsBytes> Leased<A, T> {
/// 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<A: AttributeRead, T: Sized + Copy + FromBytes + AsBytes> Leased<A, [T]> {
impl<A, T> Leased<A, [T]>
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
Expand All @@ -580,7 +588,7 @@ impl<A: AttributeRead, T: Sized + Copy + FromBytes + AsBytes> Leased<A, [T]> {
self.lender,
self.index,
offset,
temp.as_bytes_mut(),
temp.as_mut_bytes(),
);
if rc != 0 || len != core::mem::size_of::<T>() {
None
Expand Down Expand Up @@ -615,7 +623,7 @@ impl<A: AttributeRead, T: Sized + Copy + FromBytes + AsBytes> Leased<A, [T]> {
self.lender,
self.index,
offset,
dest.as_bytes_mut(),
dest.as_mut_bytes(),
);

if rc != 0 || len != expected_len {
Expand All @@ -629,7 +637,11 @@ impl<A: AttributeRead, T: Sized + Copy + FromBytes + AsBytes> Leased<A, [T]> {
/// 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<A: AttributeWrite, T: Sized + Copy + AsBytes> Leased<A, T> {
impl<A, T> Leased<A, T>
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
Expand All @@ -650,7 +662,11 @@ impl<A: AttributeWrite, T: Sized + Copy + AsBytes> Leased<A, T> {
/// 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<A: AttributeWrite, T: Sized + Copy + AsBytes> Leased<A, [T]> {
impl<A, T> Leased<A, [T]>
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
Expand Down
22 changes: 13 additions & 9 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
}
}
Expand Down Expand Up @@ -323,16 +326,16 @@ 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] }
}
};
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"),
};
Expand All @@ -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! {
Expand All @@ -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! {
Expand Down
14 changes: 10 additions & 4 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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! {
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down