From b2e84459160e8c8e49cbdee83b3da21d9f20c62f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 10 Feb 2004 23:44:15 +0000 Subject: [PATCH] Added support for epoll. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2241 --- coregrind/vg_syscalls.c | 51 +++++++++++++++++++++++++++++++++++++++- coregrind/vg_unsafe.h | 1 - include/vg_kerneliface.h | 13 ++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/coregrind/vg_syscalls.c b/coregrind/vg_syscalls.c index d2db2b278..5ae3cfe2a 100644 --- a/coregrind/vg_syscalls.c +++ b/coregrind/vg_syscalls.c @@ -2128,7 +2128,7 @@ PRE(fcntl) 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 @@ POST(poll) } } +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 @@ static const struct sys_info sys_info[] = { 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 a87387b72..faf26e89e 100644 --- a/coregrind/vg_unsafe.h +++ b/coregrind/vg_unsafe.h @@ -93,7 +93,6 @@ #include - /*--------------------------------------------------------------------*/ /*--- end vg_unsafe.h ---*/ /*--------------------------------------------------------------------*/ diff --git a/include/vg_kerneliface.h b/include/vg_kerneliface.h index 2df0a93d2..6b70e6f08 100644 --- a/include/vg_kerneliface.h +++ b/include/vg_kerneliface.h @@ -509,6 +509,19 @@ struct vki_pollfd { #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;