XDP_UMEM_PGOFF_FILL_RING and XDP_UMEM_PGOFF_COMPLETION_RING have an incorrect/inconsistent type

Open
#4,821 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

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.

Description

C-bug

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.

Dominant language
Rust
Stars
2.6k
Forks
1.3k
Avg merge
2d 13h
Merged PRs (30d)
27

Getting set up

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.

More from rust-lang/libc

All issues in rust-lang/libc

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.