[Glibc-bsd-commits] r6167 - in trunk/glibc-ports-2.25: fbtl fbtl/sysdeps/i386 fbtl/sysdeps/pthread fbtl/sysdeps/x86_64 fbtl_db kfreebsd/fbtl kfreebsd/i386 kfreebsd/i386/fbtl kfreebsd/x86_64 kfreebsd/x86_64/fbtl

aurel32 at alioth.debian.org aurel32 at alioth.debian.org
Fri Aug 4 19:16:18 UTC 2017


Author: aurel32
Date: 2017-08-04 19:16:18 +0000 (Fri, 04 Aug 2017)
New Revision: 6167

Added:
   trunk/glibc-ports-2.25/kfreebsd/i386/pt-vfork.S
   trunk/glibc-ports-2.25/kfreebsd/x86_64/pt-vfork.S
Removed:
   trunk/glibc-ports-2.25/kfreebsd/i386/fbtl/pt-vfork.S
   trunk/glibc-ports-2.25/kfreebsd/i386/fbtl/vfork.S
   trunk/glibc-ports-2.25/kfreebsd/x86_64/fbtl/pt-vfork.S
   trunk/glibc-ports-2.25/kfreebsd/x86_64/fbtl/vfork.S
Modified:
   trunk/glibc-ports-2.25/fbtl/allocatestack.c
   trunk/glibc-ports-2.25/fbtl/descr.h
   trunk/glibc-ports-2.25/fbtl/nptl-init.c
   trunk/glibc-ports-2.25/fbtl/pthread_cancel.c
   trunk/glibc-ports-2.25/fbtl/pthread_getattr_np.c
   trunk/glibc-ports-2.25/fbtl/sysdeps/i386/tcb-offsets.sym
   trunk/glibc-ports-2.25/fbtl/sysdeps/pthread/malloc-machine.h
   trunk/glibc-ports-2.25/fbtl/sysdeps/x86_64/tcb-offsets.sym
   trunk/glibc-ports-2.25/fbtl_db/structs.def
   trunk/glibc-ports-2.25/fbtl_db/td_ta_thr_iter.c
   trunk/glibc-ports-2.25/fbtl_db/td_thr_validate.c
   trunk/glibc-ports-2.25/kfreebsd/fbtl/fork.c
   trunk/glibc-ports-2.25/kfreebsd/fbtl/libc_pthread_init.c
   trunk/glibc-ports-2.25/kfreebsd/fbtl/pt-raise.c
   trunk/glibc-ports-2.25/kfreebsd/fbtl/pthread_kill.c
   trunk/glibc-ports-2.25/kfreebsd/fbtl/raise.c
   trunk/glibc-ports-2.25/kfreebsd/fbtl/register-atfork.c
   trunk/glibc-ports-2.25/kfreebsd/i386/vfork.S
   trunk/glibc-ports-2.25/kfreebsd/x86_64/vfork.S
Log:
Remove cached PID/TID in clone

mostly upstream commit c579f48edba88380635ab98cb612030e3ed8691e



Modified: trunk/glibc-ports-2.25/fbtl/allocatestack.c
===================================================================
--- trunk/glibc-ports-2.25/fbtl/allocatestack.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl/allocatestack.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -442,9 +442,6 @@
       THREAD_SYSINFO(pd) = THREAD_SELF_SYSINFO;
 #endif
 
-      /* The process ID is also the same as that of the caller.  */
-      pd->pid = THREAD_GETMEM (THREAD_SELF, pid);
-
       /* Don't allow setxid until cloned.  */
       pd->setxid_futex = -1;
 
@@ -582,9 +579,6 @@
 	  /* Don't allow setxid until cloned.  */
 	  pd->setxid_futex = -1;
 
-	  /* The process ID is also the same as that of the caller.  */
-	  pd->pid = THREAD_GETMEM (THREAD_SELF, pid);
-
 	  /* Allocate the DTV for this thread.  */
 	  if (_dl_allocate_tls (TLS_TPADJ (pd)) == NULL)
 	    {
@@ -878,9 +872,6 @@
 	  /* This marks the stack as free.  */
 	  curp->tid = 0;
 
-	  /* The PID field must be initialized for the new process.  */
-	  curp->pid = self->pid;
-
 	  /* Account for the size of the stack.  */
 	  stack_cache_actsize += curp->stackblock_size;
 
@@ -906,13 +897,6 @@
 	}
     }
 
