From: Julian Seward Date: Wed, 13 Nov 2002 22:00:20 +0000 (+0000) Subject: Merge patch from JeremyF: X-Git-Tag: svn/VALGRIND_1_9_4~149 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=088086b221a598bdf6ef7c68b6ce7258ae1fbba0;p=thirdparty%2Fvalgrind.git Merge patch from JeremyF: 23-intercept-select-poll Do the intercept thing for select and poll. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1298 --- diff --git a/coregrind/arch/x86-linux/vg_libpthread.c b/coregrind/arch/x86-linux/vg_libpthread.c index 7d5a789618..600d19842f 100644 --- a/coregrind/arch/x86-linux/vg_libpthread.c +++ b/coregrind/arch/x86-linux/vg_libpthread.c @@ -2394,12 +2394,11 @@ int do_syscall_select( int n, kernel's error numbers (VKI_EINTR etc). */ -/* __attribute__((weak)) */ -int select ( int n, - fd_set *rfds, - fd_set *wfds, - fd_set *xfds, - struct timeval *timeout ) +int VGL_(select) ( int n, + fd_set *rfds, + fd_set *wfds, + fd_set *xfds, + struct timeval *timeout ) { unsigned int ms_now, ms_end; int res; @@ -2543,8 +2542,7 @@ typedef unsigned long int nfds_t; #endif -/* __attribute__((weak)) */ -int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) +int VGL_(poll) (struct pollfd *__fds, nfds_t __nfds, int __timeout) { unsigned int ms_now, ms_end; int res, i; @@ -3340,8 +3338,6 @@ strong_alias(wait, __wait) strong_alias(write, __write) strong_alias(connect, __connect) strong_alias(send, __send) -strong_alias(poll, __poll) -strong_alias(select, __select) weak_alias (__pread64, pread64) weak_alias (__pwrite64, pwrite64) diff --git a/coregrind/vg_intercept.c b/coregrind/vg_intercept.c index fd481ed605..402a17b6b4 100644 --- a/coregrind/vg_intercept.c +++ b/coregrind/vg_intercept.c @@ -117,12 +117,97 @@ int __libc_recv(int s, void *buf, size_t len, int flags); WEAK int VGL_(recv)(int s, void *buf, size_t len, int flags) { - return __libc_recv(s, buf, len, flags); + return __libc_recv(s, buf, len, flags); } int recv(int s, void *buf, size_t len, int flags) { - return VGL_(recv)(s, buf, len, flags); + return VGL_(recv)(s, buf, len, flags); } strong_alias(recv, __recv) + +/* -------------------------------- poll -------------------------------- */ + +static inline +int my_do_syscall3 ( int syscallno, + int arg1, int arg2, int arg3 ) +{ + int __res; + __asm__ volatile ("pushl %%ebx; movl %%esi,%%ebx ; int $0x80 ; popl %%ebx" + : "=a" (__res) + : "0" (syscallno), + "S" (arg1), + "c" (arg2), + "d" (arg3) ); + return __res; +} + +#include + +#ifndef HAVE_NFDS_T +typedef unsigned long int nfds_t; +#endif + + +WEAK int VGL_(poll)(struct pollfd *__fds, nfds_t __nfds, int __timeout) +{ + int res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, __timeout); + + if (is_kerror(res)) { + * (__errno_location()) = -res; + return -1; + } + return res; +} + +int poll(struct pollfd *__fds, nfds_t __nfds, int __timeout) +{ + return VGL_(poll)(__fds, __nfds, __timeout); +} + +strong_alias(poll, __poll) + + +/* -------------------------------- select -------------------------------- */ + + +static inline +int my_do_syscall1 ( int syscallno, int arg1 ) +{ + int __res; + __asm__ volatile ("pushl %%ebx; movl %%edx,%%ebx ; int $0x80 ; popl %%ebx" + : "=a" (__res) + : "0" (syscallno), + "d" (arg1) ); + return __res; +} + + +WEAK int VGL_(select)( int n, + fd_set* readfds, + fd_set* writefds, + fd_set* exceptfds, + struct timeval * timeout ) +{ + int res; + int args[5]; + args[0] = n; + args[1] = (int)readfds; + args[2] = (int)writefds; + args[3] = (int)exceptfds; + args[4] = (int)timeout; + res = my_do_syscall1(__NR_select, (int)(&(args[0])) ); + return res; +} + +int select ( int n, + fd_set *rfds, + fd_set *wfds, + fd_set *xfds, + struct timeval *timeout ) +{ + return VGL_(select)(n, rfds, wfds, xfds, timeout); +} + +strong_alias(select, __select) diff --git a/coregrind/vg_libpthread.c b/coregrind/vg_libpthread.c index 7d5a789618..600d19842f 100644 --- a/coregrind/vg_libpthread.c +++ b/coregrind/vg_libpthread.c @@ -2394,12 +2394,11 @@ int do_syscall_select( int n, kernel's error numbers (VKI_EINTR etc). */ -/* __attribute__((weak)) */ -int select ( int n, - fd_set *rfds, - fd_set *wfds, - fd_set *xfds, - struct timeval *timeout ) +int VGL_(select) ( int n, + fd_set *rfds, + fd_set *wfds, + fd_set *xfds, + struct timeval *timeout ) { unsigned int ms_now, ms_end; int res; @@ -2543,8 +2542,7 @@ typedef unsigned long int nfds_t; #endif -/* __attribute__((weak)) */ -int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) +int VGL_(poll) (struct pollfd *__fds, nfds_t __nfds, int __timeout) { unsigned int ms_now, ms_end; int res, i; @@ -3340,8 +3338,6 @@ strong_alias(wait, __wait) strong_alias(write, __write) strong_alias(connect, __connect) strong_alias(send, __send) -strong_alias(poll, __poll) -strong_alias(select, __select) weak_alias (__pread64, pread64) weak_alias (__pwrite64, pwrite64)