Skip to content

epoll_event cannot carry provenance on user data #4885

@RalfJung

Description

@RalfJung

The epoll_event type is declared like this in C:

       struct epoll_event {
           uint32_t      events;  /* Epoll events */
           epoll_data_t  data;    /* User data variable */
       };

       union epoll_data {
           void     *ptr;
           int       fd;
           uint32_t  u32;
           uint64_t  u64;
       };

       typedef union epoll_data  epoll_data_t;

However, the Rust version in libc is different -- it just uses u64 for the data field. That is, unfortunately, not equivalent -- u64 cannot carry pointer provenance, so programs that want to store a pointer in data (which is quite common) need to use exposed-provenance APIs (i.e., ptr/int casts). Tokio carries some funky hacks to avoid that.

Since the C API is actually compatible with strict provenance here, it would be nice to expose that in libc as well. Given this is a breaking change it can only happen for libc 1.0 -- though it would be possible to have a separate event_data type and event_ctl declaration in its own module even in libc 0.2.

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