[PATCH:intel-gpu-tools 3/7] Use pthread calls instead of raw syscalls on non-Linux systems

Alan Coopersmith alan.coopersmith at oracle.com
Tue Dec 23 19:07:10 PST 2014


Raw system calls aren't portable to other kernels.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 lib/igt_core.c               |   21 ++++++++++++++++-----
 tests/core_get_client_auth.c |    8 +++++++-
 tests/drm_import_export.c    |    4 ++++
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 08e0c47..3c68780 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -45,7 +45,11 @@
 #include <unistd.h>
 #include <sys/wait.h>
 #include <sys/types.h>
+#ifdef __linux__
 #include <sys/syscall.h>
+#else
+#include <pthread.h>
+#endif
 #include <sys/utsname.h>
 #include <termios.h>
 #include <errno.h>
@@ -1258,8 +1262,6 @@ static void igt_atexit_handler(void)
 
 static void fatal_sig_handler(int sig)
 {
-	pid_t pid, tid;
-
 	restore_all_sig_handler();
 
 	/*
@@ -1268,11 +1270,20 @@ static void fatal_sig_handler(int sig)
 	 */
 	call_exit_handlers(sig);
 
+	{
+#ifdef __linux__
 	/* Workaround cached PID and TID races on glibc and Bionic libc. */
-	pid = syscall(SYS_getpid);
-	tid = syscall(SYS_gettid);
+		pid_t pid = syscall(SYS_getpid);
+		pid_t tid = syscall(SYS_gettid);
 
-	syscall(SYS_tgkill, pid, tid, sig);
+		syscall(SYS_tgkill, pid, tid, sig);
+#else
+		pthread_t tid = pthread_self();
+		union sigval value = { .sival_ptr = NULL };
+
+		pthread_sigqueue(tid, sig, value);
+#endif
+        }
 }
 
 /**
diff --git a/tests/core_get_client_auth.c b/tests/core_get_client_auth.c
index eef97e0..bbfdddf 100644
--- a/tests/core_get_client_auth.c
+++ b/tests/core_get_client_auth.c
@@ -37,7 +37,11 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#ifdef __linux__
 # include <sys/syscall.h>
+#else
+# include <pthread.h>
+#endif
 
 #include "drm.h"
 #include "ioctl_wrappers.h"
@@ -47,7 +51,9 @@
 static bool
 is_local_tid(pid_t tid)
 {
-#ifndef ANDROID
+#ifndef __linux__
+	return pthread_self() == tid;
+#elif !defined(ANDROID)
 	/* On Linux systems, drmGetClient() would return the thread ID
 	   instead of the actual process ID */
 	return syscall(SYS_gettid) == tid;
diff --git a/tests/drm_import_export.c b/tests/drm_import_export.c
index 83e753b..57b13dd 100644
--- a/tests/drm_import_export.c
+++ b/tests/drm_import_export.c
@@ -121,7 +121,11 @@ static void start_test(void)
 
 static void * test_thread(void * par)
 {
+#ifdef __linux__
 	igt_debug("start %ld\n", syscall(SYS_gettid));
+#else
+	igt_debug("start %ld\n", (long) pthread_self());
+#endif
 	start_test();
 
 	return NULL;
-- 
1.7.9.2



More information about the xorg-devel mailing list