-  /* Reset the PIDs in any cached stacks.  */
-  list_for_each (runp, &stack_cache)
-    {
-      struct pthread *curp = list_entry (runp, struct pthread, list);
-      curp->pid = self->pid;
-    }
-
   /* Add the stack of all running threads to the cache.  */
   list_splice (&stack_used, &stack_cache);
 
@@ -1058,9 +1042,9 @@
 #warning setxid fixup needed
 #if 0
   int val;
+  pid_t pid = __getpid ();
   INTERNAL_SYSCALL_DECL (err);
-  val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
-			  t->tid, SIGSETXID);
+  val = INTERNAL_SYSCALL (tgkill, err, pid, t->tid, SIGSETXID);
 
   /* If this failed, it must have had not started yet or else exited.  */
   if (!INTERNAL_SYSCALL_ERROR_P (val, err))

Modified: trunk/glibc-ports-2.25/fbtl/descr.h
===================================================================
--- trunk/glibc-ports-2.25/fbtl/descr.h	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl/descr.h	2017-08-04 19:16:18 UTC (rev 6167)
@@ -182,7 +182,7 @@
 #endif  
 
   /* Process ID - thread group ID in kernel speak.  */
-  pid_t pid;
+  pid_t pid_unused;
 
   /* List of robust mutexes the thread is holding.  */
 #ifdef __PTHREAD_MUTEX_HAVE_PREV

Modified: trunk/glibc-ports-2.25/fbtl/nptl-init.c
===================================================================
--- trunk/glibc-ports-2.25/fbtl/nptl-init.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl/nptl-init.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -175,18 +175,12 @@
 static void
 sigcancel_handler (int sig, siginfo_t *si, void *ctx)
 {
-  /* Determine the process ID.  It might be negative if the thread is
-     in the middle of a fork() call.  */
-  pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
-  if (__glibc_unlikely (pid < 0))
-    pid = -pid;
-
   /* Safety check.  It would be possible to call this function for
      other signals and send a signal from another process.  This is not
      correct and might even be a security problem.  Try to catch as
      many incorrect invocations as possible.  */     
   if (sig != SIGCANCEL
-      || si->si_pid != pid
+      || si->si_pid != __getpid()
 #if 1
    )
 #else         
@@ -236,12 +230,6 @@
 static void
 sighandler_setxid (int sig, siginfo_t *si, void *ctx)
 {
-  /* Determine the process ID.  It might be negative if the thread is
-     in the middle of a fork() call.  */
-  pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
-  if (__glibc_unlikely (pid < 0))
-    pid = -pid;
-
 #if 0
   /* Safety check.  It would be possible to call this function for
      other signals and send a signal from another process.  This is not
@@ -290,10 +278,9 @@
   struct pthread *pd = THREAD_SELF;
 #if 1  
   INLINE_SYSCALL(thr_self, 1, &(pd->ktid)); 
-  pd->pid = __getpid();
 #else
   INTERNAL_SYSCALL_DECL (err);
-  pd->pid = pd->tid = INTERNAL_SYSCALL (set_tid_address, err, 1, &pd->tid);
+  pd->tid = INTERNAL_SYSCALL (set_tid_address, err, 1, &pd->tid);
 #endif 
   THREAD_SETMEM (pd, specific[0], &pd->specific_1stblock[0]);
   THREAD_SETMEM (pd, user_stack, true);

Modified: trunk/glibc-ports-2.25/fbtl/pthread_cancel.c
===================================================================
--- trunk/glibc-ports-2.25/fbtl/pthread_cancel.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl/pthread_cancel.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -65,24 +65,17 @@
 
 	  /* The cancellation handler will take care of marking the
 	     thread as canceled.  */
-	  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_cancel
-	     is not guaranteed to be async-safe.  */
-	  int val;
 #warning TODO recheck
 #if 1
           result = INLINE_SYSCALL(thr_kill, 2, pd->tid, SIGCANCEL);
           
-#else 
-	  val = INTERNAL_SYSCALL (tgkill, err, 3,
-				  THREAD_GETMEM (THREAD_SELF, pid), pd->tid,
-				  SIGCANCEL);
+#else
+	  pid_t pid = getpid ();
 
+	  INTERNAL_SYSCALL_DECL (err);
+	  int val = INTERNAL_SYSCALL_CALL (tgkill, err, pid, pd->tid,
+					   SIGCANCEL);
+
 	  if (INTERNAL_SYSCALL_ERROR_P (val, err))
 	    result = INTERNAL_SYSCALL_ERRNO (val, err);
 #endif

Modified: trunk/glibc-ports-2.25/fbtl/pthread_getattr_np.c
===================================================================
--- trunk/glibc-ports-2.25/fbtl/pthread_getattr_np.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl/pthread_getattr_np.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -64,9 +64,7 @@
     {
       /* No stack information available.  This must be for the initial
 	 thread.  Get the info in some magical way.  */
-#ifdef __linux__
-      assert (abs (thread->pid) == thread->tid);
-#endif
+
       /* Stack size limit.  */
       struct rlimit rl;
 

Modified: trunk/glibc-ports-2.25/fbtl/sysdeps/i386/tcb-offsets.sym
===================================================================
--- trunk/glibc-ports-2.25/fbtl/sysdeps/i386/tcb-offsets.sym	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl/sysdeps/i386/tcb-offsets.sym	2017-08-04 19:16:18 UTC (rev 6167)
@@ -3,7 +3,6 @@
 
 RESULT			offsetof (struct pthread, result)
 TID			offsetof (struct pthread, tid)
-PID			offsetof (struct pthread, pid)
 CANCELHANDLING		offsetof (struct pthread, cancelhandling)
 CLEANUP_JMP_BUF		offsetof (struct pthread, cleanup_jmp_buf)
 MULTIPLE_THREADS_OFFSET	offsetof (tcbhead_t, multiple_threads)

Modified: trunk/glibc-ports-2.25/fbtl/sysdeps/pthread/malloc-machine.h
===================================================================
--- trunk/glibc-ports-2.25/fbtl/sysdeps/pthread/malloc-machine.h	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl/sysdeps/pthread/malloc-machine.h	2017-08-04 19:16:18 UTC (rev 6167)
@@ -20,43 +20,9 @@
 #ifndef _MALLOC_MACHINE_H
 #define _MALLOC_MACHINE_H
 
-#undef thread_atfork_static
-
 #include <atomic.h>
 #include <libc-lock.h>
 
-__libc_lock_define (typedef, mutex_t)
-
-#define mutex_init(m)		__libc_lock_init (*(m))
-#define mutex_lock(m)		__libc_lock_lock (*(m))
-#define mutex_trylock(m)	__libc_lock_trylock (*(m))
-#define mutex_unlock(m)		__libc_lock_unlock (*(m))
-
-/* This is defined by newer gcc version unique for each module.  */
-extern void *__dso_handle __attribute__ ((__weak__));
-
-#include <fork.h>
-
-#define ATFORK_MEM static struct fork_handler atfork_mem
-
-#ifdef SHARED
-# define thread_atfork(prepare, parent, child) \
-  atfork_mem.prepare_handler = prepare;					      \
-  atfork_mem.parent_handler = parent;					      \
-  atfork_mem.child_handler = child;					      \
-  atfork_mem.dso_handle = __dso_handle;					      \
-  atfork_mem.refcntr = 1;						      \
-  __linkin_atfork (&atfork_mem)
-#else
-# define thread_atfork(prepare, parent, child) \
-  atfork_mem.prepare_handler = prepare;					      \
-  atfork_mem.parent_handler = parent;					      \
-  atfork_mem.child_handler = child;					      \
-  atfork_mem.dso_handle = &__dso_handle == NULL ? NULL : __dso_handle;	      \
-  atfork_mem.refcntr = 1;						      \
-  __linkin_atfork (&atfork_mem)
-#endif
-
 #include <sysdeps/generic/malloc-machine.h>
 
 #endif /* !defined(_MALLOC_MACHINE_H) */

Modified: trunk/glibc-ports-2.25/fbtl/sysdeps/x86_64/tcb-offsets.sym
===================================================================
--- trunk/glibc-ports-2.25/fbtl/sysdeps/x86_64/tcb-offsets.sym	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl/sysdeps/x86_64/tcb-offsets.sym	2017-08-04 19:16:18 UTC (rev 6167)
@@ -3,7 +3,6 @@
 
 RESULT			offsetof (struct pthread, result)
 TID			offsetof (struct pthread, tid)
-PID			offsetof (struct pthread, pid)
 CANCELHANDLING		offsetof (struct pthread, cancelhandling)
 CLEANUP_JMP_BUF		offsetof (struct pthread, cleanup_jmp_buf)
 CLEANUP			offsetof (struct pthread, cleanup)

Modified: trunk/glibc-ports-2.25/fbtl_db/structs.def
===================================================================
--- trunk/glibc-ports-2.25/fbtl_db/structs.def	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl_db/structs.def	2017-08-04 19:16:18 UTC (rev 6167)
@@ -48,7 +48,6 @@
 DB_STRUCT_FIELD (pthread, list)
 DB_STRUCT_FIELD (pthread, report_events)
 DB_STRUCT_FIELD (pthread, tid)
-DB_STRUCT_FIELD (pthread, pid)
 DB_STRUCT_FIELD (pthread, start_routine)
 DB_STRUCT_FIELD (pthread, cancelhandling)
 DB_STRUCT_FIELD (pthread, schedpolicy)

Modified: trunk/glibc-ports-2.25/fbtl_db/td_ta_thr_iter.c
===================================================================
--- trunk/glibc-ports-2.25/fbtl_db/td_ta_thr_iter.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl_db/td_ta_thr_iter.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -76,48 +76,28 @@
       if (ps_pdread (ta->ph, addr, copy, ta->ta_sizeof_pthread) != PS_OK)
 	return TD_ERR;
 
-      /* Verify that this thread's pid field matches the child PID.
-	 If its pid field is negative, it's about to do a fork or it
-	 is the sole thread in a fork child.  */
-      psaddr_t pid;
-      err = DB_GET_FIELD_LOCAL (pid, ta, copy, pthread, pid, 0);
-      if (err == TD_OK && (pid_t) (uintptr_t) pid < 0)
-	{
-	  if (-(pid_t) (uintptr_t) pid == match_pid)
-	    /* It is about to do a fork, but is really still the parent PID.  */
-	    pid = (psaddr_t) (uintptr_t) match_pid;
-	  else
-	    /* It must be a fork child, whose new PID is in the tid field.  */
-	    err = DB_GET_FIELD_LOCAL (pid, ta, copy, pthread, tid, 0);
-	}
+      err = DB_GET_FIELD_LOCAL (schedpolicy, ta, copy, pthread,
+				schedpolicy, 0);
       if (err != TD_OK)
 	break;
+      err = DB_GET_FIELD_LOCAL (schedprio, ta, copy, pthread,
+				schedparam_sched_priority, 0);
+      if (err != TD_OK)
+	break;
 
-      if ((pid_t) (uintptr_t) pid == match_pid)
-	{
-	  err = DB_GET_FIELD_LOCAL (schedpolicy, ta, copy, pthread,
-				    schedpolicy, 0);
-	  if (err != TD_OK)
-	    break;
-	  err = DB_GET_FIELD_LOCAL (schedprio, ta, copy, pthread,
-				    schedparam_sched_priority, 0);
-	  if (err != TD_OK)
-	    break;
+      /* Now test whether this thread matches the specified conditions.  */
 
-	  /* Now test whether this thread matches the specified conditions.  */
-
-	  /* Only if the priority level is as high or higher.  */
-	  int descr_pri = ((uintptr_t) schedpolicy == SCHED_OTHER
-			   ? 0 : (uintptr_t) schedprio);
-	  if (descr_pri >= ti_pri)
-	    {
-	      /* Yep, it matches.  Call the callback function.  */
-	      td_thrhandle_t th;
-	      th.th_ta_p = (td_thragent_t *) ta;
-	      th.th_unique = addr;
-	      if (callback (&th, cbdata_p) != 0)
-		return TD_DBERR;
-	    }
+      /* Only if the priority level is as high or higher.  */
+      int descr_pri = ((uintptr_t) schedpolicy == SCHED_OTHER
+		       ? 0 : (uintptr_t) schedprio);
+      if (descr_pri >= ti_pri)
+	{
+	  /* Yep, it matches.  Call the callback function.  */
+	  td_thrhandle_t th;
+	  th.th_ta_p = (td_thragent_t *) ta;
+	  th.th_unique = addr;
+	  if (callback (&th, cbdata_p) != 0)
+	    return TD_DBERR;
 	}
 
       /* Get the pointer to the next element.  */

Modified: trunk/glibc-ports-2.25/fbtl_db/td_thr_validate.c
===================================================================
--- trunk/glibc-ports-2.25/fbtl_db/td_thr_validate.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/fbtl_db/td_thr_validate.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -80,28 +80,5 @@
 	err = TD_OK;
     }
 
-  if (err == TD_OK)
-    {
-      /* Verify that this is not a stale element in a fork child.  */
-      pid_t match_pid = ps_getpid (th->th_ta_p->ph);
-      psaddr_t pid;
-      err = DB_GET_FIELD (pid, th->th_ta_p, th->th_unique, pthread, pid, 0);
-      if (err == TD_OK && (pid_t) (uintptr_t) pid < 0)
-	{
-	  /* This was a thread that was about to fork, or it is the new sole
-	     thread in a fork child.  In the latter case, its tid was stored
-	     via CLONE_CHILD_SETTID and so is already the proper child PID.  */
-	  if (-(pid_t) (uintptr_t) pid == match_pid)
-	    /* It is about to do a fork, but is really still the parent PID.  */
-	    pid = (psaddr_t) (uintptr_t) match_pid;
-	  else
-	    /* It must be a fork child, whose new PID is in the tid field.  */
-	    err = DB_GET_FIELD (pid, th->th_ta_p, th->th_unique,
-				pthread, tid, 0);
-	}
-      if (err == TD_OK && (pid_t) (uintptr_t) pid != match_pid)
-	err = TD_NOTHR;
-    }
-
   return err;
 }

Modified: trunk/glibc-ports-2.25/kfreebsd/fbtl/fork.c
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/fbtl/fork.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/fbtl/fork.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -29,16 +29,9 @@
 #include <stdio-lock.h>
 #include <atomic.h>
 #include <pthreadP.h>
+#include <malloc/malloc-internal.h>
 
 
-unsigned long int *__fork_generation_pointer;
-
-
-
-/* The single linked list of all currently registered fork handlers.  */
-struct fork_handler *__fork_handlers;
-
-
 static void
 fresetlockfiles (void)
 {
@@ -59,6 +52,12 @@
     struct used_handler *next;
   } *allp = NULL;
 
+  /* Determine if we are running multiple threads.  We skip some fork
+     handlers in the single-thread case, to make fork safer to use in
+     signal handlers.  POSIX requires that fork is async-signal-safe,
+     but our current fork implementation is not.  */
+  bool multiple_threads = THREAD_GETMEM (THREAD_SELF, header.multiple_threads);
+
   /* Run all the registered preparation handlers.  In reverse order.
      While doing this we build up a list of all the entries.  */
   struct fork_handler *runp;
@@ -114,18 +113,22 @@
       break;
     }
 
-  _IO_list_lock ();
+  /* If we are not running multiple threads, we do not have to
+     preserve lock state.  If fork runs from a signal handler, only
+     async-signal-safe functions can be used in the child.  These data
+     structures are only used by unsafe functions, so their state does
+     not matter if fork was called from a signal handler.  */
+  if (multiple_threads)
+    {
+      _IO_list_lock ();
 
-#ifndef NDEBUG
-  pid_t ppid = THREAD_GETMEM (THREAD_SELF, tid);
-#endif
+      /* Acquire malloc locks.  This needs to come last because fork
+	 handlers may use malloc, and the libio list lock has an
+	 indirect malloc dependency as well (via the getdelim
+	 function).  */
+      call_function_static_weak (__malloc_fork_lock_parent);
+    }
 
-  /* We need to prevent the getpid() code to update the PID field so
-     that, if a signal arrives in the child very early and the signal
-     handler uses getpid(), the value returned is correct.  */
-  pid_t parentpid = THREAD_GETMEM (THREAD_SELF, pid);
-  THREAD_SETMEM (THREAD_SELF, pid, -parentpid);
-
 #ifdef ARCH_FORK
   pid = ARCH_FORK ();
 #else
@@ -138,26 +141,11 @@
     {
       struct pthread *self = THREAD_SELF;
 
-#if 0
-      assert (THREAD_GETMEM (self, tid) != ppid);
-#else
-      { 
-         int val = __getpid();
-         INLINE_SYSCALL(thr_self, 1, &(self->ktid));
-         THREAD_SETMEM (self, pid, val);
-                 
-# warning fetch both getpid() and ktid via SYS_thr_self
-      }   
-#endif      
+      INLINE_SYSCALL(thr_self, 1, &(self->ktid));
 
       if (__fork_generation_pointer != NULL)
 	*__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.  */
       hp_timing_t now;
@@ -166,12 +154,19 @@
       GL(dl_cpuclock_offset) = now;
 #endif
 
-      /* Reset the file list.  These are recursive mutexes.  */
-      fresetlockfiles ();
+      /* Reset the lock state in the multi-threaded case.  */
+      if (multiple_threads)
+	{
+	  /* Release malloc locks.  */
+	  call_function_static_weak (__malloc_fork_unlock_child);
 
-      /* Reset locks in the I/O code.  */
-      _IO_list_resetlock ();
+	  /* Reset the file list.  These are recursive mutexes.  */
+	  fresetlockfiles ();
 
+	  /* Reset locks in the I/O code.  */
+	  _IO_list_resetlock ();
+	}
+
       /* Reset the lock the dynamic loader uses to protect its data.  */
       __rtld_lock_initialize (GL(dl_load_lock));
 
@@ -202,14 +197,16 @@
     }
   else
     {
-      assert (THREAD_GETMEM (THREAD_SELF, tid) == ppid);
+      /* Release acquired locks in the multi-threaded case.  */
+      if (multiple_threads)
+	{
+	  /* Release malloc locks, parent process variant.  */
+	  call_function_static_weak (__malloc_fork_unlock_parent);
 
-      /* Restore the PID value.  */
-      THREAD_SETMEM (THREAD_SELF, pid, parentpid);
+	  /* We execute this even if the 'fork' call failed.  */
+	  _IO_list_unlock ();
+	}
 
-      /* We execute this even if the 'fork' call failed.  */
-      _IO_list_unlock ();
-
       /* Run the handlers registered for the parent.  */
       while (allp != NULL)
 	{

Modified: trunk/glibc-ports-2.25/kfreebsd/fbtl/libc_pthread_init.c
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/fbtl/libc_pthread_init.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/fbtl/libc_pthread_init.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -28,6 +28,9 @@
 #include <ldsodefs.h>
 
 
+unsigned long int *__fork_generation_pointer;
+
+
 #ifdef TLS_MULTIPLE_THREADS_IN_TCB
 void
 #else

Modified: trunk/glibc-ports-2.25/kfreebsd/fbtl/pt-raise.c
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/fbtl/pt-raise.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/fbtl/pt-raise.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -1,54 +1 @@
-/* Copyright (C) 2002-2013 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper at redhat.com>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <signal.h>
-#include <sysdep.h>
-#include <tls.h>
-#include <kernel-features.h>
-
-
-int
-raise (int sig)
-{
-  /* raise is an async-safe function.  It could be called while the
-     fork function temporarily invalidated the PID field.  Adjust for
-     that.  */
-     
-#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),
-			 sig);
-#endif
-}
+#include <sysdeps/unix/bsd/bsd4.4/kfreebsd/fbtl/raise.c>

Modified: trunk/glibc-ports-2.25/kfreebsd/fbtl/pthread_kill.c
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/fbtl/pthread_kill.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/fbtl/pthread_kill.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -49,12 +49,6 @@
     
   /* We have a special syscall to do the work.  */
 
-  /* 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.  */
-     
   /* 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

Modified: trunk/glibc-ports-2.25/kfreebsd/fbtl/raise.c
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/fbtl/raise.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/fbtl/raise.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -27,47 +27,9 @@
 int
 raise (int sig)
 {
-#if 1
-#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);
-
+  INLINE_SYSCALL(thr_self, 1, &ktid);
   return INLINE_SYSCALL(thr_kill, 2, ktid, sig);
-#else
-  struct pthread *pd = THREAD_SELF;
-  pid_t pid = THREAD_GETMEM (pd, pid);
-  pid_t selftid = THREAD_GETMEM (pd, tid);
-  if (selftid == 0)
-    {
-      /* This system call is not supposed to fail.  */
-#ifdef INTERNAL_SYSCALL
-      INTERNAL_SYSCALL_DECL (err);
-      selftid = INTERNAL_SYSCALL (gettid, err, 0);
-#else
-      selftid = INLINE_SYSCALL (gettid, 0);
-#endif
-      THREAD_SETMEM (pd, tid, selftid);
-
-      /* We do not set the PID field in the TID here since we might be
-	 called from a signal handler while the thread executes fork.  */
-      pid = selftid;
-    }
-  else
-    /* raise is an async-safe function.  It could be called while the
-       fork/vfork function temporarily invalidated the PID field.  Adjust for
-       that.  */
-    if (__builtin_expect (pid <= 0, 0))
-      pid = (pid & INT_MAX) == 0 ? selftid : -pid;
-
-  return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
-#endif  
 }
 libc_hidden_def (raise)
 weak_alias (raise, gsignal)

