From patchwork Mon May 27 20:03:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 1105932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-102287-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mcrowe.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="p8ZkPuSC"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45CScp0XQcz9s3l for ; Tue, 28 May 2019 06:04:57 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; q=dns; s=default; b=oi0U09vl SqhliwImsJaCZAOvZ2VFoFri0A7DRo1cNbA7CtjADkSo71OS/8fRVWIyK8TpxNd/ xQmObXvTirMuIMgsa5OibPcX9pX2Uf7hpm3oCA1QtqoDh+pfc7r+Q2uA49PL4jRG iLtOQLiKD9wLnrRU0RaLhoSzV2HUqJhjx6Y= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; s=default; bh=5ECFKO6+KelyHY F6ZhFlapQBK9U=; b=p8ZkPuSC2lZKB0U2F507eIIhw7PpTpVJcGJaloIbF18Fl1 xuSrNz4QnA+hisrl7Kiy3Z/TldKF+SHkSQ4gRLHn/4V6GFU6WxiHxRYszFu3fGIH 5J3NCSmqBFpNyF2Zk50hKcG+6uCqTJifIAJBgJNZzaz52oIXGXjVyGqvTG3EQ= Received: (qmail 58907 invoked by alias); 27 May 2019 20:04:37 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 58842 invoked by uid 89); 27 May 2019 20:04:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy= X-HELO: avasout02.plus.net X-CM-Score: 0.00 From: Mike Crowe To: libc-alpha@sourceware.org Cc: Mike Crowe Subject: [PATCH v3 4/6] nptl: pthread_rwlock: Move timeout validation into _full functions Date: Mon, 27 May 2019 21:03:45 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: As recommended by the comments in the implementations of pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock, let's move the timeout validity checks into the corresponding pthread_rwlock_rdlock_full and pthread_rwlock_wrlock_full functions. Since these functions may be called with abstime == NULL, an extra check for that is necessary too. * nptl/pthread_rwlock_common.c (__pthread_rwlock_rdlock_full): Check validity of abstime parameter. (__pthread_rwlock_rwlock_full): Likewise. * nptl/pthread_rwlock_timedrdlock.c (pthread_rwlock_timedrdlock): Remove check for validity of abstime parameter. * nptl/pthread_rwlock_timedwrlock.c (pthread_rwlock_timedwrlock): Likewise. --- ChangeLog | 14 ++++++++++++++ nptl/pthread_rwlock_common.c | 20 ++++++++++++++++++++ nptl/pthread_rwlock_timedrdlock.c | 10 ---------- nptl/pthread_rwlock_timedwrlock.c | 10 ---------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f95dd4..22a8bdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2019-05-27 Mike Crowe + nptl: pthread_rwlock: Move timeout validation into _full functions + + * nptl/pthread_rwlock_common.c (__pthread_rwlock_rdlock_full): + Check validity of abstime parameter. + (__pthread_rwlock_rwlock_full): Likewise. + + * nptl/pthread_rwlock_timedrdlock.c (pthread_rwlock_timedrdlock): + Remove check for validity of abstime parameter. + + * nptl/pthread_rwlock_timedwrlock.c (pthread_rwlock_timedwrlock): + Likewise. + +2019-05-27 Mike Crowe + nptl: Add POSIX-proposed pthread_cond_clockwait which behaves just like pthread_cond_timedwait except it always measures abstime against the supplied clockid. diff --git a/nptl/pthread_rwlock_common.c b/nptl/pthread_rwlock_common.c index 89ba21a..120b880 100644 --- a/nptl/pthread_rwlock_common.c +++ b/nptl/pthread_rwlock_common.c @@ -282,6 +282,16 @@ __pthread_rwlock_rdlock_full (pthread_rwlock_t *rwlock, { unsigned int r; + /* Make sure any passed in timeout value is valid. Note that the previous + implementation assumed that this check *must* not be performed if there + would in fact be no blocking; however, POSIX only requires that "the + validity of the abstime parameter need not be checked if the lock can be + immediately acquired" (i.e., we need not but may check it). */ + if (abstime + && __glibc_unlikely (abstime->tv_nsec >= 1000000000 + || abstime->tv_nsec < 0)) + return EINVAL; + /* Make sure we are not holding the rwlock as a writer. This is a deadlock situation we recognize and report. */ if (__glibc_unlikely (atomic_load_relaxed (&rwlock->__data.__cur_writer) @@ -576,6 +586,16 @@ static __always_inline int __pthread_rwlock_wrlock_full (pthread_rwlock_t *rwlock, const struct timespec *abstime) { + /* Make sure any passed in timeout value is valid. Note that the previous + implementation assumed that this check *must* not be performed if there + would in fact be no blocking; however, POSIX only requires that "the + validity of the abstime parameter need not be checked if the lock can be + immediately acquired" (i.e., we need not but may check it). */ + if (abstime + && __glibc_unlikely (abstime->tv_nsec >= 1000000000 + || abstime->tv_nsec < 0)) + return EINVAL; + /* Make sure we are not holding the rwlock as a writer. This is a deadlock situation we recognize and report. */ if (__glibc_unlikely (atomic_load_relaxed (&rwlock->__data.__cur_writer) diff --git a/nptl/pthread_rwlock_timedrdlock.c b/nptl/pthread_rwlock_timedrdlock.c index aa00530..84c1983 100644 --- a/nptl/pthread_rwlock_timedrdlock.c +++ b/nptl/pthread_rwlock_timedrdlock.c @@ -23,15 +23,5 @@ int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, const struct timespec *abstime) { - /* Make sure the passed in timeout value is valid. Note that the previous - implementation assumed that this check *must* not be performed if there - would in fact be no blocking; however, POSIX only requires that "the - validity of the abstime parameter need not be checked if the lock can be - immediately acquired" (i.e., we need not but may check it). */ - /* ??? Just move this to __pthread_rwlock_rdlock_full? */ - if (__glibc_unlikely (abstime->tv_nsec >= 1000000000 - || abstime->tv_nsec < 0)) - return EINVAL; - return __pthread_rwlock_rdlock_full (rwlock, abstime); } diff --git a/nptl/pthread_rwlock_timedwrlock.c b/nptl/pthread_rwlock_timedwrlock.c index 3c92e44..f0b745d 100644 --- a/nptl/pthread_rwlock_timedwrlock.c +++ b/nptl/pthread_rwlock_timedwrlock.c @@ -23,15 +23,5 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, const struct timespec *abstime) { - /* Make sure the passed in timeout value is valid. Note that the previous - implementation assumed that this check *must* not be performed if there - would in fact be no blocking; however, POSIX only requires that "the - validity of the abstime parameter need not be checked if the lock can be - immediately acquired" (i.e., we need not but may check it). */ - /* ??? Just move this to __pthread_rwlock_wrlock_full? */ - if (__glibc_unlikely (abstime->tv_nsec >= 1000000000 - || abstime->tv_nsec < 0)) - return EINVAL; - return __pthread_rwlock_wrlock_full (rwlock, abstime); }