Re: epoll gives broken results when interrupted with a signal

From: Ben Mansell
Date: Mon Nov 03 2003 - 06:08:20 EST


On Thu, 30 Oct 2003, Davide Libenzi wrote:

> Could you try to poison the event buffer before an epoll_wait() to see how
> many bytes are effectively written by the function?
>
> memset(events, 'e', num * sizeof(epoll_event));

aha! This is interesting. When epoll seems to go wrong, the
epoll_event.data of the second event is unwritten, but the .events field
is zeroed. Sometimes though, the final call to epoll_wait() returns just
one event instead of the two, and in that case, the high 32 bits of the
first epoll_event.data are unwritten. The lower 32 bits contain the
right data, and as the code treats this as a (int) FD, the top 32 bits
are discarded anyway.

Drat! I've just looked back at the kernel headers and noticed the
following, prior to the epoll_event definition:

/*
* On x86-64 make the 64bit structure have the same alignment as the
* 32bit structure. This makes 32bit emulation easier.
*/
#ifdef __x86_64__
#define EPOLL_PACKED __attribute__((packed))
#else
#define EPOLL_PACKED
#endif

struct epoll_event {
__u32 events;
__u64 data;
} EPOLL_PACKED;


Now, my code can't pull in the kernel headers so it has its own
epoll_event definition, which is missing the packed attribute. D'oh!
Guess what, everything works properly when I add it in. Looks like this
bug has been of my own making all along...

Sorry for taking up your time!


Ben

--
Ben Mansell, <ben@xxxxxxxx> Zeus Technology Ltd
Download the world's fastest webserver! Universally Serving the Net
T:+44(0)1223 525000 F:+44(0)1223 525100 http://www.zeus.com
Zeus House, Cowley Road, Cambridge, CB4 0ZT, ENGLAND
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/