This diff eliminates the need to _invoke_ syscalls via their aliases with 
the '_thread_sys_' prefix, and uses that for a few syscalls that didn't 
but should have.

This is done via the REDIRECT_SYSCALL() macro which builds on the same gcc 
extensions that the libc cleanup this fall did.  Applying that to 
sigaction(), sigprocmask(), and thrkill() makes the code easier to read 
without changing the resulting generated objects.

After that, applying it to getthrid(), sysctl(), and isssetugid() keeps 
libpthread from depending on names that are in the reserved namespace.

The sched_yield() declaration in rthread.h is actually unnecessary: 
<pthread.h> pulls in <sched.h> which has the official declaration for it, 
so delete it.

check_sym report:
No dynamic export changes
External reference changes:
added:
        _thread_sys_getthrid
        _thread_sys_issetugid
        _thread_sys_sysctl

removed:
        getthrid
        issetugid
        sysctl

ok?

Philip Guenther


Index: rthread.h
===================================================================
RCS file: /data/src/openbsd/src/lib/librthread/rthread.h,v
retrieving revision 1.55
diff -u -p -r1.55 rthread.h
--- rthread.h   27 Jan 2016 08:40:05 -0000      1.55
+++ rthread.h   2 Apr 2016 05:34:27 -0000
@@ -233,15 +233,10 @@ void      _leave_delayed_cancel(pthread_t, in
 
 void   _thread_dump_info(void);
 
-/* syscalls */
+/* syscalls not declared in system headers */
+#define REDIRECT_SYSCALL(x)            typeof(x) x asm("_thread_sys_"#x)
 void   __threxit(pid_t *);
 int    __thrsleep(const volatile void *, clockid_t, const struct timespec *,
            volatile void *, const int *);
 int    __thrwakeup(const volatile void *, int n);
 int    __thrsigdivert(sigset_t, siginfo_t *, const struct timespec *);
-int    sched_yield(void);
-int    _thread_sys_sigaction(int, const struct sigaction *,
-           struct sigaction *);
-int    _thread_sys_sigprocmask(int, const sigset_t *, sigset_t *);
-int    _thread_sys_thrkill(pid_t _tid, int _signum, void *_tcb);
-
Index: rthread.c
===================================================================
RCS file: /data/src/openbsd/src/lib/librthread/rthread.c,v
retrieving revision 1.88
diff -u -p -r1.88 rthread.c
--- rthread.c   20 Mar 2016 02:30:28 -0000      1.88
+++ rthread.c   2 Apr 2016 05:35:17 -0000
@@ -47,6 +47,21 @@
 #include "rthread.h"
 #include "tcb.h"
 
+/*
+ * Call nonstandard functions via names in the reserved namespace:
+ *     NOT YET dlctl() -> _dlctl()
+ *     getthrid -> _thread_sys_getthrid
+ */
+REDIRECT_SYSCALL(getthrid);
+
+/*
+ * libc's signal wrappers hide SIGTHR; we need to call the real syscall
+ * stubs _thread_sys_* directly.
+ */
+REDIRECT_SYSCALL(sigaction);
+REDIRECT_SYSCALL(sigprocmask);
+REDIRECT_SYSCALL(thrkill);
+
 static int concurrency_level;  /* not used */
 
 struct _spinlock _SPINLOCK_UNLOCKED_ASSIGN = _SPINLOCK_UNLOCKED;
@@ -207,9 +222,9 @@ _rthread_init(void)
        memset(&sa, 0, sizeof(sa));
        sigemptyset(&sa.sa_mask);
        sa.sa_handler = sigthr_handler;
-       _thread_sys_sigaction(SIGTHR, &sa, NULL);
+       sigaction(SIGTHR, &sa, NULL);
        sigaddset(&sa.sa_mask, SIGTHR);
-       _thread_sys_sigprocmask(SIG_UNBLOCK, &sa.sa_mask, NULL);
+       sigprocmask(SIG_UNBLOCK, &sa.sa_mask, NULL);
 
        return (0);
 }
@@ -463,7 +478,7 @@ pthread_kill(pthread_t thread, int sig)
 {
        if (sig == SIGTHR)
                return (EINVAL);
-       if (_thread_sys_thrkill(thread->tid, sig, thread->tcb))
+       if (thrkill(thread->tid, sig, thread->tcb))
                return (errno);
        return (0);
 }
@@ -487,7 +502,7 @@ pthread_cancel(pthread_t thread)
 
                if (thread->flags & THREAD_CANCEL_ENABLE) {
                        _spinunlock(&thread->flags_lock);
-                       _thread_sys_thrkill(tid, SIGTHR, thread->tcb);
+                       thrkill(tid, SIGTHR, thread->tcb);
                        return (0);
                }
        }
Index: rthread_debug.c
===================================================================
RCS file: /data/src/openbsd/src/lib/librthread/rthread_debug.c,v
retrieving revision 1.3
diff -u -p -r1.3 rthread_debug.c
--- rthread_debug.c     13 Mar 2012 05:51:30 -0000      1.3
+++ rthread_debug.c     31 Mar 2016 23:23:42 -0000
@@ -11,6 +11,8 @@
 
 #include "rthread.h"
 
+REDIRECT_SYSCALL(issetugid);
+
 int _rthread_debug_level;
 
 /*
Index: rthread_fork.c
===================================================================
RCS file: /data/src/openbsd/src/lib/librthread/rthread_fork.c,v
retrieving revision 1.15
diff -u -p -r1.15 rthread_fork.c
--- rthread_fork.c      27 Jan 2016 08:40:05 -0000      1.15
+++ rthread_fork.c      2 Apr 2016 05:35:50 -0000
@@ -45,6 +45,8 @@
 
 #include "rthread.h"
 
+REDIRECT_SYSCALL(getthrid);
+
 pid_t   _thread_sys_fork(void);
 pid_t   _thread_sys_vfork(void);
 pid_t  _dofork(int);
Index: rthread_np.c
===================================================================
RCS file: /data/src/openbsd/src/lib/librthread/rthread_np.c,v
retrieving revision 1.17
diff -u -p -r1.17 rthread_np.c
--- rthread_np.c        24 Jan 2015 10:35:33 -0000      1.17
+++ rthread_np.c        31 Mar 2016 23:00:23 -0000
@@ -36,6 +36,8 @@
 
 #include "rthread.h"
 
+REDIRECT_SYSCALL(sysctl);
+
 void
 pthread_set_name_np(pthread_t thread, const char *name)
 {

Reply via email to