Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

epoll_data alignement problem #2126

Closed
Stargateur opened this issue Mar 27, 2021 · 2 comments
Closed

epoll_data alignement problem #2126

Stargateur opened this issue Mar 27, 2021 · 2 comments
Labels
C-bug Category: bug

Comments

@Stargateur
Copy link

rust-lang/rust#46043 introduce a problem concerning epoll_data. I didn't find a way to assume it safe for me to take a reference of u64 or events.

My crate define a struct:

#[repr(transparent)]
pub struct Event<T: DataKind> {
    inner: libc::epoll_event,
    phontom: PhantomData<T>,
}

This allow me to copy layout from libc::epoll_event on every os very easily without the need to handle every os layout myself but this disallow me to know when the alignment of the struct is 1.

For events is not a big deal for me cause I just copy according to the linked issue the compiler will handle it correctly but my use of u64 can't allow copy.

Is there a rust cfg like cfg_attr(aligned_is(1)) or something like that ? With this I could assume is safe to take using unsafe and if aligned is not 1 I can use a code that doesn't use unsafe letting the compiler check the safety for me.

Without something like this is become very hard for me to use libc::epoll_event. I need to assume that the packed structure is 1 aligned. Of course I expect every OS that use a packed libc::epoll_event should be #[repr(packed(1))] so it should not be a big deal but nothing prevent an OS to do that.

@Stargateur Stargateur added the C-bug Category: bug label Mar 27, 2021
@Stargateur
Copy link
Author

Reading more deeply I may have miss interpreted the alignment 1, it's only work for field of size 1 like u8 ? this is not very clear to me.

@niluxv
Copy link
Contributor

niluxv commented Oct 25, 2022

How about using core::mem::align_of? playground

@rust-lang rust-lang locked and limited conversation to collaborators Aug 29, 2024
@tgross35 tgross35 converted this issue into discussion #3879 Aug 29, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants