Consolidate CMSG_* implementations
~~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().
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
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.
Reminder, once the PR becomes ready for a review, use @rustbot ready.
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 ready