fix epoll structure alignment on non-x86_64 archs
authorRich Felker <dalias@aerifal.cx>
Thu, 7 Mar 2013 04:57:39 +0000 (23:57 -0500)
committerRich Felker <dalias@aerifal.cx>
Thu, 7 Mar 2013 04:57:39 +0000 (23:57 -0500)
this fix is far from ideal and breaks the rule of not using
arch-specific #ifdefs, but for now we just need a solution to the
existing breakage.

the underlying problem is that the kernel folks made a very stupid
decision to make misalignment of this struct part of the kernel
API/ABI for x86_64, in order to avoid writing a few extra lines of
code to handle both 32- and 64-bit userspace on 64-bit kernels. I had
just added the packed attribute unconditionally thinking it was
harmless on 32-bit archs, but non-x86 32-bit archs have 8-byte
alignment on 64-bit types.

include/sys/epoll.h

index 5e131ab..1f0312e 100644 (file)
@@ -46,7 +46,11 @@ typedef union epoll_data {
 struct epoll_event {
        uint32_t events;
        epoll_data_t data;
 struct epoll_event {
        uint32_t events;
        epoll_data_t data;
-} __attribute__ ((__packed__));
+}
+#ifdef __x86_64__
+__attribute__ ((__packed__))
+#endif
+;
 
 
 int epoll_create(int);
 
 
 int epoll_create(int);