git: kernel - Fix lwp_tid ranging error

Matthew Dillon dillon at crater.dragonflybsd.org
Mon Jul 1 17:16:55 PDT 2019


commit c2f052162d1e85f47aeae97e82f2e0bcc0227967
Author: Matthew Dillon <dillon at apollo.backplane.com>
Date:   Mon Jul 1 11:35:52 2019 -0700

    kernel - Fix lwp_tid ranging error
    
    * We intended for lwp_tid's to range from 1..INT_MAX, but we
      had the following code in the kernel and unfortunately GCC
      optimizes out the conditional entirely.
    
      if (++lp->lwp_tid <= 0)
    	lp->lwp_tid = 1;
    
    * In addition, the pthreads library actually would like to use
      a few high bits for flags, so fix the limit while we are
      here to 0x3FFFFFFF.  This saves us a pthreads assertion in
      the mutex code if an application is actually able to wind
      the thread id up this high over its life.  Since the TID
      allocation mechanism is pretty simplistic, it is entirely
      possible to do this given heavy thread creation / deletion
      rates and enough time.
    
    * Change the conditional such that GCC does not optimize it out.
      We do not want to depend on -fwrapv for the kernel code to
      compile properly, so we don't use it.
    
      if (lp->lwp_tid == 0 || lp->lwp_tid == 0x3FFFFFFF)
    	lp->lwp_tid = 1;
      else
    	++lp->lwp_tid;

Summary of changes:
 sys/kern/kern_fork.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/c2f052162d1e85f47aeae97e82f2e0bcc0227967


-- 
DragonFly BSD source repository



More information about the Commits mailing list