Skip to content

Conversation

@gibbz00
Copy link
Contributor

@gibbz00 gibbz00 commented Jan 2, 2026

Builds upon #4908


Use size_t for parameter and return value of CMSG_{LEN,SPACE}

Fixes: #3240

Matches all platforms except Solaris and its descendants. size_t is
used there regardless in order to force excessive conversions, and to
make cross-platform code easier to write.

@rustbot
Copy link
Collaborator

rustbot commented Jan 2, 2026

Some changes occurred in solarish module

cc @jclulow, @pfmooney

Some changes occurred in OpenBSD module

cc @semarie

Some changes occurred in the Android module

cc @maurer

@rustbot

This comment has been minimized.

The original intent was to simplify the reasoning for how they
differ across platforms. It should as a consequence also make it
easier to extend target support.

Changes:

- CMSG_* functions which can be const are all marked const.
- Removes unsafe from `CMSG_ALIGN`, `CMSG_SPACE`, `CMSG_LEN`.

Fixes:

Custom CMSG_FIRSTHDR implementation for VxWorks had missed to check
that `mhdr.msg_controllen >= size_of::<cmsghdr>()`, as per
POSIX 1003.1-2024.

Documents:

- Usage and safety requirements.
- Adds missing references to upstream headers.
Fixes: rust-lang#3240

Matches all platforms except Solaris and its descendants. `size_t` is
used there regardless in order to force excessive conversions, and to
make cross-platform code easier to write.

[illumos]: https://github.com/illumos/illumos-gate/blob/118b2dbf1f4a745a7e35a5054a777c09bd90fff7/usr/src/uts/common/sys/socket.h#L499-L505
@gibbz00 gibbz00 force-pushed the cmsg_len_space_size_t branch from 9bfc5af to 97ccab6 Compare January 5, 2026 10:07
@rustbot
Copy link
Collaborator

rustbot commented Jan 5, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Types of CMSG_LEN and CMSG_SPACE don't match libc on many platforms

3 participants