From eedb87c186367920216f43437aac94f7d882690f Mon Sep 17 00:00:00 2001 From: shrinivasan ganapathy Date: Thu, 5 Oct 2017 04:26:39 -0700 Subject: LD_PRELOAD - fix multiple define - EP_INT_MAX Change-Id: Ifb8a5fb722bffd80b53d7b8bab5cb360634c8cf5 Signed-off-by: shrinivasan ganapathy --- vcl-ldpreload/src/libvcl-ldpreload/vcom.c | 48 ++++++++++++++++------ .../src/libvcl-ldpreload/vcom_glibc_socket.h | 4 +- vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c | 36 ++++++++++++++-- 3 files changed, 70 insertions(+), 18 deletions(-) diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom.c b/vcl-ldpreload/src/libvcl-ldpreload/vcom.c index d292b27..75054eb 100644 --- a/vcl-ldpreload/src/libvcl-ldpreload/vcom.c +++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom.c @@ -2705,6 +2705,12 @@ epoll_create1 (int __flags) return rv; } +static inline int +ep_op_has_event (int op) +{ + return op != EPOLL_CTL_DEL; +} + int vcom_epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event) @@ -2714,17 +2720,37 @@ vcom_epoll_ctl (int __epfd, int __op, int __fd, return -1; } + /* + * the requested operation __op is not supported + * by this interface */ + if (!((__op == EPOLL_CTL_ADD) || + (__op == EPOLL_CTL_MOD) || + (__op == EPOLL_CTL_DEL))) + { + return -EINVAL; + } + + /* op is ADD or MOD but event parameter is NULL */ + if ((ep_op_has_event (__op) && !__event)) + { + return -EFAULT; + } + + /* fd is same as epfd */ + if (__epfd == __fd) + { + return -EINVAL; + } /* implementation */ return vcom_socket_epoll_ctl (__epfd, __op, __fd, __event); } -static inline int -ep_op_has_event (int op) -{ - return op != EPOLL_CTL_DEL; -} - +/* + * implement the controller interface for epoll + * that enables the insertion/removal/change of + * file descriptors inside the interest set. + */ int epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event) @@ -2732,11 +2758,6 @@ epoll_ctl (int __epfd, int __op, int __fd, int rv; pid_t pid = getpid (); - if ((ep_op_has_event (__op) && !__event)) - { - errno = EFAULT; - return -1; - } if (is_vcom_epfd (__epfd)) { /* TBD: currently limiting epoll to support only vcom fds */ @@ -2757,13 +2778,16 @@ epoll_ctl (int __epfd, int __op, int __fd, } else { - /* TBD: currently epoll does not support kernel fds */ + /* + * TBD: currently epoll does not support kernel fds + * or epoll fds */ errno = EBADF; return -1; } } else { + /* epfd is not an epoll file descriptor */ errno = EINVAL; return -1; } diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom_glibc_socket.h b/vcl-ldpreload/src/libvcl-ldpreload/vcom_glibc_socket.h index 3ca1951..026ba60 100644 --- a/vcl-ldpreload/src/libvcl-ldpreload/vcom_glibc_socket.h +++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom_glibc_socket.h @@ -291,8 +291,8 @@ extern int __THROW epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event); -#define INT_MAX ((int)(~0U>>1)) -#define EP_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event)) +#define EP_INT_MAX ((int)(~0U>>1)) +#define EP_MAX_EVENTS (EP_INT_MAX / sizeof(struct epoll_event)) /* Wait for events on an epoll instance "epfd". Returns the number of triggered events returned in "events" buffer. Or -1 in case of diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c index 42dff9b..ba8a489 100644 --- a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c +++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c @@ -46,6 +46,7 @@ typedef struct vcom_socket_main_t_ /* Hash table for epollidx to epfd mapping */ uword *epollidx_by_epfd; + /* common epitem poll for all epfd */ /* TBD: epitem poll per epfd */ /* vcom_epitem pool */ @@ -54,6 +55,11 @@ typedef struct vcom_socket_main_t_ /* Hash table for epitemidx to epfdfd mapping */ uword *epollidx_by_epfdfd; + /* Hash table - key:epfd, value:vec of epitemidx */ + uword *epitemidxs_by_epfd; + /* Hash table - key:fd, value:vec of epitemidx */ + uword *epitemidxs_by_fd; + } vcom_socket_main_t; vcom_socket_main_t vcom_socket_main; @@ -165,6 +171,10 @@ vcom_socket_main_init (void) pool_alloc (vsm->vepolls, FD_SETSIZE); vsm->epollidx_by_epfd = hash_create (0, sizeof (i32)); + pool_alloc (vsm->vepitems, FD_SETSIZE); + vsm->epitemidxs_by_epfd = hash_create (0, sizeof (uword *)); + vsm->epitemidxs_by_fd = hash_create (0, sizeof (uword *)); + vsm->init = 1; } @@ -248,6 +258,7 @@ vcom_socket_main_destroy (void) pool_free (vsm->vepolls); hash_free (vsm->epollidx_by_epfd); + vsm->init = 0; } } @@ -259,11 +270,11 @@ vcom_socket_main_show (void) vcom_socket_t *vsock; vcom_epoll_t *vepoll; + vcom_epitem_t *vepitem; if (vsm->init) { - /* from active list of vsockets, - * close socket and vppcom session */ + /* from active list of vsockets show vsock */ /* *INDENT-OFF* */ pool_foreach (vsock, vsm->vsockets, @@ -275,8 +286,7 @@ vcom_socket_main_show (void) })); /* *INDENT-ON* */ - /* from active list of vepolls, - * close epoll and vppcom session */ + /* from active list of vepolls, show vepoll */ /* *INDENT-OFF* */ pool_foreach (vepoll, vsm->vepolls, @@ -290,6 +300,23 @@ vcom_socket_main_show (void) vepoll->flags, vepoll->count, vepoll->close); })); /* *INDENT-ON* */ + + /* from active list of vepitems, show vepitem */ + + /* *INDENT-OFF* */ + pool_foreach (vepitem, vsm->vepitems, + ({ + printf( + "epfd='%04d', fd='%04d', " + "next_fd='%04d', prev_fd='%04d', " + "type='%-30s', " + "events='%04x', revents='%04x'\n", + vepitem->epfd, vepitem->fd, + vepitem->next_fd, vepitem->prev_fd, + vcom_socket_vcom_fd_type_str (vepitem->type), + vepitem->event.events, vepitem->revent.events); + })); + /* *INDENT-ON* */ } } @@ -2246,6 +2273,7 @@ vcom_socket_epoll_create1 (int __flags) vepoll_set (vepoll, epfd, vep_idx, EPOLL_TYPE_VPPCOM_BOUND, __flags, 0, 0); + return epfd; out_close_epoll: -- cgit 1.2.3-korg