epoll_event cannot carry provenance on user data

未关闭
#4,885 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
c, rust

调研方向

从现有的 Rust libc 对 epoll_event 的声明开始,并将其与 issue 中引用的 C 定义进行比较。确定 libc 1.0 是否应直接公开 union,或者 libc 0.2 是否需要单独的 event_data 和 event_ctl API;选定的保留来源信息的接口完成实现,并针对携带指针的使用场景完成检查,即表示完成。

由索引模型根据 Issue 内容生成。

描述

C-bug

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.

主要语言
Rust
星标
2.6k
派生
1.3k
平均合并
2 天 10 小时
30 天内合并 PR
26

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-lang/libc 的其他 Issue

查看 rust-lang/libc 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。