Modified: trunk/glibc-ports-2.25/kfreebsd/fbtl/register-atfork.c
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/fbtl/register-atfork.c	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/fbtl/register-atfork.c	2017-08-04 19:16:18 UTC (rev 6167)
@@ -23,6 +23,8 @@
 #include <atomic.h>
 
 
+struct fork_handler *__fork_handlers;
+
 /* Lock to protect allocation and deallocation of fork handlers.  */
 int __fork_lock = LLL_LOCK_INITIALIZER;
 

Deleted: trunk/glibc-ports-2.25/kfreebsd/i386/fbtl/pt-vfork.S
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/i386/fbtl/pt-vfork.S	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/i386/fbtl/pt-vfork.S	2017-08-04 19:16:18 UTC (rev 6167)
@@ -1,36 +0,0 @@
-/* Copyright (C) 1999-2013 Free Software Foundation, Inc.  This file is part
-   of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-
-#include <tcb-offsets.h>
-
-/* Save the PID value.  */
-#define SAVE_PID \
-	movl	%gs:PID, %edx; 						      \
-	negl	%edx;							      \
-	movl	%edx, %gs:PID
-
-
-/* we do not have spare register during syscall */
-/* Restore the old PID value in the parent.  */
-#define RESTORE_PID_IN_PARENT \
-	movl	%gs:PID, %edx; 						      \
-	negl	%edx;							      \
-	movl	%edx, %gs:PID
-
-#include "../vfork.S"
-

