Skip to content

epoll_data alignement problem #2126

@Stargateur

Description

@Stargateur

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions