commit 53b8569f545c45a443e746695f6b1b5de64fb65a Author: Yawning Angel yawning@schwanenlied.me Date: Tue Apr 7 10:38:15 2015 +0000
Handle accept4(2) when invoked via syscall().
Signed-off-by: Yawning Angel yawning@schwanenlied.me --- src/common/compat.h | 4 ++++ src/lib/syscall.c | 21 +++++++++++++++++++++ src/lib/torsocks.h | 1 + 3 files changed, 26 insertions(+)
diff --git a/src/common/compat.h b/src/common/compat.h index 6fca641..b4bef9a 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -93,6 +93,9 @@ void tsocks_mutex_unlock(tsocks_mutex_t *m); #ifndef __NR_futex #define __NR_futex -12 #endif +#ifndef __NR_accept4 +#define __NR_accept4 -13 +#endif
#define TSOCKS_NR_SOCKET __NR_socket #define TSOCKS_NR_CONNECT __NR_connect @@ -106,6 +109,7 @@ void tsocks_mutex_unlock(tsocks_mutex_t *m); #define TSOCKS_NR_GETTID __NR_gettid #define TSOCKS_NR_GETRANDOM __NR_getrandom #define TSOCKS_NR_FUTEX __NR_futex +#define TSOCKS_NR_ACCEPT4 __NR_accept4
#endif /* __linux__ */
diff --git a/src/lib/syscall.c b/src/lib/syscall.c index 52ee4c2..5dad3ce 100644 --- a/src/lib/syscall.c +++ b/src/lib/syscall.c @@ -212,6 +212,24 @@ static LIBC_SYSCALL_RET_TYPE handle_futex(va_list args) return tsocks_libc_syscall(TSOCKS_NR_FUTEX, uaddr, op, val, timeout, uaddr2, val3); } + +/* + * Handle accept4(2) syscall. + */ +static LIBC_SYSCALL_RET_TYPE handle_accept4(va_list args) +{ + int sockfd; + struct sockaddr *addr; + socklen_t addrlen; + int flags; + + sockfd = va_arg(args, __typeof__(sockfd)); + addr = va_arg(args, __typeof__(addr)); + addrlen = va_arg(args, __typeof__(addrlen)); + flags = va_arg(args, __typeof__(flags)); + + return tsocks_accept4(sockfd, addr, &addrlen, flags); +} #endif /* __linux__ */
/* @@ -288,6 +306,9 @@ LIBC_SYSCALL_RET_TYPE tsocks_syscall(long int number, va_list args) case TSOCKS_NR_FUTEX: ret = handle_futex(args); break; + case TSOCKS_NR_ACCEPT4: + ret = handle_accept4(args); + break; #endif /* __linux__ */ default: /* diff --git a/src/lib/torsocks.h b/src/lib/torsocks.h index 3b9cda2..81073cf 100644 --- a/src/lib/torsocks.h +++ b/src/lib/torsocks.h @@ -388,6 +388,7 @@ TSOCKS_DECL(accept, LIBC_ACCEPT_RET_TYPE, LIBC_ACCEPT_SIG) /* accept4(2) */ #if (defined(__linux__)) extern TSOCKS_LIBC_DECL(accept4, LIBC_ACCEPT4_RET_TYPE, LIBC_ACCEPT4_SIG) +TSOCKS_DECL(accept4, LIBC_ACCEPT4_RET_TYPE, LIBC_ACCEPT4_SIG) #define LIBC_ACCEPT4_DECL LIBC_ACCEPT4_RET_TYPE \ LIBC_ACCEPT4_NAME(LIBC_ACCEPT4_SIG) #endif