Deleted: trunk/glibc-ports-2.25/kfreebsd/i386/fbtl/vfork.S
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/i386/fbtl/vfork.S	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/i386/fbtl/vfork.S	2017-08-04 19:16:18 UTC (rev 6167)
@@ -1,40 +0,0 @@
-/* Copyright (C) 1999-2013 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-
-#include <tcb-offsets.h>
-
-/* Save the PID value.  */
-#define SAVE_PID \
-	movl	%gs:PID, %edx; 						      \
-	negl	%edx;							      \
-	jne	1f;							      \
-	movl	$0x80000000, %edx;					      \
-1:	movl	%edx, %gs:PID
-
-
-/* we do not have spare register during syscall */
-/* Restore the old PID value in the parent.  */
-#define RESTORE_PID_IN_PARENT \
-	movl	%gs:PID, %edx; 						      \
-	cmpl	$0x80000000, %edx;					      \
-	jne	1f;							      \
-	xorl	%edx, %edx;						      \
-1:	negl	%edx;							      \
-	movl	%edx, %gs:PID
-
-#include "../vfork.S"

Added: trunk/glibc-ports-2.25/kfreebsd/i386/pt-vfork.S
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/i386/pt-vfork.S	                        (rev 0)
+++ trunk/glibc-ports-2.25/kfreebsd/i386/pt-vfork.S	2017-08-04 19:16:18 UTC (rev 6167)
@@ -0,0 +1 @@
+#include <sysdeps/unix/bsd/bsd4.4/kfreebsd/i386/vfork.S>

