Skip to content

Commit

Permalink
libnative: fix epoll_event struct layout
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bnoordhuis committed Feb 2, 2014
1 parent 3e0eb3c commit 6121acf
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/libnative/io/timer_timerfd.rs
Expand Up @@ -59,17 +59,15 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
fn add(efd: libc::c_int, fd: libc::c_int) {
let event = imp::epoll_event {
events: imp::EPOLLIN as u32,
data: imp::epoll_data_t { fd: fd, pad: 0, }
data: fd as i64,
};
let ret = unsafe {
imp::epoll_ctl(efd, imp::EPOLL_CTL_ADD, fd, &event)
};
assert_eq!(ret, 0);
}
fn del(efd: libc::c_int, fd: libc::c_int) {
let event = imp::epoll_event {
events: 0, data: imp::epoll_data_t { fd: 0, pad: 0, }
};
let event = imp::epoll_event { events: 0, data: 0 };
let ret = unsafe {
imp::epoll_ctl(efd, imp::EPOLL_CTL_DEL, fd, &event)
};
Expand All @@ -93,7 +91,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
let mut incoming = false;
debug!("{} events to process", n);
for event in events.slice_to(n as uint).iter() {
let fd = event.data.fd;
let fd = event.data as libc::c_int;
debug!("data on fd {} (input = {})", fd, input);
if fd == input {
let mut buf = [0, ..1];
Expand Down Expand Up @@ -261,14 +259,17 @@ mod imp {
pub static EPOLLHUP: libc::c_int = 0x010;
pub static EPOLLONESHOT: libc::c_int = 1 << 30;

#[cfg(target_arch = "x86_64")]
#[packed]
pub struct epoll_event {
events: u32,
data: epoll_data_t,
data: i64,
}

pub struct epoll_data_t {
fd: i32,
pad: u32,
#[cfg(not(target_arch = "x86_64"))]
pub struct epoll_event {
events: u32,
data: i64,
}

pub struct timespec {
Expand Down

5 comments on commit 6121acf

@bors
Copy link
Contributor

@bors bors commented on 6121acf Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 6121acf Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bnoordhuis/rust/sizeof-epoll-event-fixup = 6121acf into auto

@bors
Copy link
Contributor

@bors bors commented on 6121acf Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bnoordhuis/rust/sizeof-epoll-event-fixup = 6121acf merged ok, testing candidate = 62caad2

@bors
Copy link
Contributor

@bors bors commented on 6121acf Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 6121acf Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 62caad2

Please sign in to comment.