Skip to content

Commit

Permalink
Fix: undefined syscall values for x86
Browse files Browse the repository at this point in the history
Reference #11

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
  • Loading branch information
dgoulet committed Oct 24, 2013
1 parent 729ca3f commit 24f63e2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
42 changes: 42 additions & 0 deletions src/common/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,46 @@ void tsocks_mutex_unlock(tsocks_mutex_t *m);

#endif /* __linux__, __darwin__, __FreeBSD__ */

#if defined(__linux__)

#if defined(__i386)
#include <asm-generic/unistd.h>
#else
#include <unistd.h>
#endif /* defined __i386 */

#include <sys/syscall.h>

/*
* Some old system requires kernel headers for those values. If they are not
* defined, set them to a non syscall value. Just to be clear, if the value is
* undefined (here -1), tsocks syscall() will DENY the real syscall if catched.
*/
#ifndef __NR_socket
#define __NR_socket -1
#endif
#ifndef __NR_connect
#define __NR_connect -1
#endif
#ifndef __NR_close
#define __NR_close -1
#endif

#define TSOCKS_NR_SOCKET __NR_socket
#define TSOCKS_NR_CONNECT __NR_connect
#define TSOCKS_NR_CLOSE __NR_close

#endif /* __linux__ */

#if (defined(__FreeBSD__) || defined(__darwin__))

#include <sys/syscall.h>
#include <unistd.h>

#define TSOCKS_NR_SOCKET SYS_socket
#define TSOCKS_NR_CONNECT SYS_connect
#define TSOCKS_NR_CLOSE SYS_close

#endif /* __FreeBSD__, __darwin__ */

#endif /* TORSOCKS_COMPAT_H */
6 changes: 3 additions & 3 deletions src/lib/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ LIBC_SYSCALL_RET_TYPE tsocks_syscall(long int __number, va_list args)
DBG("[syscall] Syscall libc wrapper number %ld called", __number);

switch (__number) {
case SYS_socket:
case TSOCKS_NR_SOCKET:
ret = handle_socket(args);
break;
case SYS_connect:
case TSOCKS_NR_CONNECT:
ret = handle_connect(args);
break;
case SYS_close:
case TSOCKS_NR_CLOSE:
ret = handle_close(args);
break;
default:
Expand Down
5 changes: 0 additions & 5 deletions src/lib/torsocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ struct hostent **__result, int *__h_errnop
#if (defined(__linux__))

#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>

/* syscall(2) */
#define LIBC_SYSCALL_NAME syscall
Expand All @@ -190,9 +188,6 @@ struct hostent **__result, int *__h_errnop

#if (defined(__FreeBSD__) || defined(__darwin__))

#include <sys/syscall.h>
#include <unistd.h>

/* syscall(2) */
#define LIBC_SYSCALL_NAME syscall
#define LIBC_SYSCALL_NAME_STR XSTR(LIBC_SYSCALL_NAME)
Expand Down

0 comments on commit 24f63e2

Please sign in to comment.