From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99138 invoked by alias); 21 Oct 2016 21:06:52 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 99107 invoked by uid 89); 21 Oct 2016 21:06:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,RCVD_IN_SEMBACKSCATTER autolearn=no version=3.3.2 spammy=1026, Hx-languages-length:1481, 102,6, 1028 X-HELO: mx0a-001b2d01.pphosted.com From: "Tulio Magno Quites Machado Filho" To: libc-alpha@sourceware.org Subject: [PATCH] Document a behavior of an elided pthread_rwlock_unlock Date: Fri, 21 Oct 2016 21:06:00 -0000 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16102121-0020-0000-0000-00000254BA3A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16102121-0021-0000-0000-0000305E5010 Message-Id: <1477083990-9983-1-git-send-email-tuliom@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-10-21_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610210374 X-SW-Source: 2016-10/txt/msg00368.txt.bz2 Explain that pthread_rwlock_unlock may crash if called on a lock not held by the current thread. 2016-10-21 Tulio Magno Quites Machado Filho * nptl/pthread_rwlock_unlock.c: Add a comment explaining its behavior when eliding a lock not held by the current thread. * sysdeps/powerpc/nptl/elide.h: Likewise. --- nptl/pthread_rwlock_unlock.c | 4 ++++ sysdeps/powerpc/nptl/elide.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/nptl/pthread_rwlock_unlock.c b/nptl/pthread_rwlock_unlock.c index a6cadd4..112f748 100644 --- a/nptl/pthread_rwlock_unlock.c +++ b/nptl/pthread_rwlock_unlock.c @@ -35,6 +35,10 @@ __pthread_rwlock_unlock (pthread_rwlock_t *rwlock) LIBC_PROBE (rwlock_unlock, 1, rwlock); + /* Trying to elide an unlocked lock may crash the process. This + is expected and is compatible with POSIX.1-2008: "results are + undefined if the read-write lock rwlock is not held by the + calling thread". */ if (ELIDE_UNLOCK (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)) return 0; diff --git a/sysdeps/powerpc/nptl/elide.h b/sysdeps/powerpc/nptl/elide.h index 77bd82e..c573981 100644 --- a/sysdeps/powerpc/nptl/elide.h +++ b/sysdeps/powerpc/nptl/elide.h @@ -102,6 +102,8 @@ __elide_unlock (int is_lock_free) { if (is_lock_free) { + /* Intentionally crashes when trying to unlock a lock not held by this + thread. */ __libc_tend (0); return true; } -- 2.1.0