[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torsocks/master] Bug 23715: Support memfd_create(2).



commit dc1d6ae5639a84103a1b067775238f33b4590533
Author: Yawning Angel <yawning@xxxxxxxxxxxxxxx>
Date:   Sat Sep 30 07:09:13 2017 +0000

    Bug 23715: Support memfd_create(2).
    
    Enough things use this now, that the syscall(2) wrapper should support
    it, since glibc doesn't provide a wrapper for it, and the documentation
    says to invoke it using syscall(2).
---
 src/common/compat.h |  4 ++++
 src/lib/syscall.c   | 17 +++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/src/common/compat.h b/src/common/compat.h
index f490113..a9b73c2 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -126,6 +126,9 @@ void tsocks_once(tsocks_once_t *o, void (*init_routine)(void));
 #ifndef __NR_fork
 #define __NR_fork -18
 #endif
+#ifndef __NR_memfd_create
+#define __NR_memfd_create -19
+#endif
 
 #define TSOCKS_NR_SOCKET    __NR_socket
 #define TSOCKS_NR_CONNECT   __NR_connect
@@ -145,6 +148,7 @@ void tsocks_once(tsocks_once_t *o, void (*init_routine)(void));
 #define TSOCKS_NR_GETTIMEOFDAY __NR_gettimeofday
 #define TSOCKS_NR_CLOCK_GETTIME __NR_clock_gettime
 #define TSOCKS_NR_FORK      __NR_fork
+#define TSOCKS_NR_MEMFD_CREATE __NR_memfd_create
 
 /*
  * Despite glibc providing wrappers for these calls for a long time
diff --git a/src/lib/syscall.c b/src/lib/syscall.c
index 41cba28..7fba580 100644
--- a/src/lib/syscall.c
+++ b/src/lib/syscall.c
@@ -423,6 +423,20 @@ static LIBC_SYSCALL_RET_TYPE handle_fork(void)
 {
 	return tsocks_libc_syscall(TSOCKS_NR_FORK);
 }
+
+/*
+ * Handle memfd_create(2) syscall.
+ */
+static LIBC_SYSCALL_RET_TYPE handle_memfd_create(va_list args)
+{
+	const char *name;
+	unsigned int flags;
+
+	name = va_arg(args, __typeof__(name));
+	flags = va_arg(args, __typeof__(flags));
+
+	return tsocks_libc_syscall(TSOCKS_NR_MEMFD_CREATE, name, flags);
+}
 #endif /* __linux__ */
 
 /*
@@ -541,6 +555,9 @@ LIBC_SYSCALL_RET_TYPE tsocks_syscall(long int number, va_list args)
 	case TSOCKS_NR_FORK:
 		ret = handle_fork();
 		break;
+	case TSOCKS_NR_MEMFD_CREATE:
+		ret = handle_memfd_create(args);
+		break;
 #endif /* __linux__ */
 	default:
 		/*



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits