From f78d673079d5fa935d03f88fe650cf75c61b6c10 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 16 Jul 2020 15:11:17 +0800 Subject: [PATCH] firmware/rpc: added `#[repr(C)]` for structs. Previously the structs are in repr(Rust) which has no layout guarantee. --- artiq/firmware/libproto_artiq/rpc_proto.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/artiq/firmware/libproto_artiq/rpc_proto.rs b/artiq/firmware/libproto_artiq/rpc_proto.rs index c0bab177a..5e326689b 100644 --- a/artiq/firmware/libproto_artiq/rpc_proto.rs +++ b/artiq/firmware/libproto_artiq/rpc_proto.rs @@ -49,6 +49,7 @@ unsafe fn recv_value(reader: &mut R, tag: Tag, data: &mut *mut (), Ok(()) } Tag::List(it) | Tag::Array(it) => { + #[repr(C)]. struct List { elements: *mut (), length: u32 }; consume_value!(List, |ptr| { (*ptr).length = reader.read_u32()?; @@ -132,6 +133,7 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) Ok(()) } Tag::List(it) | Tag::Array(it) => { + #[repr(C)]. struct List { elements: *const (), length: u32 }; consume_value!(List, |ptr| { writer.write_u32((*ptr).length)?; @@ -151,6 +153,7 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) Ok(()) } Tag::Keyword(it) => { + #[repr(C)]. struct Keyword<'a> { name: CSlice<'a, u8> }; consume_value!(Keyword, |ptr| { writer.write_string(str::from_utf8((*ptr).name.as_ref()).unwrap())?; @@ -162,6 +165,7 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) // to accurately advance data. } Tag::Object => { + #[repr(C)]. struct Object { id: u32 }; consume_value!(*const Object, |ptr| writer.write_u32((**ptr).id))