[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [torsocks/master] Fix: undefined syscall values for x86
commit 24f63e2a16efe1719560dda6ee7e4f059e34a2f4
Author: David Goulet <dgoulet@xxxxxxxxx>
Date: Sat Oct 12 13:41:50 2013 -0400
Fix: undefined syscall values for x86
Reference #11
Signed-off-by: David Goulet <dgoulet@xxxxxxxxx>
---
src/common/compat.h | 42 ++++++++++++++++++++++++++++++++++++++++++
src/lib/syscall.c | 6 +++---
src/lib/torsocks.h | 5 -----
3 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/src/common/compat.h b/src/common/compat.h
index 18404b2..07c856f 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -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 */
diff --git a/src/lib/syscall.c b/src/lib/syscall.c
index 0edd460..b06e2e3 100644
--- a/src/lib/syscall.c
+++ b/src/lib/syscall.c
@@ -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:
diff --git a/src/lib/torsocks.h b/src/lib/torsocks.h
index 1554abc..4adf532 100644
--- a/src/lib/torsocks.h
+++ b/src/lib/torsocks.h
@@ -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
@@ -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)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits