rust-lang / rust-lang/libc

XDP_UMEM_PGOFF_FILL_RING and XDP_UMEM_PGOFF_COMPLETION_RING have an incorrect/inconsistent type

Open
#4,821 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
2.6k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
69

Description

The code below would fail to compile because XDP_UMEM_PGOFF_FILL_RING and XDP_UMEM_PGOFF_COMPLETION_RING are of type c_ulonglong (u64) while XDP_PGOFF_RX_RING and XDP_PGOFF_TX_RING are of type off_t (i64).

enum RingBufferType {
    XdpRx,
    XdpTx,
    XdpFill,
    XdpCompletion
}

impl RingBufferType {
    fn get_mmap_offset(&self) -> libc::off_t {
        match self {
            RingBufferType::XdpRx => libc::XDP_PGOFF_RX_RING,
            RingBufferType::XdpTx => libc::XDP_PGOFF_TX_RING,
            RingBufferType::XdpFill => libc::XDP_UMEM_PGOFF_FILL_RING,
            RingBufferType::XdpCompletion => libc::XDP_UMEM_PGOFF_COMPLETION_RING,
        }
    }
}

Considering that these constants are used for mmap calls in the position of the offset parameter they should all be off type off_t as that is what mmap expects. This can currently be worked around by simple casting the constant with as.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the definitions of XDP_UMEM_PGOFF_FILL_RING, XDP_UMEM_PGOFF_COMPLETION_RING, XDP_PGOFF_RX_RING, and XDP_PGOFF_TX_RING in the libc bindings, then compare their declared types with mmap's offset parameter. The work is done when all four constants use the appropriate off_t-compatible type and the shown RingBufferType example compiles without casts.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking, operating-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.