Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Apr 2018 20:45:21 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r332633 - in stable: 10/lib/libthr/thread 11/lib/libthr/thread
Message-ID:  <201804162045.w3GKjLom036576@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Mon Apr 16 20:45:21 2018
New Revision: 332633
URL: https://svnweb.freebsd.org/changeset/base/332633

Log:
  MFC 331324: Ensure thread library is initialized in pthread_testcancel().
  
  Call _thr_check_init() before reading curthread in pthread_testcancel().
  
  If a constructor in a library creates a semaphore via sem_init() and
  then waits for it via sem_wait(), the program can core dump in
  _pthread_testcancel() called from sem_wait().  This is because the
  semaphore implementation lives in libc, so the library's constructors
  can be run before libthr's constructors.
  
  Sponsored by:	DARPA / AFRL

Modified:
  stable/11/lib/libthr/thread/thr_cancel.c
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/10/lib/libthr/thread/thr_cancel.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/11/lib/libthr/thread/thr_cancel.c
==============================================================================
--- stable/11/lib/libthr/thread/thr_cancel.c	Mon Apr 16 19:33:04 2018	(r332632)
+++ stable/11/lib/libthr/thread/thr_cancel.c	Mon Apr 16 20:45:21 2018	(r332633)
@@ -130,8 +130,10 @@ _pthread_setcanceltype(int type, int *oldtype)
 void
 _pthread_testcancel(void)
 {
-	struct pthread *curthread = _get_curthread();
+	struct pthread *curthread;
 
+	_thr_check_init();
+	curthread = _get_curthread();
 	testcancel(curthread);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804162045.w3GKjLom036576>