[Glibc-bsd-commits] r4611 - trunk/glibc-ports/kfreebsd/fbtl
Petr Salinger
ps-guest at alioth.debian.org
Mon Jul 8 12:47:26 UTC 2013
Author: ps-guest
Date: 2013-06-25 16:59:18 +0000 (Tue, 25 Jun 2013)
New Revision: 4611
Modified:
trunk/glibc-ports/kfreebsd/fbtl/Makefile
trunk/glibc-ports/kfreebsd/fbtl/fork.c
trunk/glibc-ports/kfreebsd/fbtl/pt-raise.c
trunk/glibc-ports/kfreebsd/fbtl/pthread_kill.c
trunk/glibc-ports/kfreebsd/fbtl/raise.c
Log:
tid fixes
Modified: trunk/glibc-ports/kfreebsd/fbtl/Makefile
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/Makefile 2013-06-25 16:56:56 UTC (rev 4610)
+++ trunk/glibc-ports/kfreebsd/fbtl/Makefile 2013-06-25 16:59:18 UTC (rev 4611)
@@ -33,6 +33,7 @@
endif
ifeq ($(subdir),fbtl)
+routines += sys_thr_kill sys_thr_self
libpthread-routines += ptw-sys_sigprocmask ptw-sys_umtx
libpthread-routines += ptw-sys_thr_kill
libpthread-routines += ptw-sys_thr_kill2
Modified: trunk/glibc-ports/kfreebsd/fbtl/fork.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/fork.c 2013-06-25 16:56:56 UTC (rev 4610)
+++ trunk/glibc-ports/kfreebsd/fbtl/fork.c 2013-06-25 16:59:18 UTC (rev 4611)
@@ -143,8 +143,8 @@
#else
{
int val = __getpid();
+ INLINE_SYSCALL(thr_self, 1, &(self->ktid));
THREAD_SETMEM (self, pid, val);
- INLINE_SYSCALL(thr_self, 1, &(self->ktid));
# warning fetch both getpid() and ktid via SYS_thr_self
}
@@ -154,7 +154,9 @@
*__fork_generation_pointer += 4;
/* Adjust the PID field for the new process. */
+#if 0
THREAD_SETMEM (self, pid, THREAD_GETMEM (self, tid));
+#endif
#if HP_TIMING_AVAIL
/* The CPU clock of the thread and process have to be set to zero. */
Modified: trunk/glibc-ports/kfreebsd/fbtl/pt-raise.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/pt-raise.c 2013-06-25 16:56:56 UTC (rev 4610)
+++ trunk/glibc-ports/kfreebsd/fbtl/pt-raise.c 2013-06-25 16:59:18 UTC (rev 4611)
@@ -31,12 +31,22 @@
fork function temporarily invalidated the PID field. Adjust for
that. */
- return INLINE_SYSCALL(thr_kill, 2, THREAD_GETMEM (THREAD_SELF, tid), sig);
-
-#warning TODO all
-#if 0
+#if 1
+#warning TODO recheck
+ long ktid;
pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
if (__builtin_expect (pid < 0, 0))
+ {
+ /* This system call is not supposed to fail. */
+ INLINE_SYSCALL(thr_self, 1, &ktid);
+ }
+ else
+ ktid = THREAD_GETMEM (THREAD_SELF, tid);
+
+ return INLINE_SYSCALL(thr_kill, 2, ktid, sig);
+#else
+ pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
+ if (__builtin_expect (pid < 0, 0))
pid = -pid;
return INLINE_SYSCALL (tgkill, 3, pid, THREAD_GETMEM (THREAD_SELF, tid),
Modified: trunk/glibc-ports/kfreebsd/fbtl/pthread_kill.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/pthread_kill.c 2013-06-25 16:56:56 UTC (rev 4610)
+++ trunk/glibc-ports/kfreebsd/fbtl/pthread_kill.c 2013-06-25 16:59:18 UTC (rev 4611)
@@ -40,7 +40,7 @@
if a thread exits between ESRCH test and tgkill, we might return
EINVAL, because pd->tid would be cleared by the kernel. */
pid_t tid = atomic_forced_read (pd->tid);
- if (__builtin_expect (tid <= 0, 0))
+ if (__builtin_expect (tid <= KTID_TERMINATED, 0))
/* Not a valid thread handle. */
return ESRCH;
@@ -49,23 +49,21 @@
if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID)
return EINVAL;
- return INLINE_SYSCALL(thr_kill, 2, tid, signo);
-#warning kill needed
-#if 0
/* We have a special syscall to do the work. */
- INTERNAL_SYSCALL_DECL (err);
/* One comment: The PID field in the TCB can temporarily be changed
(in fork). But this must not affect this code here. Since this
function would have to be called while the thread is executing
fork, it would have to happen in a signal handler. But this is
no allowed, pthread_kill is not guaranteed to be async-safe. */
- int val;
- val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
- tid, signo);
+
+ /* the KTID field in the TCB can be wrong under FreeBSD
+ a) before __pthread_initialize_minimal is finished (with libpthread)
+ b) in child just after fork
+ c) in single threaded program (no libpthread at all)
- return (INTERNAL_SYSCALL_ERROR_P (val, err)
- ? INTERNAL_SYSCALL_ERRNO (val, err) : 0);
-#endif
+ In these situations no other thread can exist.
+ */
+ return INLINE_SYSCALL(thr_kill, 2, tid, signo);
}
strong_alias (__pthread_kill, pthread_kill)
Modified: trunk/glibc-ports/kfreebsd/fbtl/raise.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/raise.c 2013-06-25 16:56:56 UTC (rev 4610)
+++ trunk/glibc-ports/kfreebsd/fbtl/raise.c 2013-06-25 16:59:18 UTC (rev 4611)
@@ -29,8 +29,18 @@
int sig;
{
#if 1
-#warning TODO
- return __kill(__getpid(),sig);
+#warning TODO recheck
+ long ktid;
+ pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
+ if (__builtin_expect (pid <= 0, 0)) /* zero is before __pthread_initialize_minimal, i.e. also no libpthread at all */
+ {
+ /* This system call is not supposed to fail. */
+ INLINE_SYSCALL(thr_self, 1, &ktid);
+ }
+ else
+ ktid = THREAD_GETMEM (THREAD_SELF, tid);
+
+ return INLINE_SYSCALL(thr_kill, 2, ktid, sig);
#else
struct pthread *pd = THREAD_SELF;
pid_t pid = THREAD_GETMEM (pd, pid);
More information about the Glibc-bsd-commits
mailing list