Skip to content

Commit 62caad2

Browse files
committed
auto merge of #12003 : bnoordhuis/rust/sizeof-epoll-event-fixup, r=brson
Make the definition of epoll_event use natural alignment on all architectures except x86_64. Before this commit, the struct was always 12 bytes big, which works okay on x86 and x86_64 but not on ARM and MIPS, where it should be 16 bytes big with the `data` field aligned on an 8 byte boundary.
2 parents 7db6bca + 6121acf commit 62caad2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/libnative/io/timer_timerfd.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,15 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
5959
fn add(efd: libc::c_int, fd: libc::c_int) {
6060
let event = imp::epoll_event {
6161
events: imp::EPOLLIN as u32,
62-
data: imp::epoll_data_t { fd: fd, pad: 0, }
62+
data: fd as i64,
6363
};
6464
let ret = unsafe {
6565
imp::epoll_ctl(efd, imp::EPOLL_CTL_ADD, fd, &event)
6666
};
6767
assert_eq!(ret, 0);
6868
}
6969
fn del(efd: libc::c_int, fd: libc::c_int) {
70-
let event = imp::epoll_event {
71-
events: 0, data: imp::epoll_data_t { fd: 0, pad: 0, }
72-
};
70+
let event = imp::epoll_event { events: 0, data: 0 };
7371
let ret = unsafe {
7472
imp::epoll_ctl(efd, imp::EPOLL_CTL_DEL, fd, &event)
7573
};
@@ -93,7 +91,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
9391
let mut incoming = false;
9492
debug!("{} events to process", n);
9593
for event in events.slice_to(n as uint).iter() {
96-
let fd = event.data.fd;
94+
let fd = event.data as libc::c_int;
9795
debug!("data on fd {} (input = {})", fd, input);
9896
if fd == input {
9997
let mut buf = [0, ..1];
@@ -261,14 +259,17 @@ mod imp {
261259
pub static EPOLLHUP: libc::c_int = 0x010;
262260
pub static EPOLLONESHOT: libc::c_int = 1 << 30;
263261

262+
#[cfg(target_arch = "x86_64")]
263+
#[packed]
264264
pub struct epoll_event {
265265
events: u32,
266-
data: epoll_data_t,
266+
data: i64,
267267
}
268268

269-
pub struct epoll_data_t {
270-
fd: i32,
271-
pad: u32,
269+
#[cfg(not(target_arch = "x86_64"))]
270+
pub struct epoll_event {
271+
events: u32,
272+
data: i64,
272273
}
273274

274275
pub struct timespec {

0 commit comments

Comments
 (0)