Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace AsSliceU8 trait with zerocopy::AsBytes #692

Closed
mkroening opened this issue Mar 26, 2023 · 7 comments
Closed

Replace AsSliceU8 trait with zerocopy::AsBytes #692

mkroening opened this issue Mar 26, 2023 · 7 comments
Assignees
Labels
soundness Something is unsound.

Comments

@mkroening
Copy link
Member

Padding is uninitialized: Glossary - Unsafe Code Guidelines Reference

We do not check for padding, neither is AsSliceU8 unsafe.
zerocopy::AsBytes performs these checks.

@mkroening mkroening added the soundness Something is unsound. label Mar 26, 2023
@joannejchen
Copy link
Contributor

Hi @mkroening! @scotran and I are part of a Virtualization course at UT Austin, and as part of a project we have to contribute to open source repositories. Can we take up this issue?

@mkroening
Copy link
Member Author

Sure, do you want to do all three issues?

PS: To assign @scotran, he has to be a participant of this issue. Just write anything, then I can add him as well.

@joannejchen
Copy link
Contributor

Yep, all three issues would be great!

@joannejchen
Copy link
Contributor

joannejchen commented Apr 20, 2023

Hi @mkroening! I was able to switch the VirtioNetHdr (currently reflected in the pull request created) from implementing AsSliceU8 to deriving AsBytes, but I ran into an issue when trying to change from AsSliceU8 to AsBytes for the Cmd and Rsp structs (https://github.com/hermitcore/libhermit-rs/blob/master/src/fs/fuse.rs#L293): #[derive(AsBytes)] is not supported on types with type parameters. Digging around, there seems to be a workaround (google/zerocopy#10), but this would require using repr(transparent), which then cannot be used alongside repr(C) or repr(packed), which would strip padding and possibly cause alignment issue.

I just wanted to touch base first as to whether this would be the desired approach, and if so, I can continue looking into how to derive AsBytes for structs with type parameters.

joannejchen pushed a commit to joannejchen/libhermit-rs that referenced this issue Apr 20, 2023
Changed VirtioNetHdr to derive from AsBytes instead of AsSliceU8 and
changed related functions as necessary.

Fixes hermit-os#692.
joannejchen pushed a commit to joannejchen/libhermit-rs that referenced this issue Apr 20, 2023
Changed VirtioNetHdr to derive from AsBytes instead of AsSliceU8 and
changed related functions as necessary.

Fixes hermit-os#692.
joannejchen pushed a commit to joannejchen/libhermit-rs that referenced this issue Apr 20, 2023
Changed VirtioNetHdr to derive from AsBytes instead of AsSliceU8 and
changed related functions as necessary.

Fixes hermit-os#692.
joannejchen pushed a commit to joannejchen/libhermit-rs that referenced this issue Apr 21, 2023
Changed VirtioNetHdr to derive from AsBytes instead of AsSliceU8 and
changed related functions as necessary.

Fixes hermit-os#692.
joannejchen pushed a commit to joannejchen/libhermit-rs that referenced this issue Apr 21, 2023
Attempts to completely remove the AsSliceU8 trait by directly
implementing AsBytes for generic structs because of lack of support for
generics using derive.

Fixes hermit-os#692.

Signed-off-by: Joanne Chen <joannejc@cs.utexas.edu>
joannejchen pushed a commit to joannejchen/libhermit-rs that referenced this issue Apr 21, 2023
Attempts to completely remove the AsSliceU8 trait by directly
implementing AsBytes for generic structs because of lack of support for
generics using derive.

Fixes hermit-os#692.

Signed-off-by: Joanne Chen <joannejc@cs.utexas.edu>
joannejchen pushed a commit to joannejchen/libhermit-rs that referenced this issue Apr 21, 2023
Changed VirtioNetHdr to derive from AsBytes instead of AsSliceU8 and
changed related functions as necessary. AsSliceU8 cannot be completely
removed yet because of lack of support for deriving AsBytes for
generics.

Fixes hermit-os#692.
@mkroening mkroening assigned cagatay-y and unassigned joannejchen Oct 31, 2023
@mkroening
Copy link
Member Author

Just as an aside, there is a proposal for DynSized, with a very similar purpose to our AsSliceU8: rust-lang/rfcs#3536

@cagatay-y
Copy link
Contributor

AsSliceU8 was removed with #1316. I think we can close this issue.

@mkroening
Copy link
Member Author

Superseded by #1316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
soundness Something is unsound.
Projects
None yet
Development

No branches or pull requests

3 participants