Modified: trunk/glibc-ports-2.25/kfreebsd/i386/vfork.S
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/i386/vfork.S	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/i386/vfork.S	2017-08-04 19:16:18 UTC (rev 6167)
@@ -30,10 +30,6 @@
 	cfi_adjust_cfa_offset(-4)
 	cfi_register (%eip, %ecx)
 
-#ifdef SAVE_PID
-        SAVE_PID
-#endif
-
 	/* Perform the system call.  */
 	DO_CALL (vfork, 0)
 	jb	L(error)	/* Branch forward if it failed.  */
@@ -45,12 +41,6 @@
 	decl	%edx
 	andl	%edx, %eax
 
-#ifdef RESTORE_PID_IN_PARENT
-        jz L(norestore)
-        RESTORE_PID_IN_PARENT
-L(norestore):
-#endif
-
 	/* Jump to the return PC.  */
 	jmp	*%ecx
 
@@ -59,10 +49,6 @@
 	pushl	%ecx
 	cfi_adjust_cfa_offset(4)
 
-#ifdef RESTORE_PID_IN_PARENT
-        RESTORE_PID_IN_PARENT
-#endif
-
 	/* Branch to the error handler, hidden in PSEUDO_END.  */
 	jmp	SYSCALL_ERROR_LABEL
 L(pseudo_end):

