RPC alignment and size calculation #159
Labels
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: M-Labs/artiq-zynq#159
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
I am trying to fix https://github.com/m-labs/artiq/issues/1810 , and is currently reviewing our RPC code. There are a couple of potential problems in our code. I am unable to devise an example that can cause memory corruption with these, but I think we should probably get them fixed and make sure that they are correct.
https://git.m-labs.hk/M-Labs/artiq-zynq/src/branch/master/src/runtime/src/rpc.rs#L76-L108
There are two problems here.
(*ptr).elements
may be different from the slice pointer (ptr = align_ptr_mut::<u64>(data)
), as the latter one is aligned to 8 bytes while the alloc is only guaranteed to align to 4 bytes boundary.align_ptr_mut
may causeptr
to be 4 bytes afterdata
.The fix I'm thinking about is to
(*ptr).elements
.Another way would be to make alloca align to 8 bytes boundary, but this will waste memory for other types.
I think the code for array is also problematic for the same reason.
Apart from the above bugs, I'm also thinking about what is the best way to fix the tuple alignment and size calculation bug. We can write a function to calculate the alignment in our RPC code, or embed the alignment and size requirement for tuples in the tag which can be emitted by the compiler.