Added support for epoll.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2241 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_syscalls.c b/coregrind/vg_syscalls.c
index d2db2b2..5ae3cfe 100644
--- a/coregrind/vg_syscalls.c
+++ b/coregrind/vg_syscalls.c
@@ -2128,7 +2128,7 @@
 POST(fcntl)
 {
    if (arg2 == VKI_F_DUPFD)
-      if(VG_(clo_track_fds))
+      if (VG_(clo_track_fds))
          record_fd_open(tid, res, VG_(resolve_filename)(res));
 }
 
@@ -3945,6 +3945,52 @@
    }
 }
 
+PRE(epoll_create)
+{
+   /* int epoll_create(int size) */
+   MAYBE_PRINTF("epoll_create ( %d )\n", arg1);
+}
+
+POST(epoll_create)
+{
+   if (!fd_allowed(res, "open", tid)) {
+      VG_(close)(res);
+      res = -VKI_EMFILE;
+   } else {
+      if (VG_(clo_track_fds))
+         record_fd_open (tid, res, NULL);
+   }
+}
+
+PRE(epoll_ctl)
+{
+   /* int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) */
+   static const char* epoll_ctl_s[3] = {
+      "EPOLL_CTL_ADD",
+      "EPOLL_CTL_DEL",
+      "EPOLL_CTL_MOD"
+   };
+   MAYBE_PRINTF("epoll_ctl ( %d, %s, %d, %p )\n", 
+                arg1, ( arg2<3 ? epoll_ctl_s[arg2] : "?" ), arg3, arg4);
+   SYSCALL_TRACK( pre_mem_read, tid, "epoll_ctl(event)",
+                  arg4, sizeof(struct vki_epoll_event) );
+}
+
+PRE(epoll_wait)
+{
+   /* int epoll_wait(int epfd, struct epoll_event * events, 
+                     int maxevents, int timeout) */
+   MAYBE_PRINTF("epoll_wait ( %d, %p, %d, %d )\n", arg1, arg2, arg3, arg4);
+   SYSCALL_TRACK( pre_mem_write, tid, "epoll_wait(events)",
+                  arg2, sizeof(struct vki_epoll_event)*arg3);
+}
+
+POST(epoll_wait)
+{
+   if (res > 0)
+      VG_TRACK( post_mem_write, arg2, sizeof(struct vki_epoll_event)*res ) ;
+}
+
 PRE(readlink)
 {
    /* int readlink(const char *path, char *buf, size_t bufsiz); */
@@ -5201,6 +5247,9 @@
    SYSBA(creat,			True),
    SYSBA(pipe,			False),
    SYSBA(poll,			True),
+   SYSBA(epoll_create,          False),
+   SYSB_(epoll_ctl,             False),
+   SYSBA(epoll_wait,		True),
    SYSBA(readlink,		False),
    SYSBA(readv,			True),
    SYSB_(rename,		False),
diff --git a/coregrind/vg_unsafe.h b/coregrind/vg_unsafe.h
index a87387b..faf26e8 100644
--- a/coregrind/vg_unsafe.h
+++ b/coregrind/vg_unsafe.h
@@ -93,7 +93,6 @@
 
 #include <sys/poll.h>
 
-
 /*--------------------------------------------------------------------*/
 /*--- end                                              vg_unsafe.h ---*/
 /*--------------------------------------------------------------------*/
diff --git a/include/vg_kerneliface.h b/include/vg_kerneliface.h
index 2df0a93..6b70e6f 100644
--- a/include/vg_kerneliface.h
+++ b/include/vg_kerneliface.h
@@ -509,6 +509,19 @@
 #define VKI_POLLNVAL        0x0020
 
 
+/* sys/epoll.h */
+typedef union vki_epoll_data {
+   void *ptr;
+   Int   fd;
+   UInt  u32;
+   ULong u64;
+} vki_epoll_data_t;
+
+struct vki_epoll_event {
+   UInt events;            /* Epoll events */
+   vki_epoll_data_t data;      /* User data variable */
+};
+
 
 /* 
 ./include/asm-i386/posix_types.h:typedef long           __kernel_suseconds_t;