Deleted: trunk/glibc-ports-2.25/kfreebsd/x86_64/fbtl/pt-vfork.S
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/x86_64/fbtl/pt-vfork.S	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/x86_64/fbtl/pt-vfork.S	2017-08-04 19:16:18 UTC (rev 6167)
@@ -1,29 +0,0 @@
-/* Copyright (C) 2004-2013 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <tcb-offsets.h>
-
-#define SAVE_PID \
-	movl	%fs:PID, %esi;						      \
-	movl	%esi, %edx;						      \
-	negl	%edx;							      \
-	movl	%edx, %fs:PID
-
-#define RESTORE_PID_IN_PARENT \
-	movl	%esi, %fs:PID;						      \
-
-#include "../vfork.S"

Deleted: trunk/glibc-ports-2.25/kfreebsd/x86_64/fbtl/vfork.S
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/x86_64/fbtl/vfork.S	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/x86_64/fbtl/vfork.S	2017-08-04 19:16:18 UTC (rev 6167)
@@ -1,31 +0,0 @@
-/* Copyright (C) 2004-2013 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <tcb-offsets.h>
-
-#define SAVE_PID \
-	movl	%fs:PID, %esi;						      \
-	movl	$0x80000000, %ecx;					      \
-	movl	%esi, %edx;						      \
-	negl	%edx;							      \
-	cmove	%ecx, %edx;						      \
-	movl	%edx, %fs:PID
-
-#define RESTORE_PID_IN_PARENT \
-	movl	%esi, %fs:PID;						      \
-
-#include "../vfork.S"

Added: trunk/glibc-ports-2.25/kfreebsd/x86_64/pt-vfork.S
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/x86_64/pt-vfork.S	                        (rev 0)
+++ trunk/glibc-ports-2.25/kfreebsd/x86_64/pt-vfork.S	2017-08-04 19:16:18 UTC (rev 6167)
@@ -0,0 +1 @@
+#include <sysdeps/unix/bsd/bsd4.4/kfreebsd/x86_64/vfork.S>

Modified: trunk/glibc-ports-2.25/kfreebsd/x86_64/vfork.S
===================================================================
--- trunk/glibc-ports-2.25/kfreebsd/x86_64/vfork.S	2017-08-04 18:51:12 UTC (rev 6166)
+++ trunk/glibc-ports-2.25/kfreebsd/x86_64/vfork.S	2017-08-04 19:16:18 UTC (rev 6167)
@@ -30,9 +30,6 @@
 	cfi_adjust_cfa_offset(-8)
 	cfi_register(%rip, %rdi)
 
-#ifdef SAVE_PID
-        SAVE_PID
-#endif
 	/* Perform the system call.  */
 	DO_CALL (vfork, 0)
 	jb	L(error)	/* Branch forward if it failed.  */
@@ -44,12 +41,6 @@
 	decq	%rdx
 	andq	%rdx, %rax
 
-#ifdef RESTORE_PID_IN_PARENT
-	jz L(norestore)
-        RESTORE_PID_IN_PARENT
-L(norestore):
-#endif
-
 	/* Jump to the return PC.  */
 	jmp	*%rdi
 
@@ -57,9 +48,7 @@
 	/* Push back the return PC.  */
 	pushq	%rdi
 	cfi_adjust_cfa_offset(8)
-#ifdef RESTORE_PID_IN_PARENT
-        RESTORE_PID_IN_PARENT
-#endif
+
 	/* Branch to the error handler, hidden in PSEUDO_END.  */
 	jmp	SYSCALL_ERROR_LABEL
 L(pseudo_end):




More information about the Glibc-bsd-commits mailing list