Skip to content

Commit fe17cb7

Browse files
bors[bot]asomers
andauthored
Merge #1243
1243: Apply `repr(transparent)` to several FFI types r=asomers a=asomers repr(transparent) is required in order to safely cast between an FFI type and its NewType. This commit applies that attribute to PollFd, EpollEvent, IpMembershipRequest, Ipv6MembershipRequest, TimeVal, and IoVec. Fixes #1241 Co-authored-by: Alan Somers <asomers@gmail.com>
2 parents 465a8f7 + b920333 commit fe17cb7

File tree

6 files changed

+11
-6
lines changed

6 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4646
16KB. (#[1198](https://github.com/nix-rust/nix/pull/1198))
4747
- Fixed unaligned casting of `cmsg_data` to `af_alg_iv` (#[1206](https://github.com/nix-rust/nix/pull/1206))
4848
- Fixed `readlink`/`readlinkat` when reading symlinks longer than `PATH_MAX` (#[1231](https://github.com/nix-rust/nix/pull/1231))
49+
- `PollFd`, `EpollEvent`, `IpMembershipRequest`, `Ipv6MembershipRequest`,
50+
`TimeVal`, and `IoVec` are now `repr(transparent)`. This is required for
51+
correctness's sake across all architectures and compilers, though now bugs
52+
have been reported so far.
53+
(#[1243](https://github.com/nix-rust/nix/pull/1243))
4954

5055
### Removed
5156

src/poll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use errno::Errno;
1717
///
1818
/// After a call to `poll` or `ppoll`, the events that occured can be
1919
/// retrieved by calling [`revents()`](#method.revents) on the `PollFd`.
20-
#[repr(C)]
20+
#[repr(transparent)]
2121
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
2222
pub struct PollFd {
2323
pollfd: libc::pollfd,

src/sys/epoll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ libc_bitflags!{
4343
}
4444

4545
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
46-
#[repr(C)]
46+
#[repr(transparent)]
4747
pub struct EpollEvent {
4848
event: libc::epoll_event,
4949
}

src/sys/socket/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ cfg_if! {
278278
/// Request for multicast socket operations
279279
///
280280
/// This is a wrapper type around `ip_mreq`.
281-
#[repr(C)]
281+
#[repr(transparent)]
282282
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
283283
pub struct IpMembershipRequest(libc::ip_mreq);
284284

@@ -297,7 +297,7 @@ impl IpMembershipRequest {
297297
/// Request for ipv6 multicast socket operations
298298
///
299299
/// This is a wrapper type around `ipv6_mreq`.
300-
#[repr(C)]
300+
#[repr(transparent)]
301301
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
302302
pub struct Ipv6MembershipRequest(libc::ipv6_mreq);
303303

src/sys/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl fmt::Display for TimeSpec {
245245

246246

247247

248-
#[repr(C)]
248+
#[repr(transparent)]
249249
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
250250
pub struct TimeVal(timeval);
251251

src/sys/uio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn process_vm_readv(pid: ::unistd::Pid, local_iov: &[IoVec<&mut [u8]>], remo
158158
Errno::result(res).map(|r| r as usize)
159159
}
160160

161-
#[repr(C)]
161+
#[repr(transparent)]
162162
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
163163
pub struct IoVec<T>(libc::iovec, PhantomData<T>);
164164

0 commit comments

Comments
 (0)