libc icon indicating copy to clipboard operation
libc copied to clipboard

Consolidate CMSG_* implementations

Open gibbz00 opened this issue 2 months ago • 5 comments

~~Builds upon rust-lang/libc#4903~~Merged

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 -- consistently [^*].
  • 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.

Breaking API change Suggestions

  • Perhaps CMSG_FIRSTHDR can take mhdr by reference? First thing being done is otherwise a raw pointer deref under practically no safety guarantees. Doing so would also remove the need to mark it unsafe.

  • Same reasoning can be applied to mhdr in CMSG_NXTHDR, difference being that the function must remain unsafe for dereferencing cmsg.

[^*]: Except CMSG_DATA on solarish. It does align(cmsg_addr + size_of(cmsg)) rather than cmsg_addr + align(size_of(cmsg>)). The others can get away with not casting the cmsg pointer to usize by instead casting cmsg to a byte pointer and doing the addition using byte_ptr.offset().

gibbz00 avatar Jan 03 '26 13:01 gibbz00

Some changes occurred in the Android module

cc @maurer

Some changes occurred in solarish module

cc @jclulow, @pfmooney

Some changes occurred in OpenBSD module

cc @semarie

rustbot avatar Jan 03 '26 13:01 rustbot

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.

rustbot avatar Jan 05 '26 09:01 rustbot

Reminder, once the PR becomes ready for a review, use @rustbot ready.

rustbot avatar Jan 05 '26 21:01 rustbot

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.

rustbot avatar Jan 06 '26 12:01 rustbot

@rustbot ready

gibbz00 avatar Jan 06 '26 13:01 gibbz00