diff mbox

testsuite: also wrap gettid in syscall()

Message ID 20180108162708.16662-1-lucas.demarchi@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas De Marchi Jan. 8, 2018, 4:27 p.m. UTC
Not a perfect solution for overriding syscall(), but at least
it makes the testsuite to pass in a modified nsswitch.conf (one that has
a module which calls syscall() to get the thread id).
---
 testsuite/init_module.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff mbox

Patch

diff --git a/testsuite/init_module.c b/testsuite/init_module.c
index 199186b..130dd32 100644
--- a/testsuite/init_module.c
+++ b/testsuite/init_module.c
@@ -355,6 +355,22 @@  TS_EXPORT long int syscall(long int __sysno, ...)
 		return ret;
 	}
 
+	if (__sysno == __NR_gettid) {
+		static void *nextlib = NULL;
+		static long (*nextlib_syscall)(long number, ...);
+
+		if (nextlib == NULL) {
+#ifdef RTLD_NEXT
+			nextlib = RTLD_NEXT;
+#else
+			nextlib = dlopen("libc.so.6", RTLD_LAZY);
+#endif
+			nextlib_syscall = dlsym(nextlib, "syscall");
+		}
+
+		return nextlib_syscall(__NR_gettid);
+	}
+
 	/*
 	 * FIXME: no way to call the libc function due since this is a
 	 * variadic argument function and we don't have a vsyscall() variant